You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2007/07/03 20:00:44 UTC
svn commit: r552932 - in
/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests:
suites/ tests/lang/
Author: djd
Date: Tue Jul 3 11:00:43 2007
New Revision: 552932
URL: http://svn.apache.org/viewvc?view=rev&rev=552932
Log:
Some JUnit test cleanup and conversion from trunk:
DERBY-2727 551732 Conversion of AggregateClassLoadingTest
551940 Cleanup of language tests to use utility methods and close statement objects.
Added:
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java (with props)
Removed:
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoading.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoading_app.properties
Modified:
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall?view=diff&rev=552932&r1=552931&r2=552932
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall Tue Jul 3 11:00:43 2007
@@ -1,7 +1,6 @@
jdbcapi/metadata.java
jdbcapi/metadataMultiConn.java
jdbcapi/odbc_metadata.java
-lang/AggregateClassLoading.java
lang/DB2IsolationLevels.sql
lang/LOBDB2compatibility.sql
lang/aggregateOptimization.sql
Added: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java?view=auto&rev=552932
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java (added)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java Tue Jul 3 11:00:43 2007
@@ -0,0 +1,170 @@
+/**
+ * Derby - Class org.apache.derbyTesting.functionTests.tests.lang.AggregateClassLoadingTest
+ *
+ * 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.lang;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+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.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
+
+/**
+ * Test for ensuring the aggregate implementation classes are loaded correctly,
+ * even when the context class loader loads Derby engine classes as well. This
+ * is a typical situation we have seen with J2EE servers where Derby may be in
+ * the application WAR and provided as a system service by the container. <BR>
+ * Jira issue DERBY-997 <BR>
+ * Assumes embedded and only needs to be run in embedded, since all class
+ * loading happens on the engine side.
+ */
+public class AggregateClassLoadingTest extends BaseJDBCTestCase {
+
+ /**
+ * Basic constructor.
+ */
+ public AggregateClassLoadingTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Sets the auto commit to false.
+ */
+ protected void initializeConnection(Connection conn) throws SQLException {
+ conn.setAutoCommit(false);
+ }
+
+ /**
+ * Returns the implemented tests.
+ *
+ * @return An instance of <code>Test</code> with the implemented tests to
+ * run.
+ */
+ public static Test suite() {
+
+
+ /* this test creates a class loader, adding that permission to
+ * derbyTesting.jar would mean that permission was granted all
+ * the way up the stack to the derby engine. Thus increasing
+ * the chance that incorrectly a privileged block could be dropped
+ * but the tests continue to pass.
+ */
+ return SecurityManagerSetup.noSecurityManager(
+ new CleanDatabaseTestSetup(
+ new TestSuite(AggregateClassLoadingTest.class,
+ "AggregateClassLoadingTest")) {
+
+ /**
+ * Save the class loader upon entry to the
+ * suite, some JVM's install the main loader
+ * as the context loader.
+ */
+ private ClassLoader originalLoader;
+ protected void setUp() throws Exception {
+ originalLoader = Thread.currentThread().getContextClassLoader();
+ super.setUp();
+ }
+ protected void tearDown() throws Exception {
+ Thread.currentThread().setContextClassLoader(originalLoader);
+ super.tearDown();
+ }
+
+ /**
+ * @see org.apache.derbyTesting.junit.CleanDatabaseTestSetup#decorateSQL(java.sql.Statement)
+ */
+ protected void decorateSQL(Statement s)
+ throws SQLException {
+ s.execute("create table t (i int)");
+ s.execute("insert into t values 1,2,3,4,5,6,null,4,5,456,2,4,6,7,2144,44,2,-2,4");
+
+ /*
+ * Find the location of the code for the Derby
+ * connection. The rest of the engine will be at
+ * the same location!
+ */
+ URL derbyURL = s.getConnection().getClass().getProtectionDomain().getCodeSource()
+ .getLocation();
+
+ /*
+ * Create a new loader that loads from the same
+ * location as the engine. Create it without a
+ * parent, otherwise the parent will be the
+ * class loader of this class which is most
+ * likely the same as the engine. Since the
+ * class loader delegates to its parent first
+ * the bug would not show, as all the derby
+ * engine classes would be from a single loader.
+ */
+ URLClassLoader cl = new URLClassLoader(new URL[] { derbyURL }, null);
+ Thread.currentThread().setContextClassLoader(cl);
+
+ super.decorateSQL(s);
+ }
+ });
+
+ }
+
+ public void testAggregateMAX() throws SQLException {
+ testAggregate("select MAX(i) from t");
+ }
+
+ public void testAggregateMIN() throws SQLException {
+ testAggregate("select MIN(i) from t");
+ }
+
+ public void testAggregateAVG() throws SQLException {
+ testAggregate("select AVG(i) from t");
+ }
+
+ public void testAggregateCOUNT() throws SQLException {
+ testAggregate("select COUNT(i) from t");
+ }
+
+ public void testAggregateCOUNT2() throws SQLException {
+ testAggregate("select COUNT(*) from t");
+ }
+
+ /**
+ * Just run and display the aggregates result.
+ *
+ * Test some aggregates, their generated class will attempt
+ * to load the internal aggregate through the context loader
+ * first, and then any remaining loader.
+ */
+ private void testAggregate(String query) throws SQLException {
+ Statement s = createStatement();
+
+ JDBC.assertDrainResults(s.executeQuery(query), 1);
+
+ s.close();
+ }
+}
Propchange: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java
------------------------------------------------------------------------------
eol:style = native
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java?view=diff&rev=552932&r1=552931&r2=552932
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java Tue Jul 3 11:00:43 2007
@@ -130,6 +130,7 @@
0, 0, 0, 0, 0, 0, 0 };
checkDistinctRows(expectedRows);
+ s.close();
}
public void testOneRow() throws SQLException {
@@ -142,6 +143,7 @@
1, 1, 1, 2, 1, 1, 1, 1 };
checkDistinctRows(expectedRows);
+ s.close();
}
public void testIdenticalRows() throws SQLException {
@@ -155,6 +157,7 @@
2, 2, 1, 2, 1, 1, 1, 1 };
checkDistinctRows(expectedRows);
+ s.close();
}
public void testDistinctIdenticalAndDifferingRows() throws SQLException {
@@ -169,6 +172,7 @@
3, 3, 2, 4, 2, 2, 2, 2 };
checkDistinctRows(expectedRows);
+ s.close();
}
public void testDistinctTwoVaryingRows() throws SQLException {
@@ -182,6 +186,7 @@
2, 2, 2, 2, 1, 2, 2, 4 };
checkDistinctRows(expectedRows);
+ s.close();
}
public void testDistinctIdenticalNullRows() throws SQLException {
@@ -962,11 +967,6 @@
* @throws SQLException
*/
public void assertRowCount(int count, ResultSet rs) throws SQLException {
- int rowcount = 0;
- while (rs.next()) {
- rowcount++;
- }
- rs.close();
- assertEquals(count, rowcount);
+ JDBC.assertDrainResults(rs, count);
}
}
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java?view=diff&rev=552932&r1=552931&r2=552932
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java Tue Jul 3 11:00:43 2007
@@ -43,8 +43,6 @@
public class ForBitDataTest extends BaseJDBCTestCase {
- public Statement stmt = null;
-
private static String[] TABLES = {
"CREATE TABLE FBDOK.T001 (C001 CHAR FOR BIT DATA)",
"CREATE TABLE FBDOK.T002 (C002 CHAR(1) FOR BIT DATA)",
@@ -529,19 +527,6 @@
public ForBitDataTest(String name) {
super(name);
}
-
-
- /* Set up fixture */
- protected void setUp() throws SQLException {
- stmt = createStatement();
- }
-
-
- /* Tear down the fixture */
- protected void tearDown() throws Exception {
- stmt.close();
- super.tearDown();
- }
/**
Negative for bit data tests.
@@ -550,11 +535,11 @@
FBD009 maximum varchar length
*/
public void testNegative() throws SQLException {
- assertStatementError("42611", stmt, "CREATE TABLE FBDFAIL.T001 (C001 CHAR(255) FOR BIT DATA)");
- assertStatementError("42611", stmt, "CREATE TABLE FBDFAIL.T001 (C001 CHAR(255) FOR BIT DATA)");
- assertStatementError("42611", stmt, "CREATE TABLE FBDFAIL.T002 (C002 VARCHAR(32673) FOR BIT DATA)");
- assertStatementError("42X01", stmt, "CREATE TABLE FBDFAIL.T003 (C003 VARCHAR FOR BIT DATA)");
- assertStatementError("42X01", stmt, "CREATE TABLE FBDFAIL.T004 (C004 LONG VARCHAR(100) FOR BIT DATA)");
+ assertCompileError("42611", "CREATE TABLE FBDFAIL.T001 (C001 CHAR(255) FOR BIT DATA)");
+ assertCompileError("42611", "CREATE TABLE FBDFAIL.T001 (C001 CHAR(255) FOR BIT DATA)");
+ assertCompileError("42611", "CREATE TABLE FBDFAIL.T002 (C002 VARCHAR(32673) FOR BIT DATA)");
+ assertCompileError("42X01", "CREATE TABLE FBDFAIL.T003 (C003 VARCHAR FOR BIT DATA)");
+ assertCompileError("42X01", "CREATE TABLE FBDFAIL.T004 (C004 LONG VARCHAR(100) FOR BIT DATA)");
}
/**
@@ -735,7 +720,10 @@
space12[11] = (byte) 0x20;
insertData(psI, 210, space12, 10, true);
showData(psS, 210, space12, "ORG cafe20202020cafe20202020 (12) CHR <NULL> VAR <NULL> LVC cafe20202020cafe20202020 (12) BLOB <NULL> ");
+
+ psI.close();
+ Statement stmt = createStatement();
String sql = "INSERT INTO FBDVAL.T001 VALUES(80, X'2020202020', X'2020202020', X'2020202020', null)";
stmt.executeUpdate(sql);
@@ -777,11 +765,16 @@
sql = "INSERT INTO FBDVAL.T001 SELECT * FROM FBDVAL.X001";
stmt.executeUpdate(sql);
showData(psS, 200, space12, "ORG cafe20202020cafe20202020 (12) CHR cafe20202020cafe2020 (10) VAR <NULL> LVC <NULL> BLOB <NULL> ");
+
+ psS.close();
+
+ stmt.close();
}
/* testCompare fixture */
public void testCompare() throws SQLException {
+ Statement stmt = createStatement();
stmt.execute("delete from FBDVAL.T001");
PreparedStatement psI = prepareStatement("INSERT INTO FBDVAL.T001 VALUES(?, ?, ?, ?, ?)");
PreparedStatement psI2 = prepareStatement("INSERT INTO FBDVAL.T002 VALUES(?, ?, ?, ?, ?)");
@@ -848,6 +841,7 @@
}
}
}
+ stmt.close();
}
/**
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java?view=diff&rev=552932&r1=552931&r2=552932
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java Tue Jul 3 11:00:43 2007
@@ -46,28 +46,17 @@
*/
public class ForUpdateTest extends BaseJDBCTestCase {
- public Statement stmt = null;
- public Connection c = null;
-
/* Public constructor required for running test as standalone JUnit. */
public ForUpdateTest(String name) {
super(name);
}
-
-
- /* Set up fixture */
- protected void setUp() throws SQLException {
- stmt = createStatement();
- c = getConnection();
- c.setAutoCommit(false);
- }
-
-
- /* Tear down the fixture */
- protected void tearDown() throws Exception {
- stmt.close();
- super.tearDown();
- }
+
+ /**
+ * Sets the auto commit to false.
+ */
+ protected void initializeConnection(Connection conn) throws SQLException {
+ conn.setAutoCommit(false);
+ }
/**
* Create a suite of tests.
@@ -95,18 +84,22 @@
}
public void testNegative() throws SQLException {
- assertStatementError("42X01", stmt, "select i, v from t1 for");
- assertStatementError("42X01", stmt, "select i, v from t1 for read");
- assertStatementError("42X01", stmt, "select i, v from t1 for only");
- assertStatementError("42X01", stmt, "select i, v from t1 for update of");
- assertStatementError("42X01", stmt, "select i, v from t1 update");
- assertStatementError("42X01", stmt, "select i, v from t1 only");
- assertStatementError("42X01", stmt, "select i, v from t1 read");
+ assertCompileError("42X01", "select i, v from t1 for");
+ assertCompileError("42X01", "select i, v from t1 for read");
+ assertCompileError("42X01", "select i, v from t1 for only");
+ assertCompileError("42X01", "select i, v from t1 for update of");
+ assertCompileError("42X01", "select i, v from t1 update");
+ assertCompileError("42X01", "select i, v from t1 only");
+ assertCompileError("42X01", "select i, v from t1 read");
+
+ Statement stmt = createStatement();
JDBC.assertEmpty(stmt.executeQuery("select i, v from t1 for update"));
+ stmt.close();
}
public void testCursor() throws SQLException {
+ Statement stmt = createStatement();
stmt.setCursorName("C");
stmt.executeQuery("select i, v from t1, t2");
Statement stmt2 = createStatement();
@@ -127,10 +120,12 @@
assertSQLState("X0X60", e);
}
stmt2.close();
+ stmt.close();
}
public void testCursor1() throws SQLException {
+ Statement stmt = createStatement();
stmt.setCursorName("C1");
ResultSet rs = stmt.executeQuery("select i, v from t1 where i is not null");
Statement stmt2 = createStatement();
@@ -149,6 +144,7 @@
public void testCursor2() throws SQLException {
+ Statement stmt = createStatement();
stmt.setCursorName("C2");
ResultSet rs = stmt.executeQuery("select i, v from t1, t2 for read only");
Statement stmt2 = createStatement();
@@ -163,11 +159,13 @@
}
stmt2.close();
rs.close();
+ stmt.close();
}
public void testCursor3() throws SQLException {
+ Statement stmt = createStatement();
stmt.setCursorName("C3");
ResultSet rs = stmt.executeQuery("select i, v from t1 where i is not null for read only");
Statement stmt2 = createStatement();
@@ -182,11 +180,13 @@
}
stmt2.close();
rs.close();
+ stmt.close();
}
public void testUpdates() throws SQLException {
+ Statement stmt = createStatement();
JDBC.assertEmpty(stmt.executeQuery("select i, v from t1 for update of t"));
JDBC.assertEmpty(stmt.executeQuery("select i, v from t1 for update of i"));
@@ -206,10 +206,12 @@
assertStatementError("42Y90", stmt, "select * from (values (1, 2, 3)) a for update");
assertStatementError("42Y90", stmt, "values (1, 2, 3) for update");
assertStatementError("42Y90", stmt, "select * from t1 union all select * from t1 for update");
+ stmt.close();
}
public void testUpdates2() throws SQLException {
+ Statement stmt = createStatement();
stmt.executeUpdate("insert into t1 (i) values (1)");
stmt.setCursorName("C4");
ResultSet rs = stmt.executeQuery("select i from t1 s1 for update");
@@ -234,10 +236,12 @@
JDBC.assertEmpty(stmt.executeQuery("select i from t1 for update of t, v"));
JDBC.assertEmpty(stmt.executeQuery("select i from t1 for update of d"));
assertStatementError("42X04", stmt, "select i as z from t1 for update of z");
+ stmt.close();
}
public void testCursor5() throws SQLException {
+ Statement stmt = createStatement();
stmt.setCursorName("C5");
stmt.executeQuery("select i as v from t1 for update of v");
try {
@@ -250,14 +254,16 @@
JDBC.assertEmpty(stmt.executeQuery("select i from t1 for update of i, v, v, t"));
assertStatementError("42X01", stmt, "select i from t1 for update of t1.v, t1.i, t1.d");
JDBC.assertEmpty(stmt.executeQuery("select a.i+10, d, d from t1 a for update"));
+ stmt.close();
}
- public void testStatistics() throws SQLException {
+ public void testStatistics() throws SQLException {
+ Statement stmt = createStatement();
stmt.execute("create index t3bi on t3(b)");
stmt.execute("insert into t3 values (1, 'hhhh'), (2, 'uuuu'), (3, 'yyyy'), (4, 'aaaa'), (5, 'jjjj'), (6, 'rrrr')");
stmt.execute("insert into t3 values (7, 'iiii'), (8, 'wwww'), (9, 'rrrr'), (10, 'cccc'), (11, 'hhhh'), (12, 'rrrr')");
- c.commit();
+ commit();
String [][] expectedValues = { {"1", "hhhh"},
{"2", "uuuu"},
@@ -276,7 +282,7 @@
RuntimeStatisticsParser rtsp = SQLUtilities.getRuntimeStatisticsParser(stmt);
assertTrue(rtsp.usedTableScan());
assertFalse(rtsp.usedDistinctScan());
- c.commit();
+ commit();
PreparedStatement p = prepareStatement("select i, b from t3 where i = ? FOR UPDATE");
p.setString(1, "7");
@@ -287,7 +293,7 @@
assertFalse(rtsp2.usedTableScan());
assertFalse(rtsp2.usedDistinctScan());
p.close();
- c.commit();
+ commit();
p = prepareStatement("select i, b from t3 where i < ? FOR UPDATE");
@@ -304,7 +310,7 @@
assertFalse(rtsp3.usedTableScan());
assertFalse(rtsp3.usedDistinctScan());
p.close();
- c.commit();
+ commit();
p = prepareStatement("select i, b from t3 where b = ? FOR UPDATE");
@@ -316,9 +322,10 @@
assertFalse(rtsp4.usedTableScan());
assertFalse(rtsp4.usedDistinctScan());
p.close();
- c.commit();
+ commit();
stmt.execute("call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0)");
+ stmt.close();
}
public void testCursors() throws SQLException {
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java?view=diff&rev=552932&r1=552931&r2=552932
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java Tue Jul 3 11:00:43 2007
@@ -21,12 +21,11 @@
package org.apache.derbyTesting.functionTests.tests.lang;
-import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.sql.ResultSet;
import java.sql.Time;
import java.sql.Timestamp;
@@ -35,12 +34,9 @@
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
-import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.SQLUtilities;
import org.apache.derbyTesting.junit.TestConfiguration;
-import org.apache.derbyTesting.functionTests.tests.lang.CastingTest;
-
public class NullIfTest extends BaseJDBCTestCase {
private static String[][][] nullIfResults ={
@@ -138,9 +134,7 @@
* @throws SQLException
*/
public void testAllDatatypesCombinations() throws SQLException {
- Connection conn = getConnection();
-
- Statement s = conn.createStatement();
+ Statement s = createStatement();
for (int firstColumnType = 0; firstColumnType < CastingTest.SQLTypes.length; firstColumnType++) {
StringBuffer nullIfString = new StringBuffer("SELECT NULLIF("
@@ -167,6 +161,7 @@
row++;
}
assertTrue(CastingTest.T_147b[firstColumnType][secondColumnType]);
+ rs.close();
} catch (SQLException e) {
for (int r = row; r < 4; r++) {
@@ -188,6 +183,7 @@
}
}
+ s.close();
}
/**
@@ -196,9 +192,6 @@
* @throws SQLException
*/
public void testParameterForFirstOperandToNullIf() throws SQLException {
- Connection conn = getConnection();
-
- PreparedStatement ps;
for (int secondColumnType = 0; secondColumnType < CastingTest.SQLTypes.length; secondColumnType++) {
String nullIfString = new String("SELECT NULLIF(?,"
@@ -206,7 +199,7 @@
+ ") from AllDataTypesTable");
int row = 0;
try {
- ps = conn.prepareStatement(nullIfString);
+ PreparedStatement ps = prepareStatement(nullIfString);
switch (secondColumnType) {
case 0:
case 1:
@@ -265,6 +258,7 @@
row++;
}
rs.close();
+ ps.close();
} catch (SQLException e) {
for (int r = row; r < 4; r++) {
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java?view=diff&rev=552932&r1=552931&r2=552932
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java Tue Jul 3 11:00:43 2007
@@ -42,21 +42,23 @@
*/
public class ReleaseCompileLocksTest extends BaseJDBCTestCase {
- public Statement stmt = null;
- Connection conn = null;
-
/* Public constructor required for running test as standalone JUnit. */
public ReleaseCompileLocksTest(String name) {
super(name);
}
+
+ /**
+ * Sets the auto commit to false.
+ */
+ protected void initializeConnection(Connection conn) throws SQLException {
+ conn.setAutoCommit(false);
+ }
/* Set up fixture */
protected void setUp() throws SQLException {
- stmt = createStatement();
- conn = getConnection();
- conn.setAutoCommit(false);
+ Statement stmt = createStatement();
stmt.execute("create function dmlstatic() returns INT parameter style java language java external name " + "'org.apache.derbyTesting.functionTests.tests.lang." +
this.getANumber() +
@@ -65,14 +67,12 @@
stmt.execute("create function insertstatic() returns INT parameter style java language java external name " + "'org.apache.derbyTesting.functionTests.tests.lang." +
this.getANumber() +
"' no sql");
+
+ stmt.close();
+ commit();
}
- /* Tear down the fixture */
- protected void tearDown() throws Exception {
- stmt.close();
- super.tearDown();
- }
/**
* Create a suite of tests.
@@ -99,7 +99,8 @@
/*Fixtures*/
public void testReleaseCompileLocks() throws Exception {
- conn.commit();
+
+ Statement stmt = createStatement();
try {
stmt.executeQuery("select (dmlstatic()) from sys.systables where tablename = 'SYSCONGLOMERATES'");
@@ -109,11 +110,11 @@
JDBC.assertEmpty(stmt.executeQuery("select TYPE, MODE, TABLENAME, LOCKNAME, STATE from syscs_diag.lock_table order by 1"));
- conn.commit();
+ commit();
stmt.execute("drop table t1");
stmt.execute("create table t1 (s int)");
- conn.commit();
+ commit();
try {
@@ -127,14 +128,14 @@
JDBC.assertEmpty(stmt.executeQuery("select * from t1"));
stmt.execute("drop table t1");
- conn.commit();
+ commit();
JDBC.assertEmpty(stmt.executeQuery("select TYPE, MODE, TABLENAME, LOCKNAME, STATE from syscs_diag.lock_table order by 1"));
- conn.commit();
+ commit();
stmt.execute("create table test_tab (x int)");
stmt.executeUpdate("insert into test_tab values (1)");
- conn.commit();
+ commit();
JDBC.assertSingleValueResultSet(stmt.executeQuery("select count(*) from syscs_diag.lock_table"), "0");
JDBC.assertSingleValueResultSet(stmt.executeQuery("select count(*) from sys.sysviews"), "0");
@@ -152,7 +153,7 @@
assertSQLState("42Y55", e);
}
stmt.execute("create table t1 (x int)");
- conn.commit();
+ commit();
JDBC.assertEmpty(stmt.executeQuery("select * from t1"));
@@ -161,12 +162,13 @@
stmt2.execute("create table t2 (x int)");
stmt2.execute("drop table t2");
stmt2.close();
+ conn1.commit();
conn1.close();
stmt.execute("drop table test_tab");
stmt.execute("create table test_tab (x int)");
stmt.execute("insert into test_tab values (1)");
- conn.commit();
+ commit();
PreparedStatement ps = prepareStatement("update test_tab set x=2 where x=?");
ps.setCursorName("cursor1");
@@ -178,13 +180,13 @@
rs = stmt.executeQuery("select TYPE, MODE, TABLENAME, LOCKNAME, STATE from syscs_diag.lock_table order by 1");
String expectedValues1[][] = {{"ROW", "X", "TEST_TAB", "(1,7)", "GRANT" }, {"TABLE", "IX", "TEST_TAB", "Tablelock","GRANT"}};
JDBC.assertFullResultSet(rs, expectedValues1);
- conn.commit();
+ commit();
stmt.execute("create table t (c1 int not null primary key, c2 int references t)");
stmt.executeUpdate("insert into t values (1,1)");
stmt.executeUpdate("insert into t values (2,1)");
- conn.commit();
+ commit();
ps = prepareStatement("select * from t where c1 = ? and c2 = ?");
ps.setCursorName("ps");
@@ -193,41 +195,41 @@
stmt.execute("create table x(c1 int)");
stmt.execute("drop table x");
- conn.commit();
+ commit();
ps = prepareStatement("insert into t values (3,2)");
ps.setCursorName("pi");
JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
- conn.commit();
+ commit();
stmt.execute("create table x(c1 int)");
stmt.execute("drop table x");
- conn.commit();
+ commit();
ps = prepareStatement("update t set c2 = c1, c1 = c2");
ps.setCursorName("p1");
JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
- conn.commit();
+ commit();
stmt.execute("create table x(c1 int)");
stmt.execute("drop table x");
- conn.commit();
+ commit();
ps = prepareStatement("delete from t");
ps.setCursorName("p1");
JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
- conn.commit();
+ commit();
stmt.execute("create trigger update_of_t after update on t for each row values 2");
stmt.execute("create trigger insert_of_t after insert on t for each row values 3");
- conn.commit();
+ commit();
ps = prepareStatement("update t set c2=2 where c1=2");
ps.setCursorName("pu");
JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
- conn.commit();
+ commit();
rs.close();
ps.close();
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?view=diff&rev=552932&r1=552931&r2=552932
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Tue Jul 3 11:00:43 2007
@@ -109,6 +109,7 @@
suite.addTest(TimestampArithTest.suite());
suite.addTest(SpillHashTest.suite());
suite.addTest(CaseExpressionTest.suite());
+ suite.addTest(AggregateClassLoadingTest.suite());
// Add the XML tests, which exist as a separate suite
// so that users can "run all XML tests" easily.