#!/bin/bash
#
# Copyright 2011-2012 Akiban Technologies, Inc.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
#

#-----------------------------
# This is a working template for a simple script to perform crash
# recovery testing in Persistit.  This script should be run from the
# root directory of the Persistit project. As configured, this
# script runs the recovery_1.plan stress test for 60 seconds, 
# kills the JVM and then runs the recovery_2.plan to verify
# consistency.
#-----------------------------

sleep_time=180
datapath="/tmp/persistit_test_data"

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

testrunner_command="java $jvm_options -cp `find . -name akiban-persistit\*with-dependencies\*.jar` -Dstress_recovery_test_signature=1 "

command="$testrunner_command com.persistit.stress.Recovery1 datapath=$datapath"
echo "$command  > $datapath/recovery.log"
$command > $datapath/recovery.log &

echo "Sleeping for $sleep_time seconds"
sleep $sleep_time

while background_pid=`pgrep -f "stress_recovery_test_signature=1"`
do
  echo "kill -9 $background_pid"
  kill -9 $background_pid
  sleep 1
done

echo -----

command="$testrunner_command com.persistit.stress.Recovery2 datapath=$datapath"
echo $command
$command
sleep 2

