-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathvalidate-grpc-integration.sh
More file actions
executable file
·147 lines (132 loc) · 7.08 KB
/
Copy pathvalidate-grpc-integration.sh
File metadata and controls
executable file
·147 lines (132 loc) · 7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# ─────────────────────────────────────────────────────────────────────────────
# gRPC Integration Test Validation Script
#
# Runs an OpenSearch 3.5+ container with gRPC enabled, then executes the
# integration tests against it.
#
# Usage:
# ./validate-grpc-integration.sh
#
# Requirements:
# - Docker running
# - Java 21+ (for integration tests)
# - Gradle wrapper in project root
#
# Environment variables (optional):
# OPENSEARCH_VERSION — OpenSearch version to test (default: 3.5.0)
# GRPC_PORT — gRPC port to expose (default: 9400)
# REST_PORT — REST port to expose (default: 9200)
# KEEP_CONTAINER — set to "true" to keep container running after tests
# ─────────────────────────────────────────────────────────────────────────────
set -e
OPENSEARCH_VERSION="${OPENSEARCH_VERSION:-3.5.0}"
GRPC_PORT="${GRPC_PORT:-9400}"
REST_PORT="${REST_PORT:-9200}"
CONTAINER_NAME="opensearch-grpc-test"
IMAGE="opensearchproject/opensearch:${OPENSEARCH_VERSION}"
echo "═══════════════════════════════════════════════════════════════"
echo " gRPC Integration Test Validation"
echo " OpenSearch Version: ${OPENSEARCH_VERSION}"
echo " REST Port: ${REST_PORT}"
echo " gRPC Port: ${GRPC_PORT}"
echo "═══════════════════════════════════════════════════════════════"
# ─── Cleanup any existing container ──────────────────────────────────────────
echo ""
echo "▶ Cleaning up any existing container..."
docker rm -f ${CONTAINER_NAME} 2>/dev/null || true
# ─── Start OpenSearch with gRPC enabled ──────────────────────────────────────
echo ""
echo "▶ Starting OpenSearch ${OPENSEARCH_VERSION} with gRPC transport..."
docker run -d \
--name ${CONTAINER_NAME} \
-p ${REST_PORT}:9200 \
-p ${GRPC_PORT}:9400 \
-e "discovery.type=single-node" \
-e "plugins.security.disabled=true" \
-e "aux.transport.types=transport-grpc" \
-e "aux.transport.transport-grpc.port=9400" \
-e "OPENSEARCH_INITIAL_ADMIN_PASSWORD=admin" \
-e "cluster.routing.allocation.disk.threshold_enabled=false" \
${IMAGE}
# ─── Wait for cluster to be ready ────────────────────────────────────────────
echo ""
echo "▶ Waiting for OpenSearch to be ready..."
MAX_RETRIES=30
RETRY_INTERVAL=3
for i in $(seq 1 $MAX_RETRIES); do
if curl -s "http://localhost:${REST_PORT}/_cluster/health" | grep -q '"status"'; then
echo " ✓ OpenSearch is ready!"
break
fi
if [ $i -eq $MAX_RETRIES ]; then
echo " ✗ OpenSearch failed to start after ${MAX_RETRIES} attempts"
docker logs ${CONTAINER_NAME} | tail -30
docker rm -f ${CONTAINER_NAME}
exit 1
fi
echo " Waiting... (attempt $i/$MAX_RETRIES)"
sleep $RETRY_INTERVAL
done
# ─── Verify gRPC port is listening ───────────────────────────────────────────
echo ""
echo "▶ Verifying gRPC port ${GRPC_PORT} is open..."
if nc -z localhost ${GRPC_PORT} 2>/dev/null; then
echo " ✓ gRPC port is open!"
else
echo " ⚠ gRPC port not responding (nc check failed, may still work)"
fi
# ─── Show cluster info ────────────────────────────────────────────────────────
echo ""
echo "▶ Cluster info:"
curl -s "http://localhost:${REST_PORT}" | python3 -m json.tool 2>/dev/null || curl -s "http://localhost:${REST_PORT}"
echo ""
# ─── Run integration tests ───────────────────────────────────────────────────
echo ""
echo "═══════════════════════════════════════════════════════════════"
echo " Running Integration Tests"
echo "═══════════════════════════════════════════════════════════════"
echo ""
# Run the gRPC integration tests
./gradlew :java-client:integrationTest \
--tests "org.opensearch.client.opensearch.integTest.grpc.*" \
-Dtests.rest.cluster=localhost:${REST_PORT} \
-Dtests.grpc.cluster=localhost:${GRPC_PORT} \
-Dtests.opensearch.version=${OPENSEARCH_VERSION} \
-Dtests.opensearch.testcontainers.enabled=false \
-Dhttps=false \
-Duser=admin \
-Dpassword=admin \
--info 2>&1 | tee /tmp/grpc-integration-test.log
TEST_EXIT_CODE=${PIPESTATUS[0]}
# ─── Results ──────────────────────────────────────────────────────────────────
echo ""
echo "═══════════════════════════════════════════════════════════════"
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo " ✓ ALL INTEGRATION TESTS PASSED"
else
echo " ✗ INTEGRATION TESTS FAILED (exit code: ${TEST_EXIT_CODE})"
echo ""
echo " Test report: java-client/build/reports/tests/integrationTest/index.html"
echo " Full log: /tmp/grpc-integration-test.log"
fi
echo "═══════════════════════════════════════════════════════════════"
# ─── Also run unit tests for sanity ──────────────────────────────────────────
echo ""
echo "▶ Running unit tests (sanity check)..."
./gradlew :java-client:test --tests "org.opensearch.client.transport.grpc.*" 2>&1 | tail -5
# ─── Cleanup ──────────────────────────────────────────────────────────────────
if [ "${KEEP_CONTAINER}" != "true" ]; then
echo ""
echo "▶ Stopping container..."
docker rm -f ${CONTAINER_NAME}
echo " ✓ Container removed"
else
echo ""
echo "▶ Container left running (KEEP_CONTAINER=true)"
echo " REST: http://localhost:${REST_PORT}"
echo " gRPC: localhost:${GRPC_PORT}"
echo " Stop with: docker rm -f ${CONTAINER_NAME}"
fi
echo ""
exit $TEST_EXIT_CODE