1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-30 06:01:21 +03:00

The attached patch is my first run-through of the JDBC test suite. A

summary of changes:

 . removal of the tablename property from build.xml

 . addition of a dropTable method in JDBC2Tests and cleanups of many
methods in the same

 . all tests now use non-deprecated assertXYZ methods instead of the
deprecated assert method

 . failure in TimestampTest (testSetTimestamp) fixed. The failure is
because testSetTimestamp was inserting a timestamp with hour 7 but
checkTimeTest was expecting a timestamp with hour 8. AFAICS, there are
no issues wrt daylight savings time and timestamps being pushed in and
pulled out (but more explicit tests should be added in the future)

 . failure in TimeTest (testGetTime) fixed. Times to be inserted were
interpreted in the localtime zone but checking was done with the
assumption that the insertion was done in GMT.

 . formatting changes in a few of the source files (because I found
it convenient to have consistent formatting while working on them). The
formatting is consistent with the new format for java source files in
PostgreSQL.

Liam Stewart
This commit is contained in:
Bruce Momjian
2001-09-23 04:11:14 +00:00
parent c7bc0ddf76
commit b75814aee3
13 changed files with 669 additions and 717 deletions

View File

@@ -4,13 +4,17 @@ import org.postgresql.test.JDBC2Tests;
import junit.framework.TestCase;
import java.sql.*;
/* TODO tests that can be added to this test case
- SQLExceptions chained to a BatchUpdateException
- test PreparedStatement as thoroughly as Statement
*/
/**
* Test case for Statement.batchExecute()
*/
public class BatchExecuteTest extends TestCase {
private Connection con;
private Statement stmt;
public BatchExecuteTest(String name) {
super(name);
@@ -20,20 +24,13 @@ public class BatchExecuteTest extends TestCase {
// a table for this test.
protected void setUp() throws Exception {
con = JDBC2Tests.openDB();
stmt = con.createStatement();
Statement stmt = con.createStatement();
// Drop the test table if it already exists for some reason. It is
// not an error if it doesn't exist.
try {
stmt.executeUpdate("DROP TABLE testbatch");
} catch (SQLException e) {
// Intentionally ignore. We cannot distinguish "table does not
// exist" from other errors, since PostgreSQL doesn't support
// error codes yet.
}
stmt.executeUpdate("CREATE TABLE testbatch(pk INTEGER, col1 INTEGER)");
stmt.executeUpdate("INSERT INTO testbatch VALUES(1, 0)");
JDBC2Tests.createTable(con, "testbatch", "pk INTEGER, col1 INTEGER");
stmt.executeUpdate("INSERT INTO testbatch VALUES (1, 0)");
// Generally recommended with batch updates. By default we run all
// tests in this test case with autoCommit disabled.
@@ -43,13 +40,9 @@ public class BatchExecuteTest extends TestCase {
// Tear down the fixture for this test case.
protected void tearDown() throws Exception {
con.setAutoCommit(true);
if (stmt != null) {
stmt.executeUpdate("DROP TABLE testbatch");
stmt.close();
}
if (con != null) {
JDBC2Tests.closeDB(con);
}
JDBC2Tests.dropTable(con, "testbatch");
JDBC2Tests.closeDB(con);
}
public void testSupportsBatchUpdates() throws Exception {
@@ -75,6 +68,7 @@ public class BatchExecuteTest extends TestCase {
}
public void testExecuteEmptyBatch() throws Exception {
Statement stmt = con.createStatement();
int[] updateCount = stmt.executeBatch();
assertEquals(0,updateCount.length);
@@ -82,9 +76,12 @@ public class BatchExecuteTest extends TestCase {
stmt.clearBatch();
updateCount = stmt.executeBatch();
assertEquals(0,updateCount.length);
stmt.close();
}
public void testClearBatch() throws Exception {
Statement stmt = con.createStatement();
stmt.addBatch("UPDATE testbatch SET col1 = col1 + 1 WHERE pk = 1");
assertCol1HasValue(0);
stmt.addBatch("UPDATE testbatch SET col1 = col1 + 2 WHERE pk = 1");
@@ -97,9 +94,13 @@ public class BatchExecuteTest extends TestCase {
assertCol1HasValue(4);
con.commit();
assertCol1HasValue(4);
stmt.close();
}
public void testSelectThrowsException() throws Exception {
Statement stmt = con.createStatement();
stmt.addBatch("UPDATE testbatch SET col1 = col1 + 1 WHERE pk = 1");
stmt.addBatch("SELECT col1 FROM testbatch WHERE pk = 1");
stmt.addBatch("UPDATE testbatch SET col1 = col1 + 2 WHERE pk = 1");
@@ -115,6 +116,8 @@ public class BatchExecuteTest extends TestCase {
fail( "Should throw a BatchUpdateException instead of " +
"a generic SQLException: " + e);
}
stmt.close();
}
public void testPreparedStatement() throws Exception {
@@ -151,6 +154,8 @@ public class BatchExecuteTest extends TestCase {
/**
*/
public void testTransactionalBehaviour() throws Exception {
Statement stmt = con.createStatement();
stmt.addBatch("UPDATE testbatch SET col1 = col1 + 1 WHERE pk = 1");
stmt.addBatch("UPDATE testbatch SET col1 = col1 + 2 WHERE pk = 1");
stmt.executeBatch();
@@ -174,10 +179,7 @@ public class BatchExecuteTest extends TestCase {
assertCol1HasValue(12);
con.rollback();
assertCol1HasValue(12);
stmt.close();
}
}
/* TODO tests that can be added to this test case
- SQLExceptions chained to a BatchUpdateException
- test PreparedStatement as thoroughly as Statement
*/