# Data Maintenance test
run_id=$1
stream=$2
startdate=`date +%m-%d-%H:%M:%S.%2N`
echo "Maintenance test $run_id start date: ${startdate}"
echo "Maintenance test $run_id start date: ${startdate}" >> ../logs/mt_${run_id}.log
# do a refresh for each stream
loop_id=1
while [ $loop_id -le $stream ]
do
  ref_id=$(( $stream * ($run_id - 1) + $loop_id ))
  # refresh for this ref_id
    startdate=`date +%m-%d-%H:%M:%S.%2N`
    rm -rf *.sql
    cp ../maintenance/*.sql .

    echo "Refresh $ref_id start date: ${startdate}"
    echo "Refresh $ref_id start date: ${startdate}" >> ../logs/mt_${run_id}.log
    ./replace.sh $ref_id >> ../logs/mt_${run_id}.log 2>&1
    ./refresh.sh $ref_id
    enddate=`date +%m-%d-%H:%M:%S.%2N`
    echo "Refresh $ref_id end date: ${enddate}"
    echo "Refresh $ref_id end date: ${enddate}" >> ../logs/mt_${run_id}.log
    # backup test sqls
    mkdir -p mt_${ref_id}
    rm -rf mt_${ref_id}/*.sql
    cp *.sql mt_${ref_id}/
	
  ((loop_id++))
done

enddate=`date +%m-%d-%H:%M:%S.%2N`
echo "Maintenance test $run_id end date: ${enddate}"
echo "Maintenance test $run_id end date: ${enddate}" >> ../logs/mt_${run_id}.log

