ctdb-tests: Update integration tests to use ctdb -X
[Samba.git] / ctdb / tests / simple / 55_ctdb_ptrans.sh
blob14de67efa6fad739313cfd2416a976bfba2df43e
1 #!/bin/bash
3 test_info()
5 cat <<EOF
6 Verify that the ctdb ptrans works as expected
8 Prerequisites:
10 * An active CTDB cluster with at least 2 active nodes.
12 Steps:
14 1. Verify that the status on all of the ctdb nodes is 'OK'.
15 2. Pipe some operation to ctdb ptrans and validate the TDB contents with ctdb catdb
17 Expected results:
19 * ctdb ptrans works as expected.
20 EOF
23 . "${TEST_SCRIPTS_DIR}/integration.bash"
25 ctdb_test_init "$@"
27 set -e
29 cluster_is_healthy
31 TESTDB="ptrans_test.tdb"
33 # Create a temporary persistent database to test with
34 echo "create persistent test database $TESTDB"
35 try_command_on_node 0 $CTDB attach $TESTDB persistent
37 # Wipe Test database
38 echo "wipe test database"
39 try_command_on_node 0 $CTDB wipedb $TESTDB
41 ##########
43 echo "Adding 3 records"
45 items='\
46 "key1" "value1"
47 "key2" "value1"
48 "key3" "value1"'
50 echo "$items" | try_command_on_node -i 0 $CTDB ptrans "$TESTDB"
52 try_command_on_node 0 $CTDB catdb "$TESTDB"
54 n=$(echo "$out" | grep -c '^key.*= "key.*"' || true)
56 if [ $n -ne 3 ] ; then
57 echo "BAD: expected 3 keys in..."
58 echo "$out"
59 exit 1
60 else
61 echo "GOOD: 3 records were inserted"
64 ##########
66 echo "Deleting 1 record, updating 1, adding 1 new record, 1 bogus input line"
68 items='\
69 "key1" ""
70 "key2" "value2"
71 "key3"
72 "key4" "value1"'
74 echo "$items" | try_command_on_node -i 0 $CTDB ptrans "$TESTDB"
76 try_command_on_node 0 $CTDB catdb "$TESTDB"
78 n=$(echo "$out" | grep -c '^key.*= "key.*"' || true)
80 if [ $n -ne 3 ] ; then
81 echo "BAD: expected 3 keys in..."
82 echo "$out"
83 exit 1
84 else
85 echo "GOOD: 3 records found"
88 ##########
90 echo "Verifying records"
92 while read key value ; do
93 try_command_on_node 0 $CTDB pfetch "$TESTDB" "$key"
94 if [ "$value" != "$out" ] ; then
95 echo "BAD: for key \"$key\" expected \"$value\" but got \"$out\""
96 exit 1
97 else
98 echo "GOOD: for key \"$key\" got \"$out\""
100 done <<EOF
101 key2 value2
102 key3 value1
103 key4 value1
106 ##########
108 echo "Deleting all records"
110 items='\
111 "key2" ""
112 "key3" ""
113 "key4" ""'
115 echo "$items" | try_command_on_node -i 0 $CTDB ptrans "$TESTDB"
117 try_command_on_node 0 $CTDB catdb "$TESTDB"
119 n=$(echo "$out" | grep -c '^key.*= "key.*"' || true)
121 if [ $n -ne 0 ] ; then
122 echo "BAD: expected 0 keys in..."
123 echo "$out"
124 exit 1
125 else
126 echo "GOOD: 0 records found"