db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1619376 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/ suites/ tests/storetests/
Date Thu, 21 Aug 2014 12:26:42 GMT
Author: kahatlen
Date: Thu Aug 21 12:26:41 2014
New Revision: 1619376

URL: http://svn.apache.org/r1619376
Log:
DERBY-6709: Convert the storetests suite to JUnit

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/Derby94Test.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/_Suite.java   (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/derby94.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/st_derby1939.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/st_derby715.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/st_reclaim_longcol.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/st_schema.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storetests.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storetests.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/default_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/default_derby.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94_derby.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby715_derby.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby715_sed.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_schema.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_schema_app.properties
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeall.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemats.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeunit.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby1939.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby715.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_reclaim_longcol.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java?rev=1619376&r1=1619375&r2=1619376&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java Thu Aug 21 12:26:41 2014
@@ -93,6 +93,7 @@ public class AllPackages extends BaseTes
              org.apache.derbyTesting.functionTests.tests.largedata.LobLimitsLiteTest.class);
         classes.add(org.apache.derbyTesting.functionTests.tests.jdbcapi._Suite.class);
         classes.add(org.apache.derbyTesting.functionTests.tests.store._Suite.class);
+        classes.add(org.apache.derbyTesting.functionTests.tests.storetests._Suite.class);
         classes.add(org.apache.derbyTesting.functionTests.tests.tools._Suite.class);
         classes.add(org.apache.derbyTesting.functionTests.tests.engine._Suite.class);
         classes.add(org.apache.derbyTesting.functionTests.tests.demo._Suite.class);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeall.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeall.properties?rev=1619376&r1=1619375&r2=1619376&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeall.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeall.properties Thu Aug 21 12:26:41 2014
@@ -19,7 +19,6 @@
 #    storeall
 #        storemats
 #        storemore
-#        storetests
 #        storeunit
 #
 #    Each store test should only appear ONCE in one of the following, this is
@@ -29,9 +28,8 @@
 #        storemats.runall       - all other store tests to be run in storemats
 #        storemore.runall       - any other store function test not to be included in
 #                                 storemats, but to be run nightly.
-#        storetests.runall      - set of store tests that use one database 
 #        storeunit.runall       - set of store unit tests 
 #        storerecovery.runall   - set of recovery tests that use one database
 #        
-suites=storemore storemats storetests storeunit storerecovery
+suites=storemore storemats storeunit storerecovery
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemats.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemats.properties?rev=1619376&r1=1619375&r2=1619376&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemats.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemats.properties Thu Aug 21 12:26:41 2014
@@ -19,7 +19,6 @@
 #    storeall
 #        storemats
 #        storemore
-#        storetests
 #        storeunit
 #
 #    Each store test should only appear ONCE in one of the following, this is
@@ -29,7 +28,6 @@
 #        storemats.runall   - all other store tests to be run in storemats
 #        storemore.runall   - any other store test not to be included in
 #                                 storemats, but to be run nightly.
-#        storetests.runall  - a set of tests that share the same database
 #        storeunit.runall   - a set of store unit tests
 #
 #        

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeunit.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeunit.properties?rev=1619376&r1=1619375&r2=1619376&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeunit.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storeunit.properties Thu Aug 21 12:26:41 2014
@@ -19,7 +19,6 @@
 #    storeall
 #        storemats - basic set
 #        storemore - more tests
-#        storetests- use 1 database
 #        storeunit - unit tests
 #    xa - xa tests (partially store, partially language tests)
 #

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/Derby94Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/Derby94Test.java?rev=1619376&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/Derby94Test.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/Derby94Test.java Thu Aug 21 12:26:41 2014
@@ -0,0 +1,146 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.storetests.Derby94Test
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.storetests;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Regression test case for DERBY-94, which prevented some locks from
+ * being released at the end of the transaction if lock escalation had
+ * happened.
+ */
+public class Derby94Test extends BaseJDBCTestCase {
+    public Derby94Test(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        Test test = TestConfiguration.embeddedSuite(Derby94Test.class);
+        // Reduce lock escalation threshold to make it possible to test
+        // with fewer rows.
+        test = DatabasePropertyTestSetup.singleProperty(
+                test, "derby.locks.escalationThreshold", "102");
+        test = new CleanDatabaseTestSetup(test);
+        return test;
+    }
+
+    public void testDerby94() throws SQLException {
+        setAutoCommit(false);
+
+        PreparedStatement locktable = prepareStatement(
+                "select type, lockcount, mode, tablename, lockname, state "
+                        + "from syscs_diag.lock_table "
+                        + "order by tablename, type desc, mode, "
+                        + "lockcount, lockname");
+
+        Statement s = createStatement();
+
+        s.execute("create table t1(c1 int, c2 int not null primary key)");
+        s.execute("create table t2(c1 int)");
+
+        PreparedStatement ins1 = prepareStatement(
+                                        "insert into t1 values (?, ?)");
+        for (int i = 0; i < 160; i++) {
+            ins1.setInt(1, i);
+            ins1.setInt(2, 200 + i);
+            ins1.execute();
+        }
+
+        s.execute("insert into t2 values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9");
+
+        commit();
+
+        Statement s1 = createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                                       ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs1 = s1.executeQuery("select * from t1 for update of c1");
+
+        assertTrue(rs1.next());
+        assertEquals(0, rs1.getInt("c1"));
+        assertEquals(200, rs1.getInt("c2"));
+        rs1.updateInt("c1", 999);
+        rs1.updateRow();
+
+        assertTrue(rs1.next());
+        assertEquals(1, rs1.getInt("c1"));
+        assertEquals(201, rs1.getInt("c2"));
+
+        Statement s2 = createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                                       ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs2 = s2.executeQuery("select * from t2 for update of c1");
+        assertTrue(rs2.next());
+        assertEquals(0, rs2.getInt("c1"));
+
+        JDBC.assertFullResultSet(
+                locktable.executeQuery(),
+                new String[][] {
+                    { "TABLE", "2", "IX", "T1", "Tablelock", "GRANT" },
+                    { "ROW",   "1", "U",  "T1", "(1,8)",     "GRANT" },
+                    { "ROW",   "1", "X",  "T1", "(1,7)",     "GRANT" },
+                    { "TABLE", "1", "IX", "T2", "Tablelock", "GRANT" },
+                    { "ROW",   "1", "U",  "T2", "(1,7)",     "GRANT" },
+                });
+
+        // The following insert should get X lock on t2 because of escalation,
+        // but should leave U lock on t1 as it is.
+        assertUpdateCount(s, 160, "insert into t2 select c1 from t1");
+
+        JDBC.assertFullResultSet(
+                locktable.executeQuery(),
+                new String[][] {
+                    { "TABLE", "3", "IX", "T1", "Tablelock", "GRANT" },
+                    { "ROW",   "1", "U",  "T1", "(1,8)",     "GRANT" },
+                    { "ROW",   "1", "X",  "T1", "(1,7)",     "GRANT" },
+                    { "TABLE", "4", "IX", "T2", "Tablelock", "GRANT" },
+                    { "TABLE", "1", "X",  "T2", "Tablelock", "GRANT" },
+                });
+
+        // The following update statement should escalate the locks on t1
+        // to table level X lock.
+        assertUpdateCount(s, 160, "update t1 set c1 = c1 + 999");
+
+        JDBC.assertFullResultSet(
+                locktable.executeQuery(),
+                new String[][] {
+                    { "TABLE", "8", "IX", "T1", "Tablelock", "GRANT" },
+                    { "TABLE", "1", "X",  "T1", "Tablelock", "GRANT" },
+                    { "TABLE", "4", "IX", "T2", "Tablelock", "GRANT" },
+                    { "TABLE", "1", "X",  "T2", "Tablelock", "GRANT" },
+                });
+
+        rs1.close();
+        rs2.close();
+        commit();
+
+        // The following lock table dump should not show any locks.
+        // The above commit should have release them.
+        JDBC.assertEmpty(locktable.executeQuery());
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/Derby94Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/_Suite.java?rev=1619376&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/_Suite.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/_Suite.java Thu Aug 21 12:26:41 2014
@@ -0,0 +1,44 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.storetests._Suite
+
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License
+*/
+
+package org.apache.derbyTesting.functionTests.tests.storetests;
+
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.BaseTestSuite;
+
+public class _Suite extends BaseTestCase {
+    private _Suite(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        BaseTestSuite suite = new BaseTestSuite("storetests");
+
+        suite.addTest(st_derby1939.suite());
+        suite.addTest(st_reclaim_longcol.suite());
+        suite.addTest(st_derby715.suite());
+        suite.addTest(Derby94Test.suite());
+
+        return suite;
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/_Suite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/build.xml?rev=1619376&r1=1619375&r2=1619376&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/build.xml (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/build.xml Thu Aug 21 12:26:41 2014
@@ -81,6 +81,7 @@
       destdir="${out.dir}">
       <classpath>
         <pathelement path="${compile.classpath}"/>
+        <pathelement path="${junit}"/>
       </classpath>
       <include name="${this.dir}/*.java"/>
       <compilerarg value="-Xlint"/>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby1939.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby1939.java?rev=1619376&r1=1619375&r2=1619376&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby1939.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby1939.java Thu Aug 21 12:26:41 2014
@@ -22,9 +22,14 @@
  */
 package org.apache.derbyTesting.functionTests.tests.storetests;
 
-import org.apache.derby.tools.ij;
 
 import java.sql.*;
+import java.util.Properties;
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
  * Repro for DERBY-1939.  In effect what we have to do is execute
@@ -50,57 +55,48 @@ import java.sql.*;
  * data in the tables, but having found it we can now reliably
  * reproduce the failure.
  */
-public class st_derby1939 {
+public class st_derby1939 extends BaseJDBCTestCase {
 
 	// We have a VARCHAR column in the table to help with the
 	// hash table "spill-over".
 	private final int VC_SIZE = 1024;
-	private char[] cArr = new char[VC_SIZE];
 
-	public static void main(String [] args)
-	{
-
-		try {
-            System.setProperty("derby.language.maxMemoryPerTable", "140");
-            System.setProperty("derby.optimizer.noTimeout", "true");
-
-            ij.getPropertyArg(args);
-            Connection conn = ij.startJBMS();
-
-            st_derby1939 test = new st_derby1939();
-            test.doLoad(conn);
-            test.doQuery(conn);
-            conn.close();
-		} catch (Throwable t) {
-			System.out.println("OOPS, unexpected error:");
-			t.printStackTrace();
-		}
-	}
+    public st_derby1939(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        Properties sysprops = new Properties();
+        sysprops.setProperty("derby.language.maxMemoryPerTable", "140");
+        sysprops.setProperty("derby.optimizer.noTimeout", "true");
+        return new SystemPropertyTestSetup(
+                new CleanDatabaseTestSetup(
+                        TestConfiguration.embeddedSuite(st_derby1939.class)),
+                sysprops, true);
+    }
+
+    public void testDerby1939() throws SQLException {
+        setAutoCommit(false);
+        doLoad();
+        doQuery();
+    }
 
-	private void doLoad(Connection conn) throws Exception
+    private void doLoad() throws SQLException
 	{
-		conn.setAutoCommit(false);
-		Statement st = conn.createStatement();
-		try {
-			st.execute("drop table d1939_t1");
-		} catch (SQLException se) {}
-		try {
-			st.execute("drop table d1939_t2");
-		} catch (SQLException se) {}
+        Statement st = createStatement();
 
-		System.out.println("Creating tables and index...");
+        println("Creating tables and index...");
 		st.execute("create table d1939_t1 (i smallint, vc varchar(" + VC_SIZE + "))");
 		st.execute("create table d1939_t2 (j smallint, val double, vc varchar(" + VC_SIZE + "))");
 		st.execute("create index ix_d1939_t1 on d1939_t1 (i)");
 
-		PreparedStatement pSt = conn.prepareStatement(
+        PreparedStatement pSt = prepareStatement(
 			"insert into d1939_t1(i, vc) values (?, ?)");
 
-		PreparedStatement pSt2 = conn.prepareStatement(
+        PreparedStatement pSt2 = prepareStatement(
 			"insert into d1939_t2 values (?, ?, ?)");
 
-		String str = null;
-		System.out.println("Doing inserts...");
+        println("Doing inserts...");
 	
 		// Number of rows and columns here is pretty much just "magic";
 		// changing any of them can make it so that the problem doesn't
@@ -115,7 +111,7 @@ public class st_derby1939 {
 			 */
 			for (int j = 0; j < 10; j++)
 			{
-				str = buildString(i + ":" + j);
+                String str = buildString(i + ":" + j);
 				pSt.setInt(1, i % 10);
 				pSt.setString(2, str);
 				pSt.execute();
@@ -138,10 +134,10 @@ public class st_derby1939 {
 		pSt2.setNull(1, Types.INTEGER);
 		pSt2.setDouble(2, 48.0d);
 		pSt.close();
-		conn.commit();
+        commit();
 	}
 
-	private void doQuery(Connection conn) throws Exception
+    private void doQuery() throws SQLException
 	{
 		/* Set Derby properties to allow the optimizer to find the
 		 * best plan (Hash Join with Index) and also to set a max
@@ -149,9 +145,7 @@ public class st_derby1939 {
 		 * to "spill" to disk.
 		 */
 
-
-		conn.setAutoCommit(false);
-		PreparedStatement pSt = conn.prepareStatement(
+        PreparedStatement pSt = prepareStatement(
 			"select * from d1939_t2 " +
 			"  left outer join " +
 			"    (select distinct d1939_t1.i, d1939_t2.j, d1939_t1.vc from d1939_t2 " + 
@@ -161,7 +155,7 @@ public class st_derby1939 {
 			"    ) x1 " + 
 			"  on d1939_t2.j = x1.i");
 
-		System.out.println("Done preparing, about to execute...");
+        println("Done preparing, about to execute...");
 		pSt.setShort(1, (short)8);
 		int count = 0;
 		try {
@@ -173,15 +167,13 @@ public class st_derby1939 {
 			// so just get the first 10 rows as a sanity check.
 			for (count = 0; rs.next() && count < 10; count++);
 			rs.close();
-			System.out.println("-=-> Ran without error, retrieved first "
-				 + count + " rows.");
+            println("Ran without error, retrieved first " + count + " rows.");
 
 		} catch (SQLException se) {
 
 			if (se.getSQLState().equals("XSDA7"))
 			{
-				System.out.println("-=-> Reproduced DERBY-1939:\n" +
-					" -- " + se.getMessage());
+                fail("Reproduced DERBY-1939", se);
 			}
 			else
 				throw se;
@@ -189,15 +181,14 @@ public class st_derby1939 {
 		}
 
 		pSt.close();
-		conn.rollback();
+        rollback();
 	}
 
 	private String buildString(String s) {
-
-		char [] sArr = new char [] { s.charAt(0), s.charAt(1), s.charAt(2) };
-		for (int i = 0; i < cArr.length; i++)
-			cArr[i] = sArr[i % 3];
-
-		return new String(cArr);
+        StringBuilder sb = new StringBuilder(VC_SIZE);
+        for (int i = 0; i < VC_SIZE; i++) {
+            sb.append(s.charAt(i % s.length()));
+        }
+        return sb.toString();
 	}
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby715.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby715.java?rev=1619376&r1=1619375&r2=1619376&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby715.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_derby715.java Thu Aug 21 12:26:41 2014
@@ -1,6 +1,6 @@
 /*
 
-   Derby - Class org.apache.derbyTesting.functionTests.harness.procedure
+   Derby - Class org.apache.derbyTesting.functionTests.tests.storetests.st_derby715
 
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -21,17 +21,19 @@
 
 package org.apache.derbyTesting.functionTests.tests.storetests;
 
-
-import org.apache.derbyTesting.functionTests.tests.store.BaseTest;
-import org.apache.derbyTesting.functionTests.util.Barrier;
-
 import java.sql.Connection;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-
-import org.apache.derby.tools.ij;
-
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Test;
+import org.apache.derbyTesting.functionTests.util.Barrier;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
 
@@ -44,242 +46,126 @@ incorrect timeout vs. a deadlock).
 
 **/
 
-public class st_derby715 extends BaseTest
-{
-    static boolean verbose = false;
+public class st_derby715 extends BaseJDBCTestCase {
+    private Barrier barrier;
+    private List<Throwable> errors;
 
-    public st_derby715()
-    {
+    public st_derby715(String name) {
+        super(name);
     }
 
+    public static Test suite() {
+        Test test = TestConfiguration.embeddedSuite(st_derby715.class);
+        test = DatabasePropertyTestSetup.setLockTimeouts(test, 1, 60);
+        test = new CleanDatabaseTestSetup(test);
+        return test;
+    }
 
-    /**
-     * Create the base table that the 2 threads will use.
-     **/
-    private static void setup()
-        throws Exception
-    {
-        Connection conn = ij.startJBMS();
-        Statement  stmt = conn.createStatement();
-
-        // drop table, ignore table does not exist error.
-
-        try
-        {
-            stmt.executeUpdate("drop table a");
-        }
-        catch (Exception e)
-        {
-            // ignore drop table errors.
-        }
-
-        try
-        {
-            stmt.executeUpdate("drop table b");
-        }
-        catch (Exception e)
-        {
-            // ignore drop table errors.
-        }
+    @Override
+    protected void initializeConnection(Connection conn) throws SQLException {
+        conn.setAutoCommit(false);
+        conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+    }
 
+    /**
+     * Run two threads, where thread 1 first reads from table A and then
+     * inserts a row into table B, and thread 2 first reads from table B
+     * and then inserts a row into table A. This should cause a deadlock
+     * in one of the threads. Before DERBY-715, sometimes a timeout would
+     * be raised instead of a deadlock.
+     */
+    public void test_st_derby715() throws Exception {
+        Statement stmt = createStatement();
         stmt.executeUpdate("create table a (a integer)");
         stmt.executeUpdate("create table b (b integer)");
         stmt.close();
-        conn.commit();
-        conn.close();
-    }
-
-    public static class t1 implements Runnable
-    {
-        String[] argv;
-        private final Barrier barrier;
-
-        public t1(Barrier barrier, String[] argv)
-        {
-            argv = argv;
-            this.barrier = barrier;
-        }
-        public void run()
-        {
-            try
-            {
-                ij.getPropertyArg(argv); 
-                Connection conn = ij.startJBMS();
-                conn.setAutoCommit(false);
-                conn.setTransactionIsolation(
-                        Connection.TRANSACTION_SERIALIZABLE);
-
-                Statement stmt = conn.createStatement();
-                if (verbose)
-                    System.out.println("Thread 1 before selecting from b");
-
-                // get row locks on all rows in b
-                ResultSet rs = stmt.executeQuery("select * from b");
-
-                if (verbose)
-                    System.out.println("Thread 1 before selecting next from b");
-
-                while (rs.next())
-                {
-                    if (verbose)
-                        System.out.println("Thread t1 got " + rs.getString(1));
-                }
-                if (verbose)
-                    System.out.println("Thread 1 after all next.");
+        commit();
 
-                // give thread 2 a chance to catch up.
-                barrier.await();
+        Connection c1 = openDefaultConnection();
+        Connection c2 = openDefaultConnection();
+        Statement stmt1 = c1.createStatement();
+        Statement stmt2 = c2.createStatement();
 
-                if (verbose)
-                    System.out.println("Thread 1 before inserting into a...");
+        // Run the test five times.
+        for (int i = 0; i < 5; i++) {
+            barrier = new Barrier(2);
+            errors = Collections.synchronizedList(new ArrayList<Throwable>());
+            Thread test1 = new WorkerThread(stmt1, "Thread 1", "a", "b");
+            Thread test2 = new WorkerThread(stmt2, "Thread 2", "b", "a");
+            test1.start();
+            test2.start();
+            test1.join();
+            test2.join();
 
-                // now wait on lock inserting row into table a - either 
-                // thread 1 or thread 2 should get a deadlock, NOT a timeout.
-                stmt.executeUpdate("insert into a values(1)");
+            // We expect exactly one of the threads to fail, and that it
+            // failed with a deadlock.
 
-                if (verbose)
-                    System.out.println("Thread 1 after inserting into a...");
+            assertFalse("Both threads succeeded", errors.isEmpty());
 
-                conn.rollback();
-            }
-            catch (SQLException sqle)
-            {
-                if (sqle.getSQLState().equals("40001"))
-                {
-                    // only expected exception is a deadlock, we should
-                    // get at least one deadlock, so print it to output.
-                    // Don't know which thread will get the deadlock, so
-                    // don't label it.
-                    System.out.println("Got a Deadlock.");
-                }
-                else
-                {
-                    org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(
-                        System.out, sqle);
-                    sqle.printStackTrace(System.out);
+            if (errors.size() > 1) {
+                for (Throwable t: errors) {
+                    printStackTrace(t);
                 }
-                if (verbose)
-                    System.out.println("Thread 1 got exception:\n");
+                fail("Both threads failed");
             }
-            catch (Exception ex)
-            {
-                System.out.println("got unexpected exception: " + ex);
+
+            Throwable t = errors.get(0);
+            if (t instanceof SQLException) {
+                assertSQLState("40001", (SQLException) t);
+                println("Got expected deadlock: " + t);
+            } else {
+                fail("Unexpected exception", t);
             }
         }
+
+        stmt1.close();
+        stmt2.close();
     }
 
-    public static class t2 implements Runnable
-    {
-        String[] argv;
-        private final Barrier barrier;
-        public t2 (Barrier barrier, String[] argv)
-        {
-            argv = argv;
-            this.barrier = barrier;
-        }
-        public void run()
-        {
-            try
-            {
-                ij.getPropertyArg(argv); 
-                Connection conn = ij.startJBMS();
-                conn.setAutoCommit(false);
-                conn.setTransactionIsolation(
-                        Connection.TRANSACTION_SERIALIZABLE);
-
-                Statement stmt = conn.createStatement();
-
-                if (verbose)
-                    System.out.println("Thread 2 before selecting from a");
-
-                ResultSet rs = stmt.executeQuery("select * from a");
-
-                if (verbose)
-                    System.out.println("Thread 2 before selecting next from a");
-
-                while (rs.next())
-                {
-                    if (verbose)
-                        System.out.println("Thread t2 got " + rs.getString(1));
-                }
+    @Override
+    protected void tearDown() throws Exception {
+        barrier = null;
+        errors = null;
+        super.tearDown();
+    }
 
-                if (verbose)
-                    System.out.println("Thread 2 after all next.");
+    private class WorkerThread extends Thread {
+        private final Statement stmt;
+        private final String id;
+        private final String readTable;
+        private final String writeTable;
 
-                // Wait till thread 1 has executed the query and obtained
-                // locks on the rows in table B.
-                barrier.await();
+        WorkerThread(Statement stmt, String id,
+                     String readTable, String writeTable) {
+            this.stmt = stmt;
+            this.id = id;
+            this.readTable = readTable;
+            this.writeTable = writeTable;
+        }
 
-                if (verbose)
-                    System.out.println("Thread 2 before inserting into b");
+        @Override
+        public void run() {
+            try {
+                _run();
+            } catch (Throwable t) {
+                errors.add(t);
+            }
+        }
 
-                stmt.executeUpdate("insert into b values(2)");
+        private void _run() throws SQLException, InterruptedException {
+            println(id + " before selecting from " + readTable);
+            JDBC.assertEmpty(stmt.executeQuery("select * from " + readTable));
+            println(id + " after reading all rows");
 
-                if (verbose)
-                    System.out.println("Thread 2 after inserting into b");
+            // Wait till the other thread has completed reading and is ready
+            // to insert a row.
+            barrier.await();
 
-                conn.rollback();
-            }
-            catch (SQLException sqle)
-            {
-                if (verbose)
-                    System.out.println("Thread 1 got exception:\n");
-
-                if (sqle.getSQLState().equals("40001"))
-                {
-                    // only expected exception is a deadlock, we should
-                    // get at least one deadlock, so print it to output.
-                    // Don't know which thread will get the deadlock, so
-                    // don't label it.
-                    System.out.println("Got a Deadlock.");
-                }
-                else
-                {
-                    org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(
-                        System.out, sqle);
-                    sqle.printStackTrace(System.out);
-                }
-            }
-            catch (Exception ex)
-            {
-                System.out.println("got unexpected exception: " + ex);
-            }
-        }
-    }
-    
-    public void testList(Connection conn)
-        throws SQLException
-    {
-    }
+            println(id + " before inserting into " + writeTable);
+            stmt.execute("insert into " + writeTable + " values (1)");
+            println(id + " after inserting");
 
-    public static void main(String[] argv) 
-        throws Throwable
-    {
-        ij.getPropertyArg(argv); 
-
-        st_derby715 setup_ddl = new st_derby715();
-        setup_ddl.setup();
-        setup_ddl = null;
-
-        {
-            for (int i = 0; i < 5; i++)
-            {
-                Barrier barrier = new Barrier(2);
-                Thread test1 = new Thread(new t1(barrier, argv));
-                Thread test2 = new Thread(new t2(barrier, argv));
-                test1.start();
-                test2.start();
-                test1.join();
-                test2.join();
-            }
+            stmt.getConnection().rollback();
         }
-        /*
-        catch (SQLException sqle)
-        {
-			org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(
-                System.out, sqle);
-			sqle.printStackTrace(System.out);
-		}
-        */
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_reclaim_longcol.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_reclaim_longcol.java?rev=1619376&r1=1619375&r2=1619376&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_reclaim_longcol.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/storetests/st_reclaim_longcol.java Thu Aug 21 12:26:41 2014
@@ -1,6 +1,6 @@
 /*
 
-   Derby - Class org.apache.derbyTesting.functionTests.harness.procedure
+   Derby - Class org.apache.derbyTesting.functionTests.tests.storetests.st_reclaim_longcol
 
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -22,20 +22,19 @@
 package org.apache.derbyTesting.functionTests.tests.storetests;
 
 
-import org.apache.derby.shared.common.sanity.SanityManager;
-
-import org.apache.derbyTesting.functionTests.tests.store.BaseTest;
-
-import java.sql.CallableStatement;
-import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
 
 import java.util.Arrays;
 
-import org.apache.derby.tools.ij;
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 
 /**
@@ -49,7 +48,7 @@ the case of long columns, the actual row
 as the long data is streamed onto other pages.  So the table can grow 
 unexpectedly quite large before the default space reclamation kicks in.  The
 change queues space reclamation in the case of long columns (blob/clob),
-imediately post commit of the single delete.
+immediately post commit of the single delete.
 
 The testing strategy is to loop doing insert, delete, commit of a blob for
 a number of iterations and check that the actual size of the table is 
@@ -59,21 +58,17 @@ of background activities.
 
 **/
 
-public class st_reclaim_longcol extends BaseTest
+public class st_reclaim_longcol extends BaseJDBCTestCase
 {
     static boolean verbose = false;
 
-    public st_reclaim_longcol()
-    {
+    public st_reclaim_longcol(String name) {
+        super(name);
     }
 
-
-    /**
-     * Create the base table.
-     **/
-    private static void setup()
-        throws Exception
-    {
+    public static Test suite() {
+        return new CleanDatabaseTestSetup(
+                TestConfiguration.embeddedSuite(st_reclaim_longcol.class));
     }
 
     /**
@@ -84,33 +79,30 @@ public class st_reclaim_longcol extends 
      * tests that space from the long column row is reclaimed even though
      * there are non-deleted rows on the page.
      **/
-    private static final int SHORT_BLOB_SIZE = 10;
-    public void test1(Connection conn, int blob_size, int num_rows)
-        throws SQLException
+    private void test1(int blob_size, int num_rows) throws SQLException
     {
         byte[]  long_byteVal    = new byte[blob_size];
         byte[]  short_byteVal   = new byte[10];
 
-        beginTest(
-            conn, 
+        println(
             "test1:insert/delete of " + num_rows + 
                 " rows with blob(" + blob_size + ")"); 
 
         Arrays.fill(long_byteVal,  (byte)'L');
         Arrays.fill(short_byteVal, (byte)'S');
 
-        createTable(
-            conn, 
-            "longcol", 
+        Statement s = createStatement();
+        dropTable("LONGCOL");
+        s.execute(
             "create table longcol (id int primary key not null, val blob(" + 
             blob_size + "))");
 
-        conn.commit();
+        commit();
 
         PreparedStatement ins_stmt = 
-            conn.prepareStatement("insert into longcol values (?, ?)");
+            prepareStatement("insert into longcol values (?, ?)");
         PreparedStatement del_stmt = 
-            conn.prepareStatement("delete from longcol where id = ?");
+            prepareStatement("delete from longcol where id = ?");
 
         // worst case is a mixture of rows with long columns and those without.
         // Insert of row with a long column always first goes onto a new 
@@ -155,22 +147,31 @@ public class st_reclaim_longcol extends 
 
             // commit the xact, post commit should kick in to reclaim the
             // blob space sometime after the commit.
-            conn.commit();
+            commit();
 
             // after each commit give the background thread a chance to 
             // reclaim the deleted rows.
-            wait_for_max_allocated(conn, "test1", worst_case_max_allocated);
+            wait_for_max_allocated("test1", worst_case_max_allocated);
         }
 
         // get total pages = allocated pages + free pages
-        int[] sp_info = getSpaceInfo(conn, "APP", "LONGCOL", true);
+        ResultSet rs = getSpaceTable("LONGCOL");
+        assertTrue("Space table was empty", rs.next());
 
-        int total_pages = 
-            sp_info[SPACE_INFO_NUM_ALLOC] + sp_info[SPACE_INFO_NUM_FREE];
+        int allocated = rs.getInt("NUMALLOCATEDPAGES");
+        int free = rs.getInt("NUMFREEPAGES");
+        int total_pages = allocated + free;
+
+        println("Space information after " + num_rows +
+                "insert/delete pairs of rows in longcol table containing " +
+                blob_size + "blobs:");
+        printCurrentRow(rs);
+
+        JDBC.assertEmpty(rs);  // There should only be one row.
 
         int total_expected_page_max = 12 + num_rows;
 
-        while (total_pages > total_expected_page_max)
+        if (total_pages > total_expected_page_max)
         {
             // for the above test case we expect the following space:
             //     page 0
@@ -183,34 +184,14 @@ public class st_reclaim_longcol extends 
             //         marked "half-filled" and can be used in future for
             //         short rows that don't fit on the last page inserted.
 
-            System.out.println(
+            fail(
                 "Test 1 failed, expected less than " + 
                 total_expected_page_max + " pages - count is:\n" +
-                "free pages     : "   + sp_info[SPACE_INFO_NUM_FREE] +
-                "\nallocated pages: " + sp_info[SPACE_INFO_NUM_ALLOC]);
-
-            break;
+                "free pages     : " + free +
+                "\nallocated pages: " + allocated);
         }
 
-        if (verbose)
-        {
-            System.out.println(
-                "Space information after " + num_rows + 
-                "insert/delete pairs of rows in longcol table containing " + 
-                blob_size + "blobs:");
-
-            System.out.println("isindex = "   + sp_info[SPACE_INFO_IS_INDEX]);
-            System.out.println("num_alloc = " + sp_info[SPACE_INFO_NUM_ALLOC]);
-            System.out.println("num_free = "  + sp_info[SPACE_INFO_NUM_FREE]);
-            System.out.println("page_size = " + sp_info[SPACE_INFO_PAGE_SIZE]);
-            System.out.println(
-                "estimspacesaving = " + sp_info[SPACE_INFO_ESTIMSPACESAVING]);
-        }
-
-        endTest(
-            conn, 
-            "test1:insert/delete of " + num_rows + 
-                " rows with blob(" + blob_size + ")"); 
+        commit();
     }
 
     /**
@@ -223,8 +204,7 @@ public class st_reclaim_longcol extends 
      * immediately marked for post commit on individual delete, rather
      * than waiting for all rows on a page to be deleted.
      **/
-    public void test2(
-    Connection  conn, 
+    private void test2(
     int         blob_size, 
     int         work_size, 
     int         total_work)
@@ -233,8 +213,7 @@ public class st_reclaim_longcol extends 
         byte[]  long_byteVal    = new byte[blob_size];
         byte[]  short_byteVal   = new byte[10];
 
-        beginTest(
-            conn, 
+        println(
             "test2:queue of " + work_size + 
                 " rows with blob(" + blob_size + "), total_work = " + 
                 total_work); 
@@ -242,18 +221,16 @@ public class st_reclaim_longcol extends 
         Arrays.fill(long_byteVal,  (byte)'L');
         Arrays.fill(short_byteVal, (byte)'S');
 
-        createTable(
-            conn, 
-            "longcol", 
+        Statement s = createStatement();
+        dropTable("LONGCOL");
+        s.execute(
             "create table longcol (id int primary key not null, val blob(" + 
             blob_size + "))");
 
-        conn.commit();
-
         PreparedStatement ins_stmt = 
-            conn.prepareStatement("insert into longcol values (?, ?)");
+            prepareStatement("insert into longcol values (?, ?)");
         PreparedStatement del_stmt = 
-            conn.prepareStatement("delete from longcol where id = ?");
+            prepareStatement("delete from longcol where id = ?");
 
         // insert the "work_size" number of elements into the table
         for (int iter = 0; iter < work_size; iter++)
@@ -264,7 +241,7 @@ public class st_reclaim_longcol extends 
             ins_stmt.executeUpdate();
 
         }
-        conn.commit();
+        commit();
 
 
         // for each subsequent work item, queue it to the end and delete
@@ -282,7 +259,7 @@ public class st_reclaim_longcol extends 
 
             // commit the xact, post commit should kick in to reclaim the
             // blob space sometime after the commit.
-            conn.commit();
+            commit();
         }
 
 
@@ -304,24 +281,19 @@ public class st_reclaim_longcol extends 
         // on availability of background cpu, so just wait to get under
         // an expected max of allocated pages.  Expect 10 allocated pages per
         // item in work size and add 5 pages for misc overhead.
-        wait_for_max_allocated(conn, "test2", (10 * work_size) + 5);
+        wait_for_max_allocated("test2", (10 * work_size) + 5);
 
-        int[] sp_info = getSpaceInfo(conn, "APP", "LONGCOL", true);
+        ResultSet rs = getSpaceTable("LONGCOL");
+        assertTrue("Space table was empty", rs.next());
 
-        int total_pages = 
-            sp_info[SPACE_INFO_NUM_ALLOC] + sp_info[SPACE_INFO_NUM_FREE];
+        int total_pages =
+                rs.getInt("NUMALLOCATEDPAGES") + rs.getInt("NUMFREEPAGES");
 
-        if (verbose)
-        {
-            System.out.println("Space information:");
+        println("Space information:");
+        printCurrentRow(rs);
+        JDBC.assertEmpty(rs);
 
-            System.out.println("isindex = "   + sp_info[SPACE_INFO_IS_INDEX]);
-            System.out.println("num_alloc = " + sp_info[SPACE_INFO_NUM_ALLOC]);
-            System.out.println("num_free = "  + sp_info[SPACE_INFO_NUM_FREE]);
-            System.out.println("page_size = " + sp_info[SPACE_INFO_PAGE_SIZE]);
-            System.out.println(
-                "estimspacesaving = " + sp_info[SPACE_INFO_ESTIMSPACESAVING]);
-        }
+        commit();
 
         // Run another iteration of the work loop, by now memory should 
         // have gotten to constant.
@@ -338,7 +310,7 @@ public class st_reclaim_longcol extends 
 
             // commit the xact, post commit should kick in to reclaim the
             // blob space sometime after the commit.
-            conn.commit();
+            commit();
         }
 
         // Wait for background thread to convert all deleted rows to 
@@ -346,44 +318,56 @@ public class st_reclaim_longcol extends 
         // on availability of background cpu, so just wait to get under
         // an expected max of allocated pages.  Expect 10 allocated pages per
         // item in work size and add 5 pages for misc overhead.
-        wait_for_max_allocated(conn, "test2_2", (10 * work_size) + 5);
+        wait_for_max_allocated("test2_2", (10 * work_size) + 5);
 
+        rs = getSpaceTable("LONGCOL");
+        assertTrue("Space table was empty", rs.next());
 
-        int[] second_sp_info = getSpaceInfo(conn, "APP", "LONGCOL", true);
+        int second_total_pages =
+                rs.getInt("NUMALLOCATEDPAGES") + rs.getInt("NUMFREEPAGES");
 
-        int second_total_pages = 
-            sp_info[SPACE_INFO_NUM_ALLOC] + sp_info[SPACE_INFO_NUM_FREE];
+        println("Space information:");
+        printCurrentRow(rs);
+        JDBC.assertEmpty(rs);
+
+        commit();
 
         // This could fail due to machine variability, leaving it for now
         // as I have not seen this failure reported.
         if (total_pages != second_total_pages)
         {
-            System.out.println(
+            fail(
                 "Test 2 failed, expected constant memory after second run." +
                 "initial total = " + total_pages +
                 "second total = " + second_total_pages);
         }
+    }
 
-        if (verbose)
-        {
-            System.out.println("Space information:");
+    /**
+     * Invoke SYSCS_DIAG.SPACE_TABLE on the specified table in the current
+     * schema.
+     */
+    private ResultSet getSpaceTable(String table) throws SQLException {
+        PreparedStatement ps = prepareStatement(
+                "select * from table(syscs_diag.space_table(?)) t "
+                        + "where isindex = 0");
+        ps.setString(1, table);
+        return ps.executeQuery();
+    }
 
-            System.out.println("isindex = "   + sp_info[SPACE_INFO_IS_INDEX]);
-            System.out.println("num_alloc = " + sp_info[SPACE_INFO_NUM_ALLOC]);
-            System.out.println("num_free = "  + sp_info[SPACE_INFO_NUM_FREE]);
-            System.out.println("page_size = " + sp_info[SPACE_INFO_PAGE_SIZE]);
-            System.out.println(
-                "estimspacesaving = " + sp_info[SPACE_INFO_ESTIMSPACESAVING]);
+    /**
+     * Print the value of all columns in the current row of the specified
+     * result set, if debugging is enabled.
+     */
+    private void printCurrentRow(ResultSet rs) throws SQLException {
+        if (TestConfiguration.getCurrent().isVerbose()) {
+            ResultSetMetaData rsmd = rs.getMetaData();
+            for (int col = 1; col <= rsmd.getColumnCount(); col++) {
+                println(rsmd.getColumnName(col) + ": " + rs.getObject(col));
+            }
         }
-
-        endTest(
-            conn, 
-            "test2:queue of " + work_size + 
-                " rows with blob(" + blob_size + "), total_work = " + 
-                total_work); 
     }
 
-
     /**
      * wait for background thread to convert allocated pages to free pages
      * <p>
@@ -399,25 +383,14 @@ public class st_reclaim_longcol extends 
      * were seeing failures, see DERBY-1913.
      **/
     private void wait_for_max_allocated(
-    Connection  conn,
     String      test_name,
     int         alloc_wait_count)
         throws SQLException 
     {
         // an initial 1/10 of second which should work for most environments.
-        try
-        {
-            Thread.sleep(100);
-        }
-        catch (Exception ex)
-        {
-            // just ignore interupts of sleep.
-        }
+        sleep(100);
 
-        // get number of allocated pages
-        int[] sp_info     = getSpaceInfo(conn, "APP", "LONGCOL", true);
-        int   total_alloc = sp_info[SPACE_INFO_NUM_ALLOC];
-        int   save_total_alloc = total_alloc;
+        Integer save_total_alloc = null;
 
         // wait for maximum 100 seconds.
 
@@ -425,27 +398,34 @@ public class st_reclaim_longcol extends 
         int max_wait_for_bg_thread = 10000;
         int ms_waited              = 100;
 
-        while (total_alloc > alloc_wait_count)
+        while (true)
         {
+            ResultSet rs = getSpaceTable("LONGCOL");
+            assertTrue("Space table was empty", rs.next());
+            int total_alloc = rs.getInt("NUMALLOCATEDPAGES");
+            int free = rs.getInt("NUMFREEPAGES");
+            JDBC.assertEmpty(rs);
+
+            if (total_alloc <= alloc_wait_count) {
+                // The number of allocated pages has shrunk enough. Break
+                // out of the loop.
+                break;
+            }
+
+            // Save the first count so that we can see if we've made
+            // progress later.
+            if (save_total_alloc == null) {
+                save_total_alloc = total_alloc;
+            }
+
             if (ms_waited < max_wait_for_bg_thread)
             {
                 // The result is dependent on background activity which may
                 // differ from machine to machine.  Loop, sleeping in this
                 // thread to allow background thread to run.
 
-                try
-                {
-                    ms_waited += 1000;
-                    Thread.sleep(1000);
-                }
-                catch (Exception ex)
-                {
-                    // just ignore interupts of sleep.
-                }
-
-                // get number of allocated pages
-                sp_info     = getSpaceInfo(conn, "APP", "LONGCOL", true);
-                total_alloc = sp_info[SPACE_INFO_NUM_ALLOC];
+                ms_waited += 1000;
+                sleep(1000);
 
             }
             else if (total_alloc < save_total_alloc)
@@ -468,47 +448,25 @@ public class st_reclaim_longcol extends 
                 //         marked "half-filled" and can be used in future for
                 //         short rows that don't fit on the last page inserted.
 
-                System.out.println(
+                fail(
                     "Test " + test_name + 
                     " failed in wait_for_max_allocated(), expected less than " + 
                     alloc_wait_count + " allocated pages:\n" +
-                    "free pages     : "   + sp_info[SPACE_INFO_NUM_FREE] +
-                    "\nallocated pages: " + sp_info[SPACE_INFO_NUM_ALLOC] +
+                    "free pages     : "   + free +
+                    "\nallocated pages: " + total_alloc +
                     "\nWaited " + ms_waited + "ms. for background work.");
-
-                break;
             }
         }
     }
 
-
-    public void testList(Connection conn)
-        throws SQLException
+    public void testList() throws SQLException
     {
-        test1(conn, 250000, 20);
+        setAutoCommit(false);
+
+        test1(250000, 20);
 
         // DERBY-1913 - disabling test2 as it is too sensitive to background
         // processing.
-        // test2(conn, 250000, 5, 500);
-    }
-
-    public static void main(String[] argv) 
-        throws Throwable
-    {
-        st_reclaim_longcol test = new st_reclaim_longcol();
-
-        ij.getPropertyArg(argv); 
-        Connection conn = ij.startJBMS();
-
-        try
-        {
-            test.testList(conn);
-        }
-        catch (SQLException sqle)
-        {
-			org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(
-                System.out, sqle);
-			sqle.printStackTrace(System.out);
-		}
+        // test2(250000, 5, 500);
     }
 }



Mime
View raw message