-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-system.sh
More file actions
executable file
·97 lines (85 loc) · 2.49 KB
/
test-system.sh
File metadata and controls
executable file
·97 lines (85 loc) · 2.49 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
#!/bin/bash
echo "🚀 Testing PubSubGo System"
echo "=========================="
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
SERVER_URL="http://localhost:8080"
CLI="./pubsub-cli"
# Function to check if server is running
check_server() {
echo -n "🔍 Checking if server is running... "
if curl -s -f $SERVER_URL/health > /dev/null 2>&1; then
echo -e "${GREEN}✅ Server is running${NC}"
return 0
else
echo -e "${RED}❌ Server is not running${NC}"
echo "Please start the server first:"
echo " ./pubsubgo-server -config config.yaml"
return 1
fi
}
# Function to test CLI connection
test_cli() {
echo -n "🔧 Testing CLI connection... "
if $CLI --server $SERVER_URL topics list > /dev/null 2>&1; then
echo -e "${GREEN}✅ CLI can connect${NC}"
return 0
else
echo -e "${RED}❌ CLI cannot connect${NC}"
return 1
fi
}
# Function to create test topic
create_topic() {
echo -n "📁 Creating test topic... "
if $CLI --server $SERVER_URL topics create --name test-topic --partitions 2 > /dev/null 2>&1; then
echo -e "${GREEN}✅ Topic created${NC}"
return 0
else
echo -e "${YELLOW}⚠️ Topic might already exist${NC}"
return 0
fi
}
# Function to publish test message
publish_message() {
echo -n "📤 Publishing test message... "
if $CLI --server $SERVER_URL publish --topic test-topic --message "Hello from test!" --key "test-key" --priority "high" > /dev/null 2>&1; then
echo -e "${GREEN}✅ Message published${NC}"
return 0
else
echo -e "${RED}❌ Failed to publish message${NC}"
return 1
fi
}
# Function to list topics
list_topics() {
echo "📋 Listing topics:"
$CLI --server $SERVER_URL topics list
}
# Function to get topic stats
get_stats() {
echo "📊 Getting topic stats:"
$CLI --server $SERVER_URL topics stats --name test-topic
}
# Main test sequence
main() {
check_server || exit 1
test_cli || exit 1
create_topic
publish_message || exit 1
list_topics
echo ""
get_stats
echo ""
echo -e "${GREEN}🎉 System test completed successfully!${NC}"
echo ""
echo "To test real-time subscription, run in another terminal:"
echo " $CLI subscribe --topic test-topic"
echo ""
echo "Then publish more messages:"
echo " $CLI publish --topic test-topic --message 'Live message!'"
}
main "$@"