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/06/29 18:23:16 UTC
svn commit: r551940 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang:
DistinctTest.java ForBitDataTest.java ForUpdateTest.java NullIfTest.java
ReleaseCompileLocksTest.java
Author: djd
Date: Fri Jun 29 09:23:15 2007
New Revision: 551940
URL: http://svn.apache.org/viewvc?view=rev&rev=551940
Log:
Cleanup some language junit tests to use utility methods, close statement objects and
not use fields for statements/connection.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java?view=diff&rev=551940&r1=551939&r2=551940
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java Fri Jun 29 09:23:15 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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java?view=diff&rev=551940&r1=551939&r2=551940
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForBitDataTest.java Fri Jun 29 09:23:15 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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java?view=diff&rev=551940&r1=551939&r2=551940
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForUpdateTest.java Fri Jun 29 09:23:15 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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java?view=diff&rev=551940&r1=551939&r2=551940
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java Fri Jun 29 09:23:15 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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java?view=diff&rev=551940&r1=551939&r2=551940
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java Fri Jun 29 09:23:15 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();