

rm -rf ./tmp/pstore/*
rm -f *.txt

if [ "$OSPL_HOME" = "" ];then
echo "*** Please source release.com to set OpenSplice environment variables";
echo "*** ERROR OpenSplice environment variables NOT SET"
exit;
fi
echo "=== OSPL_HOME is "${OSPL_HOME}
echo "=== OSPL_URI is "${OSPL_URI}

if [ -z "$JAVA_HOME" ]; then
    echo "WARNING: JAVA_HOME not defined. Cannot find libjsig.so and set LD_PRELOAD"
    echo "         This could prevent cleanup of Java application at exit"
else
   OSPL_JSIG=`find $JAVA_HOME -follow -name libjsig.so | grep -v server/libjsig.so | grep -v client/libjsig.so`

   if [ -z "$OSPL_JSIG" ]; then
      echo "WARNING: Unable to find libjsig.so in JAVA_HOME: $JAVA_HOME"
      echo "         This could prevent cleanup of Java application at exit"
   fi
fi

if [ "$EXRUNTYPE" = "shm" ]
then
   OSPL_URI=file://$OSPL_HOME/examples/dcps/Durability/ospl_shm.xml
else
   OSPL_URI=file://$OSPL_HOME/examples/dcps/Durability/ospl_sp.xml
fi

export OSPL_URI

if [ "$OSPL_HOME" = "" ]
then
   echo "*** Please source release.com to set OpenSplice environment variables";
   echo "*** ERROR OpenSplice environment variables NOT SET"
   exit;
fi

if [ "$EXRUNTYPE" = "shm" ]
then
   $VG_OSPL_START ospl stop
   sleep 2

   $VG_OSPL_START ospl start
   $VG_START_SLEEP
fi

echo "============================="
echo "==== Scenario 3.1      ======"
echo "============================="
echo " ===== Launching durability subscriber"

LD_PRELOAD=$OSPL_JSIG $SPLICE_JAVA -classpath $OSPL_HOME/jar/dcpssaj.jar:classes:$SPLICE_EXTRA_CP DurabilityDataSubscriber transient > subResult_3_1.txt &

sleep 5

echo " ===== Launching durability publisher"

LD_PRELOAD=$OSPL_JSIG $SPLICE_JAVA -classpath $OSPL_HOME/jar/dcpssaj.jar:classes:$SPLICE_EXTRA_CP DurabilityDataPublisher transient true true > pubResult_3_1.txt &

#Rather than kill the publisher just wait till it completes.
echo "===== Sleep 30s to let the publisher complete "
sleep 30

echo "=== Scenario 3.1 done"

echo "=== Checking Durability Subscriber results Scenario 3.1"
grep "^[0-9]" subResult_3_1.txt > tail_subResult.txt

diff -w tail_subResult.txt ../../expected_result > subdiff.txt
if [ -s subdiff.txt ] || [ ! -r subResult_3_1.txt ];then
   echo NOK
   echo "*** ERROR : example Durability failed ";
   cat subdiff.txt;
else
   echo OK
fi

echo "============================="
echo "==== Scenario 3.2      ======"
echo "============================="

if [ "$EXRUNTYPE" = "shm" ]
then
   $VG_OSPL_START ospl stop
   sleep 2

   $VG_OSPL_START ospl start
   $VG_START_SLEEP
fi

echo === running a first Subscriber
LD_PRELOAD=$OSPL_JSIG $SPLICE_JAVA -classpath $OSPL_HOME/jar/dcpssaj.jar:classes:$SPLICE_EXTRA_CP DurabilityDataSubscriber transient > subResult_3_2_1.txt &
echo "=== End of first DurabilityDataSubscriber  (Scenario 3.2)"

sleep 5

echo " ===== Launching durability publisher"

LD_PRELOAD=$OSPL_JSIG $SPLICE_JAVA -classpath $OSPL_HOME/jar/dcpssaj.jar:classes:$SPLICE_EXTRA_CP DurabilityDataPublisher transient false true > pubResult_3_2.txt &

sleep 5

echo === running a second Subscriber
LD_PRELOAD=$OSPL_JSIG $SPLICE_JAVA -classpath $OSPL_HOME/jar/dcpssaj.jar:classes:$SPLICE_EXTRA_CP DurabilityDataSubscriber transient > subResult_3_2_2.txt &
echo "=== End of second DurabilityDataSubscriber  (Scenario 3.2)"

#Rather than kill the publisher just wait till it completes.
echo "===== Sleep 30s to let the publisher complete "
sleep 30

echo "=== Checking Durability second Subscriber results Scenario 3.2"
# Checking only result of second subscriber
grep "^[0-9]" subResult_3_2_2.txt > tail_subResult.txt

diff -w tail_subResult.txt ../../expected_result > subdiff.txt
if [ -s subdiff.txt ] || [ ! -r subResult_3_2_2.txt ];then
   echo NOK
   echo "*** ERROR : example Durability failed ";
cat subdiff.txt;
   else
   echo OK
fi

echo "============================="
echo "==== Scenario 3.3      ======"
echo "============================="

if [ "$EXRUNTYPE" = "shm" ]
then
   $VG_OSPL_START ospl stop
   sleep 2

   $VG_OSPL_START ospl start
   $VG_START_SLEEP
fi

echo === running a first Subscriber
LD_PRELOAD=$OSPL_JSIG $SPLICE_JAVA -classpath $OSPL_HOME/jar/dcpssaj.jar:classes:$SPLICE_EXTRA_CP DurabilityDataSubscriber persistent > subResult_3_3_1.txt &
echo "=== End of first DurabilityDataSubscriber  (Scenario 3.3)"

sleep 5

echo " ===== Launching durability publisher"

LD_PRELOAD=$OSPL_JSIG $SPLICE_JAVA -classpath $OSPL_HOME/jar/dcpssaj.jar:classes:$SPLICE_EXTRA_CP DurabilityDataPublisher persistent false true > pubResult_3_3.txt &

#Rather than kill the publisher just wait till it completes.
echo "===== Sleep 30s to let the publisher complete "
sleep 30

if [ "$EXRUNTYPE" = "shm" ]
then
   $VG_OSPL_START ospl stop
   sleep 2

   $VG_OSPL_START ospl start
   $VG_START_SLEEP

   sleep 15
fi

echo === running a second Subscriber
LD_PRELOAD=$OSPL_JSIG $SPLICE_JAVA -classpath $OSPL_HOME/jar/dcpssaj.jar:classes:$SPLICE_EXTRA_CP DurabilityDataSubscriber persistent > subResult_3_3_2.txt &
echo "=== End of first DurabilityDataSubscriber  (Scenario 3.3)"

sleep 20

echo "=== Checking Durability second Subscriber results Scenario 3.3"
echo "    (not empty after restarting OpenSplice)"
# Checking only result of second subscriber
grep "^[0-9]" subResult_3_3_2.txt > tail_subResult.txt
if [ -s tail_subResult.txt ];then
   echo OK
else
   echo NOK
   echo "*** ERROR : example Durability failed ";
fi

if [ "$EXRUNTYPE" = "shm" ]
then
   # Don't kill it too soon.
   sleep 5
   $VG_OSPL_START ospl stop
   sleep 2
fi
