chord/test.bash
2025-03-15 20:30:05 -04:00

39 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
set -ex
go build -o ./chord-node
# Test create and join.
./chord-node join -ip 127.0.0.1:3000 &
FIRST=$!
sleep 3
./chord-node join -ip 127.0.0.1:3001 -c 127.0.0.1:3000 &
SECOND=$!
./chord-node join -ip 127.0.0.1:3002 -c 127.0.0.1:3000 &
THIRD=$!
sleep 5
# Each node logs its predecessor and successors. At this point, we see the ring.
# Test lookup.
# First check that the lookup is independent of the node we ask.
./chord-node lookup -k key1 -n 127.0.0.1:3000
./chord-node lookup -k key1 -n 127.0.0.1:3001
./chord-node lookup -k key1 -n 127.0.0.1:3002
# Now check that we get some different nodes for different keys.
./chord-node lookup -k key2 -n 127.0.0.1:3000
./chord-node lookup -k key3 -n 127.0.0.1:3000
# Test data storage.
./chord-node put -k key1 -v value1 -n 127.0.0.1:3000
./chord-node get -k key1 -n 127.0.0.1:3000
./chord-node put -k key1 -v value2 -n 127.0.0.1:3001
./chord-node get -k key1 -n 127.0.0.1:3002
# Test leaving.
./chord-node leave -n 127.0.0.1:3000
kill $FIRST $SECOND $THIRD