-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·282 lines (240 loc) · 9.32 KB
/
Copy pathscript.sh
File metadata and controls
executable file
·282 lines (240 loc) · 9.32 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/bash
# Initialize success counter
success_count=0
total_tests=7
proxy_pid=""
backend_pids=()
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo "Starting comprehensive proxy functionality tests..."
echo "=================================================="
# Function to build classpath with dependencies
build_classpath() {
echo -e "${BLUE}Building classpath with dependencies...${NC}"
mvn dependency:build-classpath -Dmdep.outputFile=cp.txt -q
if [ -f "cp.txt" ]; then
CLASSPATH=$(cat cp.txt):target/classes:target/ahc-proxy-1.0-SNAPSHOT.jar
rm cp.txt
echo -e "${GREEN}✅ Classpath built successfully${NC}"
else
echo -e "${RED}❌ Failed to build classpath${NC}"
exit 1
fi
}
# Function to start backend servers for cluster testing
start_backend_servers() {
echo -e "${BLUE}Starting backend application servers for cluster testing...${NC}"
for port in 8001 8002 8003; do
echo "Starting backend application server on port $port..."
java -cp "$CLASSPATH" -DlocalPort=$port -DserverName="server-$port" examples.TestBackendServer > /dev/null 2>&1 &
local pid=$!
backend_pids+=($pid)
echo "Backend application server started on port $port with PID: $pid"
# Wait a moment for the server to start
sleep 2
# Check if server is running
if ! kill -0 $pid 2>/dev/null; then
echo -e "${RED}❌ Failed to start backend server on port $port${NC}"
return 1
fi
# Test if server is accepting connections
timeout 3 bash -c "until nc -z localhost $port; do sleep 0.1; done" 2>/dev/null
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Backend application server on port $port is accepting connections${NC}"
else
echo -e "${RED}❌ Backend application server on port $port is not accepting connections${NC}"
return 1
fi
done
echo -e "${GREEN}✅ All backend application servers started successfully${NC}"
return 0
}
# Function to stop backend servers
stop_backend_servers() {
if [ ${#backend_pids[@]} -gt 0 ]; then
echo -e "${YELLOW}Stopping backend application servers...${NC}"
for pid in "${backend_pids[@]}"; do
if [ ! -z "$pid" ] && kill -0 $pid 2>/dev/null; then
echo "Stopping backend application server (PID: $pid)..."
kill $pid
sleep 1
# Force kill if still running
if kill -0 $pid 2>/dev/null; then
echo "Force killing backend application server (PID: $pid)..."
kill -9 $pid
fi
fi
done
backend_pids=()
echo -e "${GREEN}✅ All backend application servers stopped${NC}"
fi
}
# Function to start non-cluster proxy server
start_non_cluster_proxy() {
echo -e "${BLUE}Starting non-cluster proxy server...${NC}"
java -cp "$CLASSPATH" examples.TestHttp1 &
proxy_pid=$!
echo "Proxy server started with PID: $proxy_pid"
echo "Waiting for proxy server to initialize..."
sleep 3
if ! kill -0 $proxy_pid 2>/dev/null; then
echo -e "${RED}❌ Failed to start non-cluster proxy server${NC}"
return 1
fi
timeout 5 bash -c 'until nc -z localhost 8000; do sleep 0.1; done' 2>/dev/null
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Non-cluster proxy server is running and accepting connections${NC}"
return 0
else
echo -e "${RED}❌ Non-cluster proxy server is not accepting connections${NC}"
stop_proxy
return 1
fi
}
# Function to start cluster proxy server
start_notifier_log_proxy() {
echo -e "${BLUE}Starting Notifier log proxy server...${NC}"
java -cp "$CLASSPATH" examples.TestHttp1Notifier &
proxy_pid=$!
echo "Notifer log proxy server started with PID: $proxy_pid"
echo "Waiting for Notifier log proxy server to initialize..."
sleep 3
if ! kill -0 $proxy_pid 2>/dev/null; then
echo -e "${RED}❌ Failed to start Notifer log proxy server${NC}"
return 1
fi
timeout 5 bash -c 'until nc -z localhost 8000; do sleep 0.1; done' 2>/dev/null
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Notifer log proxy server is running and accepting connections${NC}"
return 0
else
echo -e "${RED}❌ Notifer log proxy server is not accepting connections${NC}"
stop_proxy
return 1
fi
}
# Function to stop proxy server
stop_proxy() {
if [ ! -z "$proxy_pid" ] && kill -0 $proxy_pid 2>/dev/null; then
echo -e "${YELLOW}Stopping proxy server (PID: $proxy_pid)...${NC}"
kill $proxy_pid
sleep 2
if kill -0 $proxy_pid 2>/dev/null; then
echo -e "${YELLOW}Force killing proxy server...${NC}"
kill -9 $proxy_pid
fi
echo -e "${GREEN}✅ Proxy server stopped${NC}"
fi
proxy_pid=""
}
# Function to run proxy tests
run_proxy_tests() {
local test_type=$1
echo
echo -e "${BLUE}Running tests for $test_type proxy...${NC}"
echo "================================="
# GET operation (no auth, compression)
echo "Test 1: GET operation (no auth, no compression)"
if timeout 10 curl -x localhost:8000 "http://echo.free.beeceptor.com/sample-request?author=beeceptor" -s -o /dev/null -w "%{http_code}" | grep -q "200"; then
echo -e "${GREEN}✅ GET test passed${NC}"
((success_count++))
else
echo -e "${RED}❌ GET test failed${NC}"
fi
echo
# POST operation (body, header)
echo "Test 2: POST operation (with body and headers)"
if timeout 10 curl -x localhost:8000 -X POST -H "Content-Type: application/json" -d '{"name": "John Doe", "age": 30, "city": "New York"}' "http://echo.free.beeceptor.com/sample-request?author=beeceptor" -s -o /dev/null -w "%{http_code}" | grep -q "200"; then
echo -e "${GREEN}✅ POST test passed${NC}"
((success_count++))
else
echo -e "${RED}❌ POST test failed${NC}"
fi
echo
# POST operation (body, header, w/compression)
echo "Test 3: POST operation (with compression)"
if timeout 10 curl -x localhost:8000 -X POST -H "Content-Type: application/json" -d '{"name": "John Doe", "age": 30, "city": "New York"}' "http://echo.free.beeceptor.com/sample-request?author=beeceptor" -H "Accept-Encoding: gzip" -s -o /dev/null -w "%{http_code}" | grep -q "200"; then
echo -e "${GREEN}✅ POST with compression test passed${NC}"
((success_count++))
else
echo -e "${RED}❌ POST compression test failed${NC}"
fi
echo
# HTTPS tunneling test (only for non-cluster proxy)
if [ "$test_type" = "non-cluster" ]; then
echo "Test 4: HTTPS tunneling"
if timeout 10 curl -x localhost:8000 "https://echo.free.beeceptor.com/sample-request?author=beeceptor" -s -o /dev/null -w "%{http_code}" | grep -q "200"; then
echo -e "${GREEN}✅ Tunnel successfully worked. Test passed${NC}"
((success_count++))
else
echo -e "${RED}❌ Tunnel test failed${NC}"
fi
echo
else
echo "Test 4: HTTPS tunneling"
echo -e "${YELLOW}⚠️ HTTPS tunneling is not supported in cluster mode - SKIPPED${NC}"
echo
fi
}
# Cleanup function for graceful exit
cleanup() {
echo -e "${YELLOW}Cleaning up...${NC}"
stop_proxy
stop_backend_servers
exit 0
}
# Set trap for cleanup on script exit
trap cleanup EXIT INT TERM
# Always recompile the project to ensure latest code changes
echo -e "${YELLOW}Compiling project...${NC}"
mvn clean compile package -DskipTests
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Failed to compile project${NC}"
exit 1
fi
echo -e "${GREEN}✅ Project compiled successfully${NC}"
# Build classpath with all dependencies
build_classpath
echo -e "${BLUE}Testing Non-Cluster Proxy Server${NC}"
echo "=================================="
# Test non-cluster proxy
if start_non_cluster_proxy; then
run_proxy_tests "non-cluster"
else
echo -e "${RED}❌ Failed to start non-cluster proxy server, skipping tests${NC}"
fi
# Stop the non-cluster proxy
stop_proxy
sleep 2
echo
echo -e "${BLUE}Testing Notifier log Proxy Server${NC}"
echo "============================="
# Start backend servers for cluster testing
if start_backend_servers; then
if start_notifier_log_proxy; then
run_proxy_tests "cluster"
else
echo -e "${RED}❌ Failed to start cluster proxy server, skipping tests${NC}"
fi
stop_proxy
stop_backend_servers
else
echo -e "${RED}❌ Failed to start backend application servers, skipping cluster tests${NC}"
fi
echo
echo -e "${YELLOW}ℹ️ Logger notifier mode tests are commented out (implementation not finished)${NC}"
# Final results
echo
echo "=================================================="
echo -e "${BLUE}Final Test Results: $success_count/$total_tests tests passed${NC}"
if [ $success_count -eq $total_tests ]; then
echo -e "${GREEN}🎉 SUCCESS: All proxy functionality tests completed successfully!${NC}"
exit 0
else
echo -e "${YELLOW}⚠️ Some tests failed ($((total_tests - success_count)) failures). Please check the logs and try again.${NC}"
exit 1
fi