org.apache.derbyTesting.functionTests.tests.jdbcapi
Class XATransactionTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.jdbcapi.XATransactionTest
All Implemented Interfaces:
junit.framework.Test

public class XATransactionTest
extends BaseJDBCTestCase

The test of the properties of the XA transaction interface implementation.


Field Summary
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
XATransactionTest(java.lang.String name)
           
 
Method Summary
(package private) static javax.transaction.xa.Xid createXid(int gtrid, int bqual)
          Create the Xid object for global transaction identification with the specified identification values.
private static javax.transaction.xa.Xid parseXid(java.lang.String str)
          Parses the xid value from the string.
static junit.framework.Test suite()
           
 void testGlobalXIDinTransactionTable()
          Tests whether it is possible to reconstruct the original Xid value correctly from SYSCS_DIAG.TRANSACTION_TABLE.
 void testPendingLocalTranAndServerShutdown()
          This test does following 1)Start the network server 2)Start a local xa transaction 3)Do not commit the local XA transaction 4)Shutdown the network server 5)Start the server again Before the fix for DERBY-4053 went in, step 4) would not shutdown the server properly because of the pending local XA transaction.
 void testTransactionTimeoutAndJoin()
          DERBY-4232: Test that two branches can be joined after the timeout has been set.
 void testTransactionTimeoutAndSuspendResume()
          DERBY-4232: Test that an XA transaction can be suspended and resumed when a timeout is in effect.
 void testXAExceptionErrorCodeOnSQLExceptionDerby4141()
          DERBY-4141 XAExceptions caused by SQLExceptions should have a non-zero errorCode.
 void testXATransactionTimeout()
          Tests the functionality of the XA transaction timeout.
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XATransactionTest

public XATransactionTest(java.lang.String name)
Method Detail

testPendingLocalTranAndServerShutdown

public void testPendingLocalTranAndServerShutdown()
                                           throws java.lang.Exception
This test does following 1)Start the network server 2)Start a local xa transaction 3)Do not commit the local XA transaction 4)Shutdown the network server 5)Start the server again Before the fix for DERBY-4053 went in, step 4) would not shutdown the server properly because of the pending local XA transaction. During the server shutdown, we try to close all the open connections but the close on the XA connection results into an exception because there is still a pending transaction. That exception is not handled by the server and because of that, all the code necessary to shutdown the server is not executed. The next time around, step 5), when we try to bring up the server again, it ends up hanging 2009-07-09 21:21:28.828 GMT : Invalid reply from network server: Insufficient data. 2009-07-09 21:21:28.843 GMT : Could not listen on port 1527 on host 127.0.0.1: java.net.BindException: Address already in use: JVM_Bind The fix for DERBY-4053 makes sure that before calling close on local XA transaction, we first rollback any transaction active on the connection.

Throws:
java.lang.Exception

testGlobalXIDinTransactionTable

public void testGlobalXIDinTransactionTable()
                                     throws java.lang.Exception
Tests whether it is possible to reconstruct the original Xid value correctly from SYSCS_DIAG.TRANSACTION_TABLE.

Throws:
java.lang.Exception

testXATransactionTimeout

public void testXATransactionTimeout()
                              throws java.lang.Exception
Tests the functionality of the XA transaction timeout.

It executes 66 global transactions during the test. Everyone of them just inserts a row into XATT table. The rows inserted by the transactions are different. Some of these transactions are committed and some of them are left in different stages. The stage of the transaction in which it is left is chosed depending on division remainders.

After finishing these 1000 transactions a select statement is executed on that table. However, if there are still some unfinished transactions that were not aborted they will hold a lock on a XATT table until they will get rolled back by the transaction timeout. The number of rows in the XATT table is calculated. It is then compared with the excepted number of rows (the transaction we know we have committed).

The call to xaRes.setTransactionTimeout(5) before the call to xaRes.start() makes the transactions to be rolled back due to timeout.

Throws:
java.lang.Exception

testTransactionTimeoutAndSuspendResume

public void testTransactionTimeoutAndSuspendResume()
                                            throws java.lang.Exception
DERBY-4232: Test that an XA transaction can be suspended and resumed when a timeout is in effect.

Throws:
java.lang.Exception

testTransactionTimeoutAndJoin

public void testTransactionTimeoutAndJoin()
                                   throws java.lang.Exception
DERBY-4232: Test that two branches can be joined after the timeout has been set.

Throws:
java.lang.Exception

testXAExceptionErrorCodeOnSQLExceptionDerby4141

public void testXAExceptionErrorCodeOnSQLExceptionDerby4141()
                                                     throws java.lang.Exception
DERBY-4141 XAExceptions caused by SQLExceptions should have a non-zero errorCode. SESSION_SEVERITY or greater map to XAException.XAER_RMFAIL. Lesser exceptions map to XAException.XAER_RMERR

Throws:
java.lang.Exception

createXid

static javax.transaction.xa.Xid createXid(int gtrid,
                                          int bqual)
                                   throws javax.transaction.xa.XAException
Create the Xid object for global transaction identification with the specified identification values.

Parameters:
gtrid - Global Transaction ID
bqual - Branch Qualifier
Throws:
javax.transaction.xa.XAException

parseXid

private static javax.transaction.xa.Xid parseXid(java.lang.String str)
Parses the xid value from the string. The format of the input string is the same as the global_xid column in syscs_diag.transaction_table table - '(formatid_in_dec,global_transaction_id_in_hex,branch_qualifier_in_hex)'

Parameters:
str - Global Transaction ID converted to a string.
Returns:
The xid object corresponding to the xid specified in a string.

suite

public static junit.framework.Test suite()

Built on Sat 2009-11-28 18:44:18-0800, from revision 885187

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.