-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest-transactions.sh
executable file
·61 lines (47 loc) · 1.53 KB
/
test-transactions.sh
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
#!/bin/bash
# Test script for Accord transactions in Cassandra
# This script runs a series of tests to verify transaction functionality
echo "Testing Accord Transactions..."
# Wait for Cassandra to be ready
while ! docker exec cassandra-accord ./bin/cqlsh -e "describe keyspaces" > /dev/null 2>&1; do
echo "⏳ Waiting for Cassandra to start..."
sleep 5
done
echo "✅ Cassandra is ready!"
# Create test keyspace and table
docker exec cassandra-accord ./bin/cqlsh << EOF
CREATE KEYSPACE IF NOT EXISTS demo
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
CREATE TABLE IF NOT EXISTS demo.products (
item text,
inventory_count decimal,
PRIMARY KEY (item)
) WITH transactional_mode = 'full'
EOF
echo "Created test table"
# Insert test data
docker exec cassandra-accord ./bin/cqlsh << EOF
INSERT INTO demo.products(item, inventory_count)
VALUES ('test_item', 100)
EOF
echo "Inserted test data"
# Run test transaction
docker exec cassandra-accord ./bin/cqlsh << EOF
BEGIN TRANSACTION
UPDATE demo.products
SET inventory_count -= 1
WHERE item='test_item';
COMMIT TRANSACTION
EOF
echo "Executed test transaction"
# Verify result
RESULT=$(docker exec cassandra-accord ./bin/cqlsh -e "SELECT inventory_count FROM demo.products WHERE item='test_item'" | grep -A 2 inventory_count | tail -n 1 | tr -d ' ')
echo "Result: $RESULT"
if [ "$RESULT" = "99" ]; then
echo "✅ Transaction test passed!"
else
echo "❌ Transaction test failed!"
echo "Expected: 99"
echo "Got: $RESULT"
exit 1
fi