From b9680c86ebdc1956af69665cf60f6b55554be20e Mon Sep 17 00:00:00 2001 From: KamleshKumar427 Date: Fri, 5 May 2023 00:00:04 +0500 Subject: [PATCH] regression test for cypher load balancing added --- src/test/regression/README | 2 +- .../tests/01.Cypher_load_balance/.gitignore | 1 + .../tests/01.Cypher_load_balance/test.sh | 188 ++++++++++++++++++ 3 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 src/test/regression/tests/01.Cypher_load_balance/.gitignore create mode 100644 src/test/regression/tests/01.Cypher_load_balance/test.sh diff --git a/src/test/regression/README b/src/test/regression/README index 6af63c6a5..9f753a0f0 100644 --- a/src/test/regression/README +++ b/src/test/regression/README @@ -19,7 +19,7 @@ tests: test scripts live here. Each test case has its own should return non 0 value. To add a new test case, simply create a shell script under this. - The test name "001.*" to "050.*" is for regular regression + The test name "01.*" and "001.*" to "050.*" is for regular regression tests, while after "051.*" are for bugs. regress.sh exports following environment variables which can be diff --git a/src/test/regression/tests/01.Cypher_load_balance/.gitignore b/src/test/regression/tests/01.Cypher_load_balance/.gitignore new file mode 100644 index 000000000..f937fcb17 --- /dev/null +++ b/src/test/regression/tests/01.Cypher_load_balance/.gitignore @@ -0,0 +1 @@ +testdir/ diff --git a/src/test/regression/tests/01.Cypher_load_balance/test.sh b/src/test/regression/tests/01.Cypher_load_balance/test.sh new file mode 100644 index 000000000..49fcd3302 --- /dev/null +++ b/src/test/regression/tests/01.Cypher_load_balance/test.sh @@ -0,0 +1,188 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------- +# test script for load balancing. +# +source $TESTLIBS +TESTDIR=testdir +PSQL=$PGBIN/psql + +# sleep time after reload in seconds +st=10 + +for mode in r +do + rm -fr $TESTDIR + mkdir $TESTDIR + cd $TESTDIR + +# create test environment + echo -n "creating test environment..." + $PGPOOL_SETUP -m $mode -n 2 || exit 1 + echo "done." + + source ./bashrc.ports + + echo "backend_weight0 = 0" >> etc/pgpool.conf + echo "backend_weight1 = 1" >> etc/pgpool.conf + echo "statement_level_load_balance = on" >> etc/pgpool.conf + + + ./startall + + export PGPORT=$PGPOOL_PORT + + wait_for_pgpool_startup + + $PSQL -p 11002 template1 </dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: select is sent to zero-weight node. + ./shutdownall + exit 1 + fi + echo ok: simple load balance works. + + +# check a set of cypher queries: + + $PSQL template1 <(b) RETURN a.name \$\$) AS (a agtype); + +EOF + +# check if Create queries are sent to node 0 + fgrep "CREATE (p:Person {name: 'Alice', age: 30}) RETURN p.name" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Write queries sent to secondary node. + ./shutdownall + exit 1 + fi + fgrep "CREATE (p:Person {name: 'Bob', age: 35}) RETURN p.name" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Write queries sent to secondary node. + ./shutdownall + exit 1 + fi + fgrep "MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) CREATE (a)-[:FRIENDS_WITH]->(b) RETURN a.name" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Write queries sent to secondary node. + ./shutdownall + exit 1 + fi + echo ok: Wrtie queries work. + + + +# Read and Update query + $PSQL template1 <(b:Person) RETURN a.name \$\$) AS (a agtype); + +-- Update Alice's age +SELECT * FROM cypher('test_graph', \$\$ MATCH (p:Person {name: 'Alice'}) SET p.age = 31 RETURN p.age \$\$) AS (a agtype); + +-- Merge a new node or update if exists with the same name +SELECT * FROM cypher('test_graph', \$\$ MERGE (p:Person {name: 'Charlie', age: 25}) RETURN p.name \$\$) AS (a agtype); + +-- Delete the relationship between Alice and Bob +SELECT * FROM cypher('test_graph', \$\$ MATCH (a:Person {name: 'Alice'})-[r:FRIENDS_WITH]->(b:Person {name: 'Bob'}) DELETE r RETURN a.age \$\$) AS (a agtype); + +-- Delete the node for Charlie +SELECT * FROM cypher('test_graph', \$\$ MATCH (p:Person {name: 'Charlie'}) DETACH DELETE p RETURN p.name \$\$) AS (a agtype); + +EOF + +# check if Read queries are sent to node 1 + + fgrep "MATCH (p:Person) RETURN p.name" log/pgpool.log |grep "DB node id: 1">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Read query sent to primary node. + ./shutdownall + exit 1 + fi + + fgrep "MATCH (a:Person)-[r:FRIENDS_WITH]->(b:Person) RETURN a.name" log/pgpool.log |grep "DB node id: 1">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Read query sent to primary node. + ./shutdownall + exit 1 + fi + + fgrep "MATCH (p:Person {name: 'Alice'}) SET p.age = 31 RETURN p.age" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Update query sent to secondary node. + ./shutdownall + exit 1 + fi + + fgrep "MERGE (p:Person {name: 'Charlie', age: 25}) RETURN p.name" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Merge query sent to secondary node. + ./shutdownall + exit 1 + fi + + fgrep "MATCH (a:Person {name: 'Alice'})-[r:FRIENDS_WITH]->(b:Person {name: 'Bob'}) DELETE r RETURN a.age" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Delete relationship query sent to secondary node. + ./shutdownall + exit 1 + fi + + fgrep "MATCH (p:Person {name: 'Charlie'}) DETACH DELETE p RETURN p.name" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: Delete node query sent to secondary node. + ./shutdownall + exit 1 + fi + + echo ok: Wrtie queries work. + + + ./shutdownall + + cd .. + +done +exit 0