-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·141 lines (106 loc) · 3.27 KB
/
test.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
set -e
###
# Set up basic variables
###
# PIDs to clean up before exiting
CLEANUPPID=""
# Directory where script resides
RUNDIR=$(readlink -m $(dirname "$0"))
cd "$RUNDIR"
###
# Kill the background processes before exiting
###
function finish {
if [ ! -z "$CLEANUPPID" ]
then
eval kill $CLEANUPPID
fi
}
trap finish EXIT
##
# Clean last run
rm -rf target/integ-working
export fbdir=$(readlink -m ../Friendly-Backup)
#TODO bobby uncomment
#for testbasedir in test/integ/happy*
for testbasedir in test/integ/happy1
do
testname=$(basename $testbasedir)
# Install and start up each client
for srcdir in $testbasedir/client*
do
testdir=target/integ-working/$testname/$(basename $srcdir)
# install FriendlyBackup
"$fbdir/install.sh" "$testdir"
# Copy test client config, identity, etc.
[ -d "$srcdir"/dir-to-backup ] && cp -r "$srcdir"/dir-to-backup "$testdir"
cp -r "$srcdir"/gnupg "$testdir/var/"
cp "$srcdir"/BackupConfig.properties "$testdir"/var/
# Clean logs & start process
pushd "$testdir"
rm -f logs/*.log
./bin/run.sh > ./run.out &
CLEANUPPID="$! $CLEANUPPID "
popd
done
# wait for the clients to begin listening
sleep 1
cd "$RUNDIR"
TESTCLIENTBASE=target/integ-working/$testname/client1/
# Start the backup
tail -f $TESTCLIENTBASE/logs/service.log | sed '/Starting backup/ q' > /dev/null&
pid=$!
touch "$TESTCLIENTBASE/backup.txt"
echo "Waiting for backup to start"
wait $pid
echo "Backup started"
tail -f $TESTCLIENTBASE/logs/service.log | sed '/Backup complete/ q' > /dev/null
echo "Backup complete"
tail -f $TESTCLIENTBASE/logs/service.log | sed '/Starting restore/ q' > /dev/null&
pid=$!
touch "$TESTCLIENTBASE/restore.txt"
echo "Waiting for restore to start"
wait $pid
echo "Restore started"
tail -f $TESTCLIENTBASE/logs/service.log | sed '/Restore complete/ q' > /dev/null
echo "Restore complete"
eval kill $CLEANUPPID
CLEANUPPID=
if diff -qr "$TESTCLIENTBASE/dir-to-backup/" "$TESTCLIENTBASE/restore-dir/"
then
echo "Test passed"
else
echo "Test failed - backup & restore files not the same" 1>&2
fi
done
# mkdir -p target/integ-working/happy2
cat > /dev/null <<EOF
Backup backup = new Backup(app.getBackupConfig());
backup.doBackup();
Restore restore = new Restore(app.getBackupConfig());
restore.doRestore();
Assert.assertTrue(compareDirectories(
app.getBackupConfig().getBackupRootDirectories()[0],
app.getBackupConfig().getRestoreRootDirectory()));
EOF
cat > /dev/null <<EOF
//wait for everyone to get started listening
Thread.sleep(100);
//clean out the db
for(TestNode tn : testNodes) {
File dbRoot = tn.getDBFile();
cleanDirectory(dbRoot.getParentFile());
}
testNodes[0].backup();
tryRestore();
tryRestore();
//touch a backup file
File f = new File("test/integ/happy2/config1/dir-to-backup/hi.txt");
FileOutputStream fos = new FileOutputStream(f, true);
fos.write('A');
fos.close();
Thread.sleep(500);
testNodes[0].backup();
tryRestore();
tryRestore();
EOF