summaryrefslogtreecommitdiff
path: root/ctdb/tests/simple/55_ctdb_ptrans.sh
blob: ba92899a6130ebdce1388227bbacc6d7f64559fd (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash

test_info()
{
    cat <<EOF
Verify that the ctdb ptrans works as expected

Prerequisites:

* An active CTDB cluster with at least 2 active nodes.

Steps:

1. Verify that the status on all of the ctdb nodes is 'OK'.
2. Pipe some operation to ctdb ptrans and validate the TDB contents with ctdb catdb

Expected results:

* ctdb ptrans works as expected.
EOF
}

. "${TEST_SCRIPTS_DIR}/integration.bash"

ctdb_test_init "$@"

set -e

cluster_is_healthy

TESTDB="ptrans_test.tdb"

# Create a temporary persistent database to test with
echo "create persistent test database $TESTDB"
try_command_on_node 0 $CTDB attach $TESTDB persistent

# Wipe Test database
echo "wipe test database"
try_command_on_node 0 $CTDB wipedb $TESTDB

##########

echo "Adding 3 records"

items='
"key1" "value1"
"key2" "value1"
"key3" "value1"'

echo "$items" | try_command_on_node -i 0 $CTDB ptrans "$TESTDB"

try_command_on_node 0 $CTDB catdb "$TESTDB"

n=$(echo "$out" | grep -c '^key.*= "key.*"' || true)

if [ $n -ne 3 ] ; then
    echo "BAD: expected 3 keys in..."
    echo "$out"
    exit 1
else
    echo "GOOD: 3 records were inserted"
fi

##########

echo "Deleting 1 record, updating 1, adding 1 new record, 1 bogus input line"

items='
"key1" ""
"key2" "value2"
"key3"
"key4" "value1"'

echo "$items" | try_command_on_node -i 0 $CTDB ptrans "$TESTDB"

try_command_on_node 0 $CTDB catdb "$TESTDB"

n=$(echo "$out" | grep -c '^key.*= "key.*"' || true)

if [ $n -ne 3 ] ; then
    echo "BAD: expected 3 keys in..."
    echo "$out"
    exit 1
else
    echo "GOOD: 3 records found"
fi

##########

echo "Verifying records"

while read key value ; do
    try_command_on_node 0 $CTDB pfetch "$TESTDB" "$key"
    if [ "$value" != "$out" ] ; then
	echo "BAD: for key \"$key\" expected \"$value\" but got \"$out\""
	exit 1
    else
	echo "GOOD: for key \"$key\" got \"$out\""
    fi
done <<EOF
key2 value2
key3 value1
key4 value1
EOF

##########

echo "Deleting all records"

items='
"key2" ""
"key3" ""
"key4" ""'

echo "$items" | try_command_on_node -i 0 $CTDB ptrans "$TESTDB"

try_command_on_node 0 $CTDB catdb "$TESTDB"

n=$(echo "$out" | grep -c '^key.*= "key.*"' || true)

if [ $n -ne 0 ] ; then
    echo "BAD: expected 0 keys in..."
    echo "$out"
    exit 1
else
    echo "GOOD: 0 records found"
fi