-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-cluster.sh
More file actions
executable file
·98 lines (79 loc) · 2.83 KB
/
check-cluster.sh
File metadata and controls
executable file
·98 lines (79 loc) · 2.83 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
#!/usr/bin/env bash
# Run skill eval cases against a live Couchbase cluster using cbsh.
# Requires: cbsh installed, a running Couchbase cluster with travel-sample loaded.
# Usage: ./scripts/check-cluster.sh <host> <user> <password>
# Example: ./scripts/check-cluster.sh localhost app-user s3cr3t
# Use a least-privilege application user, not the Administrator account.
set -euo pipefail
HOST="${1:?Usage: $0 <host> <user> <password>}"
USER="${2:?}"
PASS="${3:?}"
PASS_COUNT=0
FAIL_COUNT=0
run_query() {
local desc="$1" query="$2" expect="$3"
result=$(cbsh --hostnames "$HOST" --username "$USER" --password "$PASS" \
--tls-accept-all-certs \
--script "query '$query'" 2>/dev/null | tail -1)
if echo "$result" | grep -q "$expect"; then
echo " ✅ $desc"
PASS_COUNT=$((PASS_COUNT+1))
else
echo " ❌ $desc"
echo " Expected: $expect"
echo " Got: $result"
FAIL_COUNT=$((FAIL_COUNT+1))
fi
}
echo "=== couchbase-server-querying ==="
run_query \
"Basic SELECT with WHERE" \
"SELECT name FROM \`travel-sample\`.inventory.airline WHERE country = 'United States' LIMIT 1" \
"name"
run_query \
"COUNT aggregation" \
"SELECT COUNT(*) AS cnt FROM \`travel-sample\`.inventory.airline WHERE country IS NOT MISSING" \
"cnt"
run_query \
"UNNEST array" \
"SELECT r.sourceairport, s.flight FROM \`travel-sample\`.inventory.route r UNNEST r.schedule s WHERE s.day = 0 LIMIT 1" \
"sourceairport"
run_query \
"ANY ... SATISFIES" \
"SELECT name FROM \`travel-sample\`.inventory.hotel WHERE ANY a IN reviews SATISFIES a.ratings.Overall >= 4 END LIMIT 1" \
"name"
run_query \
"SELECT RAW" \
"SELECT RAW name FROM \`travel-sample\`.inventory.airline LIMIT 1" \
'"'
run_query \
"DATE_TRUNC_STR" \
"SELECT DATE_TRUNC_STR(NOW_STR(), 'day') AS today" \
"today"
run_query \
"ARRAY_LENGTH" \
"SELECT ARRAY_LENGTH(schedule) AS n FROM \`travel-sample\`.inventory.route LIMIT 1" \
'"n"'
echo ""
echo "=== couchbase-server-query-optimizer ==="
run_query \
"EXPLAIN shows IndexScan (not PrimaryScan)" \
"EXPLAIN SELECT name FROM \`travel-sample\`.inventory.airline WHERE country = 'United States'" \
"IndexScan"
run_query \
"system:indexes accessible" \
"SELECT COUNT(*) AS cnt FROM system:indexes WHERE bucket_id = 'travel-sample'" \
"cnt"
echo ""
echo "=== couchbase-server-data-modeling ==="
run_query \
"Nested field access" \
"SELECT address.city FROM \`travel-sample\`.inventory.hotel WHERE address.city IS NOT MISSING LIMIT 1" \
"city"
run_query \
"META().id accessible" \
"SELECT META().id FROM \`travel-sample\`.inventory.airline LIMIT 1" \
'"id"'
echo ""
echo "Results: $PASS_COUNT passed, $FAIL_COUNT failed"
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1