Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c69bb04

Browse files
committed
Attached is a patch that fixes
ConnectionTest.testTransactionIsolation() in the JDBC driver's test suite. This reduces the number of failures of the test suite from 7 to 6. The patch fixes the test case itself, rather than the driver. In addition to the change described in my posting below, I fixed the part of the test with autocommit enabled. The author of the test assumed that setting the transaction isolation level would have no effect, but in fact it does. Perhaps the test case worked with pre-7.1 behaviour, when the JDBC driver set the isolation level in every transaction, instead of using "set session characteristics". Anyway, now it works with a backend built from current CVS and the behaviour is JDBC compliant. I also extended the test case by changing the isolation level before beginning a transaction and verifying it inside the transaction. Regards, Ren? Pijlman
1 parent d70a944 commit c69bb04

File tree

1 file changed

+89
-31
lines changed

1 file changed

+89
-31
lines changed

src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java

+89-31
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* PS: Do you know how difficult it is to type on a train? ;-)
1212
*
13-
* $Id: ConnectionTest.java,v 1.3 2001/09/07 22:17:48 momjian Exp $
13+
* $Id: ConnectionTest.java,v 1.4 2001/09/10 14:54:22 momjian Exp $
1414
*/
1515

1616
public class ConnectionTest extends TestCase {
@@ -203,36 +203,94 @@ public void testWarnings() {
203203
}
204204
}
205205

206-
/**
207-
* Transaction Isolation Levels
208-
*/
209-
public void testTransactionIsolation() {
210-
try {
211-
Connection con = JDBC2Tests.openDB();
212-
213-
con.setAutoCommit(false);
214-
215-
// These are the currently available ones
216-
con.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
217-
assert(con.getTransactionIsolation()==Connection.TRANSACTION_SERIALIZABLE);
218-
219-
con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
220-
assert(con.getTransactionIsolation()==Connection.TRANSACTION_READ_COMMITTED);
221-
222-
// Now turn on AutoCommit. Transaction Isolation doesn't work outside of
223-
// a transaction, so they should return READ_COMMITTED at all times!
224-
con.setAutoCommit(true);
225-
con.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
226-
assert(con.getTransactionIsolation()==Connection.TRANSACTION_READ_COMMITTED);
227-
228-
con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
229-
assert(con.getTransactionIsolation()==Connection.TRANSACTION_READ_COMMITTED);
230-
231-
JDBC2Tests.closeDB(con);
232-
} catch(SQLException ex) {
233-
assert(ex.getMessage(),false);
234-
}
235-
}
206+
/**
207+
* Transaction Isolation Levels
208+
*/
209+
public void testTransactionIsolation()
210+
{
211+
try
212+
{
213+
Connection con = JDBC2Tests.openDB();
214+
215+
// PostgreSQL defaults to READ COMMITTED
216+
assertEquals( con.getTransactionIsolation(),
217+
Connection.TRANSACTION_READ_COMMITTED );
218+
219+
// Begin a transaction
220+
con.setAutoCommit(false);
221+
222+
// The isolation level should not have changed
223+
assertEquals( con.getTransactionIsolation(),
224+
Connection.TRANSACTION_READ_COMMITTED );
225+
226+
// Now change the default for future transactions
227+
con.setTransactionIsolation( Connection.TRANSACTION_SERIALIZABLE );
228+
229+
// Since the call to setTransactionIsolation() above was made
230+
// inside the transaction, the isolation level of the current
231+
// transaction did not change. It affects only future transactions.
232+
// This behaviour is recommended by the JDBC spec.
233+
assertEquals( con.getTransactionIsolation(),
234+
Connection.TRANSACTION_READ_COMMITTED );
235+
236+
// Begin a new transaction
237+
con.commit();
238+
239+
// Now we should see the new isolation level
240+
assertEquals( con.getTransactionIsolation(),
241+
Connection.TRANSACTION_SERIALIZABLE );
242+
243+
// Repeat the steps above with the transition back to
244+
// READ COMMITTED.
245+
con.setTransactionIsolation(
246+
Connection.TRANSACTION_READ_COMMITTED );
247+
assertEquals( con.getTransactionIsolation(),
248+
Connection.TRANSACTION_SERIALIZABLE );
249+
con.commit();
250+
assertEquals( con.getTransactionIsolation(),
251+
Connection.TRANSACTION_READ_COMMITTED );
252+
253+
// Now run some tests with autocommit enabled.
254+
con.setAutoCommit(true);
255+
256+
assertEquals( con.getTransactionIsolation(),
257+
Connection.TRANSACTION_READ_COMMITTED );
258+
259+
con.setTransactionIsolation( Connection.TRANSACTION_SERIALIZABLE );
260+
assertEquals( con.getTransactionIsolation(),
261+
Connection.TRANSACTION_SERIALIZABLE );
262+
263+
con.setTransactionIsolation(
264+
Connection.TRANSACTION_READ_COMMITTED );
265+
assertEquals( con.getTransactionIsolation(),
266+
Connection.TRANSACTION_READ_COMMITTED );
267+
268+
// Test if a change of isolation level before beginning the
269+
// transaction affects the isolation level inside the transaction.
270+
con.setTransactionIsolation( Connection.TRANSACTION_SERIALIZABLE );
271+
assertEquals( con.getTransactionIsolation(),
272+
Connection.TRANSACTION_SERIALIZABLE );
273+
con.setAutoCommit(false);
274+
assertEquals( con.getTransactionIsolation(),
275+
Connection.TRANSACTION_SERIALIZABLE );
276+
con.setAutoCommit(true);
277+
assertEquals( con.getTransactionIsolation(),
278+
Connection.TRANSACTION_SERIALIZABLE );
279+
con.setTransactionIsolation(
280+
Connection.TRANSACTION_READ_COMMITTED );
281+
assertEquals( con.getTransactionIsolation(),
282+
Connection.TRANSACTION_READ_COMMITTED );
283+
con.setAutoCommit(false);
284+
assertEquals( con.getTransactionIsolation(),
285+
Connection.TRANSACTION_READ_COMMITTED );
286+
287+
JDBC2Tests.closeDB(con);
288+
}
289+
catch ( SQLException ex )
290+
{
291+
fail( ex.getMessage() );
292+
}
293+
}
236294

237295
/**
238296
* JDBC2 Type mappings

0 commit comments

Comments
 (0)