pgpool2.git / summary / log / commit / refs
commit 9164a98cdadab1ba9ccb49ee613cc223fa693dda
Author: Tatsuo Ishii <ishii@postgresql.org>
Commit: Muhammad Usama <m.usama@gmail.com>
Date: Sat Jan 25 03:05:21 2014 +0000
Add new regression test for query cache.
.../regression/tests/006.memqcache/expected.txt | 1 +
.../regression/tests/006.memqcache/jdbctest.java | 52 +++++++++++++++++++++
src/test/regression/tests/006.memqcache/test.sh | 53 ++++++++++++++++++++++
3 files changed, 106 insertions(+)
diff --git a/src/test/regression/tests/006.memqcache/expected.txt b/src/test/regression/tests/006.memqcache/expected.txt
new file mode 100644
index 000000000..0cfbf0888
--- /dev/null
+++ b/src/test/regression/tests/006.memqcache/expected.txt
@@ -0,0 +1 @@
+2
diff --git a/src/test/regression/tests/006.memqcache/jdbctest.java b/src/test/regression/tests/006.memqcache/jdbctest.java
new file mode 100644
index 000000000..29ecb9897
--- /dev/null
+++ b/src/test/regression/tests/006.memqcache/jdbctest.java
@@ -0,0 +1,52 @@
+import java.sql.*;
+import javax.sql.*;
+import java.util.*;
+import java.io.*;
+
+public class jdbctest {
+ public static void main(String[] args) {
+ try {
+
+ Properties prop = new Properties();
+ prop.load(new FileInputStream("jdbctest.prop"));
+ String url = prop.getProperty("jdbc.url");
+ String user = prop.getProperty("jdbc.user");
+ String pwd = prop.getProperty("jdbc.password");
+
+ Connection conn = DriverManager.getConnection(url, user, pwd);
+ conn.setAutoCommit(true);
+ String sql = "INSERT INTO t1 VALUES (1);";
+ Statement pst = conn.createStatement();
+ pst.executeUpdate(sql);
+ pst.close();
+ PreparedStatement prest = conn.prepareStatement("SELECT * FROM t1");
+ ResultSet rs = prest.executeQuery();
+ rs.next();
+ rs.close();
+ prest.close();
+
+ /*
+ * Cache test in a explicit transaction
+ */
+ conn.setAutoCommit(false);
+ // execute DML. This should prevent SELECTs from using query cache in the transaction.
+ sql = "UPDATE t1 SET i = 2;";
+ pst = conn.createStatement();
+ pst.executeUpdate(sql);
+ pst.close();
+ // should not use the cache and should return "2", rather than "1"
+ prest = conn.prepareStatement("SELECT * FROM t1");
+ rs = prest.executeQuery();
+ rs.next();
+ System.out.println(rs.getInt(1));
+ rs.close();
+ prest.close();
+ conn.commit();
+ conn.close();
+
+ } catch (Exception e) {
+ System.err.println("jdbctest: ERROR: " + e);
+ System.exit(1);
+ }
+ }
+}
diff --git a/src/test/regression/tests/006.memqcache/test.sh b/src/test/regression/tests/006.memqcache/test.sh
new file mode 100755
index 000000000..340ab57b4
--- /dev/null
+++ b/src/test/regression/tests/006.memqcache/test.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+#-------------------------------------------------------------------
+# test script for memqcache.
+# requires Java PostgreSQL JDBC driver.
+PGBENCH=$PGBENCH_PATH
+
+WHOAMI=`whoami`
+source $TESTLIBS
+TESTDIR=testdir
+
+for mode in s r n
+do
+ rm -fr $TESTDIR
+ mkdir $TESTDIR
+ cd $TESTDIR
+
+# create test environment
+ echo -n "creating test environment..."
+ sh $PGPOOL_SETUP -m $mode -n 2 || exit 1
+ echo "done."
+
+ echo "memory_cache_enabled = on" >> etc/pgpool.conf
+
+ source ./bashrc.ports
+
+ export PGPORT=$PGPOOL_PORT
+
+ echo "jdbc.url=jdbc:postgresql://localhost:$PGPOOL_PORT/test" > jdbctest.prop
+ echo "jdbc.user=$WHOAMI" >> jdbctest.prop
+ echo "jdbc.password=" >> jdbctest.prop
+ cp ../jdbctest.java .
+ javac jdbctest.java
+ export CLASSPATH=.:$JDBC_DRIVER
+ ./startall
+ wait_for_pgpool_startup
+
+ psql test <<EOF
+CREATE TABLE t1 (i int);
+EOF
+
+ java jdbctest > result.txt 2>&1
+ cmp ../expected.txt result.txt
+ if [ $? != 0 ];then
+ ./shutdownall
+ exit 1
+ fi
+
+ ./shutdownall
+
+ cd ..
+done
+
+exit 0
[parent: 7519f7d5cfc7]