|
1 | 1 | #!/bin/bash |
2 | | -# This script launches 100 nodes (one seed + 99 joiners), |
3 | | -# writes a key to the seed node, waits for propagation, |
4 | | -# and then performs 10 random reads to verify data consistency. |
| 2 | +# This script: |
| 3 | +# - Clones the DynaRust binary into a unique folder for each node so that each node uses its own file system. |
| 4 | +# - Launches 100 nodes (one seed and 99 joiners) from their own working directories. |
| 5 | +# - Writes a key/value pair to the "default" table on the seed node. |
| 6 | +# - Waits for propagation and performs random reads. |
| 7 | +# - Also tests endpoints for listing keys and retrieving multiple keys. |
| 8 | +# - Finally, it cleans up (kills node processes and removes the temporary directories). |
5 | 9 |
|
6 | 10 | set -e |
7 | 11 |
|
8 | | -# Trap exit signals to kill background nodes when the script exits. |
9 | | -trap "kill $(jobs -p) 2>/dev/null" EXIT |
| 12 | +# Create a temporary directory where we'll create subdirectories for each node. |
| 13 | +TMP_DIR=$(mktemp -d -t dynatest.XXXXXX) |
| 14 | +echo "Using temporary directory: ${TMP_DIR}" |
| 15 | + |
| 16 | +# Trap exit signals to kill background nodes and cleanup TMP_DIR when the script exits. |
| 17 | +cleanup() { |
| 18 | + echo "Cleaning up..." |
| 19 | + kill $(jobs -p) 2>/dev/null || true |
| 20 | + rm -rf "${TMP_DIR}" |
| 21 | +} |
| 22 | +trap cleanup EXIT |
10 | 23 |
|
11 | 24 | # Total number of cluster nodes to start. |
12 | | -NODES=100 |
| 25 | +NODES=30 |
13 | 26 | # Base port for the first (seed) node. |
14 | 27 | BASE_PORT=6660 |
15 | 28 |
|
16 | 29 | echo "Starting DynaRust nodes for cluster test..." |
17 | 30 |
|
18 | | -# Start the seed node. |
19 | | -echo "Starting seed node at 127.0.0.1:${BASE_PORT}" |
20 | | -./target/release/DynaRust 127.0.0.1:${BASE_PORT} & |
21 | | -# Save the PID if needed. |
22 | | -PIDS=($!) |
23 | | - |
24 | | -# Start additional nodes joining the seed. |
25 | | -for (( i=1; i<NODES; i++ )); do |
26 | | - PORT=$((BASE_PORT + i)) |
27 | | - echo "Starting node at 127.0.0.1:${PORT} joining 127.0.0.1:${BASE_PORT}" |
28 | | - ./target/release/DynaRust 127.0.0.1:${PORT} 127.0.0.1:${BASE_PORT} & |
29 | | - PIDS+=($!) |
| 31 | +# Array to hold the PIDs of launched processes. |
| 32 | +PIDS=() |
| 33 | + |
| 34 | +# Start nodes. Each node will be run from its own directory under TMP_DIR. |
| 35 | +for (( i=0; i<NODES; i++ )); do |
| 36 | + NODE_DIR="${TMP_DIR}/node${i}" |
| 37 | + mkdir -p "${NODE_DIR}" |
| 38 | + # Copy the binary to the node directory. |
| 39 | + cp ./target/release/DynaRust "${NODE_DIR}/DynaRust" |
| 40 | + |
| 41 | + PORT=$((BASE_PORT + i)) |
| 42 | + |
| 43 | + if [ $i -eq 0 ]; then |
| 44 | + # Seed node - no join argument. |
| 45 | + echo "Starting seed node at 127.0.0.1:${PORT} in ${NODE_DIR}" |
| 46 | + ( cd "${NODE_DIR}" && ./DynaRust 127.0.0.1:${PORT} ) & |
| 47 | + PIDS+=($!) |
| 48 | + else |
| 49 | + # Other nodes join the seed node. |
| 50 | + echo "Starting node at 127.0.0.1:${PORT} in ${NODE_DIR}, joining 127.0.0.1:${BASE_PORT}" |
| 51 | + ( cd "${NODE_DIR}" && ./DynaRust 127.0.0.1:${PORT} 127.0.0.1:${BASE_PORT} ) & |
| 52 | + PIDS+=($!) |
| 53 | + fi |
30 | 54 | done |
31 | 55 |
|
32 | | -# Wait for the cluster nodes to start and join. |
33 | 56 | echo "Waiting 5 seconds for cluster stabilization..." |
34 | 57 | sleep 5 |
35 | 58 |
|
36 | | -# Write a test value to the seed node. |
| 59 | +# Define test parameters. |
| 60 | +TABLE="default" |
37 | 61 | KEY="testkey" |
38 | 62 | VALUE="testvalue" |
39 | | -echo "Writing key '$KEY' with value '$VALUE' to the seed node..." |
40 | | -curl -s -X PUT "http://127.0.0.1:${BASE_PORT}/key/${KEY}" \ |
| 63 | + |
| 64 | +# Write a test value to the seed node in the "default" table. |
| 65 | +echo "Writing key '$KEY' with value '$VALUE' to table '$TABLE' on the seed node..." |
| 66 | +curl -s -X PUT "http://127.0.0.1:${BASE_PORT}/${TABLE}/key/${KEY}" \ |
41 | 67 | -H "Content-Type: application/json" \ |
42 | | - -d "{\"value\": \"${VALUE}\"}" |
| 68 | + -d "{\"attribute\": \"${VALUE}\"}" |
43 | 69 | echo "" |
44 | 70 |
|
45 | | -# Wait 3 seconds to allow the update to propagate to all nodes. |
46 | 71 | echo "Waiting 3 seconds for data propagation..." |
47 | 72 | sleep 3 |
48 | 73 |
|
49 | 74 | # Perform 10 random read operations from nodes in the cluster. |
50 | 75 | NUM_READS=10 |
51 | 76 | echo "Performing ${NUM_READS} random reads from cluster nodes..." |
52 | 77 | for (( i=1; i<=NUM_READS; i++ )); do |
53 | | - # Using the built-in $RANDOM to generate a random index. |
54 | 78 | NODE_INDEX=$(($RANDOM % $NODES)) |
55 | 79 | READ_PORT=$((BASE_PORT + NODE_INDEX)) |
56 | 80 | echo "Read attempt ${i} from node at 127.0.0.1:${READ_PORT}:" |
57 | | - curl -s "http://127.0.0.1:${READ_PORT}/key/${KEY}" |
| 81 | + curl -s "http://127.0.0.1:${READ_PORT}/${TABLE}/key/${KEY}" |
| 82 | + echo -e "\n-------------------------" |
| 83 | +done |
| 84 | + |
| 85 | +# Test the new endpoint to list all keys in the table from the seed node. |
| 86 | +echo "Listing all keys in table '$TABLE' from the seed node:" |
| 87 | +curl -s "http://127.0.0.1:${BASE_PORT}/${TABLE}/keys" |
| 88 | +echo -e "\n-------------------------" |
| 89 | + |
| 90 | +# Test the new endpoint to retrieve multiple keys from the table from the seed node. |
| 91 | +echo "Retrieving multiple keys from table '$TABLE' from the seed node (requesting 'testkey' and 'nonexistent'):" |
| 92 | +curl -s -X POST "http://127.0.0.1:${BASE_PORT}/${TABLE}/keys" \ |
| 93 | + -H "Content-Type: application/json" \ |
| 94 | + -d '{"keys": ["testkey", "nonexistent"]}' |
| 95 | +echo -e "\n-------------------------" |
| 96 | + |
| 97 | +# Select 3 random nodes and for each: |
| 98 | +# - Retrieve the test key value using GET /default/key/{key} |
| 99 | +# - List all keys using GET /default/keys |
| 100 | +echo "Selecting 3 random nodes to verify key access and key listing:" |
| 101 | +for (( i=1; i<=3; i++ )); do |
| 102 | + NODE_INDEX=$(($RANDOM % $NODES)) |
| 103 | + READ_PORT=$((BASE_PORT + NODE_INDEX)) |
| 104 | + echo "From node at 127.0.0.1:${READ_PORT}:" |
| 105 | + echo "Retrieving key '$KEY':" |
| 106 | + curl -s "http://127.0.0.1:${READ_PORT}/${TABLE}/key/${KEY}" |
| 107 | + echo "" |
| 108 | + echo "Listing keys in table '$TABLE':" |
| 109 | + curl -s "http://127.0.0.1:${READ_PORT}/${TABLE}/keys" |
58 | 110 | echo -e "\n-------------------------" |
59 | 111 | done |
60 | 112 | pkill DynaRust |
| 113 | + |
61 | 114 | echo "Test completed successfully." |
0 commit comments