#!/bin/bash

#-----------------------------
# This is a working template for a script to perform crash
# recovery testing in Persistit using two machines.
# This script should be run from the root directory of the Persistit
# project. As configured, this script runs the recovery_1.plan stress 
# on a target server specified in $1 until that machine is stopped
# via power failure or other crash.
#
# To run this test:
#
#   ./src/test/resources/stress-recovery-remote1 username@remotehost remote_directory_path
# 
#
# Where remote_directory_path is the full path on the remote machine to the
# root of an akiban-persistit working directory.
#
# After the desired period of time, crash the remote machine.
#
# To complete the test, restart the target machine and then run
# stress-recovery-remote2.
#
# This tests assumes some predefined directories:
#
# On the local machine, this test writes the ticket stream to
#     /tmp/persistit_test_data/recovery.log
#
# On the target machine, this test creates the directory ~/persistit_test_data
# (relative to the remote user) to hold Volume and Journal files (Note: that 
# /tmp/persistit_test_data is not used since rebooting the machine removes data
# from /tmp.)
#
# On the target side, this test also assumes you have created a branch of
# the akiban-persistit project in some directory.  Supply that directory
# path as the second
#-----------------------------

local_datapath=/tmp/persistit_test_data
remote_datapath="~/persistit_test_data"

jvm_options="-Xmx2G -Xrunjdwp:transport=dt_socket,address=8000,suspend=n,server=y"

testrunner_command="cd $2; mkdir -p $remote_datapath  ; rm $remote_datapath/persistit* ; java $jvm_options -cp \`find . -name akiban-persistit\*with-dependencies\*.jar\` "

command="ssh $1 $testrunner_command com.persistit.stress.Recovery1 datapath=$remote_datapath"

echo "$command > $local_datapath/recovery.log"
$command > $local_datapath/recovery.log

