Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc69bb04

Browse files
committed
Attached is a patch that fixes
ConnectionTest.testTransactionIsolation() in the JDBC driver'stest suite. This reduces the number of failures of the testsuite from 7 to 6. The patch fixes the test case itself, ratherthan the driver.In addition to the change described in my posting below, I fixedthe part of the test with autocommit enabled. The author of thetest assumed that setting the transaction isolation level wouldhave no effect, but in fact it does. Perhaps the test caseworked with pre-7.1 behaviour, when the JDBC driver set theisolation level in every transaction, instead of using "setsession characteristics". Anyway, now it works with a backendbuilt from current CVS and the behaviour is JDBC compliant.I also extended the test case by changing the isolation levelbefore beginning a transaction and verifying it inside thetransaction.Regards,Ren? Pijlman
1 parentd70a944 commitc69bb04

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

Lines changed: 89 additions & 31 deletions
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
publicclassConnectionTestextendsTestCase {
@@ -203,36 +203,94 @@ public void testWarnings() {
203203
}
204204
}
205205

206-
/**
207-
* Transaction Isolation Levels
208-
*/
209-
publicvoidtestTransactionIsolation() {
210-
try {
211-
Connectioncon =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(SQLExceptionex) {
233-
assert(ex.getMessage(),false);
234-
}
235-
}
206+
/**
207+
* Transaction Isolation Levels
208+
*/
209+
publicvoidtestTransactionIsolation()
210+
{
211+
try
212+
{
213+
Connectioncon =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 (SQLExceptionex )
290+
{
291+
fail(ex.getMessage() );
292+
}
293+
}
236294

237295
/**
238296
* JDBC2 Type mappings

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp