#!/usr/bin/env bash

# expected results: Parse: 0 Parse: 1 Parse: 2 Execute:0 Execute:1 Execute:2
set 0 1 2 0 1 2
grep "BEGIN" $PGPOOLLOG | grep "LOG" | awk '{print $9}' | while read node
do
	if [ $1 -ne $node ]; then
		echo "expected: $1 result: $node"
		exit 99
	fi
	shift
done

if [ $? = 99 ]; then
	exit 1
fi

# expected results: Parse: 0 Parse: 1 Parse: 2 Execute:0 Execute:1 Execute:2
set 0 1 2 0 1 2
grep "COMMIT" $PGPOOLLOG | grep "LOG" | awk '{print $9}' | while read node
do
	if [ $1 -ne $node ]; then
		echo "expected: $1 result: $node"
		exit 99
	fi
	shift
done

if [ $? = 99 ]; then
	exit 1
fi

# select load balance node per query
n=`grep "selecting load balance node" $PGPOOLLOG | wc -l`
if [ $n != 5 ]; then
	exit 1
fi

exit 0
