-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick suspend support. Enable tx.suspend without xaresource.end #40
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,19 +37,28 @@ public class JtaTest extends TestCase { | |
|
||
private final static Logger log = LoggerFactory.getLogger(JtaTest.class); | ||
|
||
private BitronixTransactionManager btm; | ||
private BitronixTransactionManager _btm; | ||
|
||
protected void setUp() throws Exception { | ||
TransactionManagerServices.getConfiguration().setGracefulShutdownInterval(1); | ||
TransactionManagerServices.getConfiguration().setExceptionAnalyzer(DefaultExceptionAnalyzer.class.getName()); | ||
btm = TransactionManagerServices.getTransactionManager(); | ||
_btm = null; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to support configuration updates per testcase. |
||
|
||
protected BitronixTransactionManager getBtm() { | ||
if (_btm == null) { | ||
_btm = TransactionManagerServices.getTransactionManager(); | ||
} | ||
return _btm; | ||
} | ||
|
||
protected void tearDown() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
btm.shutdown(); | ||
} | ||
|
||
public void testTransactionManagerGetTransaction() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
assertNull(btm.getTransaction()); | ||
|
||
btm.begin(); | ||
|
@@ -66,6 +75,22 @@ public void testTransactionManagerGetTransaction() throws Exception { | |
|
||
// this test also helps verifying MDC support but logs have to be manually checked | ||
public void testSuspendResume() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
log.info("test starts"); | ||
btm.begin(); | ||
log.info("tx begun"); | ||
Transaction tx = btm.suspend(); | ||
log.info("tx suspended"); | ||
btm.resume(tx); | ||
log.info("tx resumed"); | ||
btm.rollback(); | ||
log.info("test over"); | ||
} | ||
|
||
// this test also helps verifying MDC support but logs have to be manually checked | ||
public void testQuickSuspendResume() throws Exception { | ||
TransactionManagerServices.getConfiguration().setQuickSuspend(true); | ||
BitronixTransactionManager btm = getBtm(); | ||
log.info("test starts"); | ||
btm.begin(); | ||
log.info("tx begun"); | ||
|
@@ -78,6 +103,7 @@ public void testSuspendResume() throws Exception { | |
} | ||
|
||
public void testTimeout() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
btm.setTransactionTimeout(1); | ||
btm.begin(); | ||
CountingSynchronization sync = new CountingSynchronization(); | ||
|
@@ -97,6 +123,7 @@ public void testTimeout() throws Exception { | |
} | ||
|
||
public void testMarkedRollback() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
btm.begin(); | ||
CountingSynchronization sync = new CountingSynchronization(); | ||
btm.getTransaction().registerSynchronization(sync); | ||
|
@@ -115,6 +142,7 @@ public void testMarkedRollback() throws Exception { | |
} | ||
|
||
public void testRecycleAfterSuspend() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
PoolingDataSource pds = new PoolingDataSource(); | ||
pds.setClassName(LrcXADataSource.class.getName()); | ||
pds.setUniqueName("lrc-pds"); | ||
|
@@ -150,7 +178,46 @@ public void testRecycleAfterSuspend() throws Exception { | |
pds.close(); | ||
} | ||
|
||
public void testRecycleAfterQuickSuspend() throws Exception { | ||
TransactionManagerServices.getConfiguration().setQuickSuspend(true); | ||
BitronixTransactionManager btm = getBtm(); | ||
PoolingDataSource pds = new PoolingDataSource(); | ||
pds.setClassName(LrcXADataSource.class.getName()); | ||
pds.setUniqueName("lrc-pds"); | ||
pds.setMaxPoolSize(2); | ||
pds.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName()); | ||
pds.init(); | ||
|
||
btm.begin(); | ||
|
||
Connection c1 = pds.getConnection(); | ||
c1.createStatement(); | ||
c1.close(); | ||
|
||
Transaction tx = btm.suspend(); | ||
|
||
btm.begin(); | ||
|
||
Connection c11 = pds.getConnection(); | ||
c11.createStatement(); | ||
c11.close(); | ||
|
||
btm.commit(); | ||
|
||
|
||
btm.resume(tx); | ||
|
||
Connection c2 = pds.getConnection(); | ||
c2.createStatement(); | ||
c2.close(); | ||
|
||
btm.commit(); | ||
|
||
pds.close(); | ||
} | ||
|
||
public void testTransactionContextCleanup() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
assertEquals(Status.STATUS_NO_TRANSACTION, btm.getStatus()); | ||
|
||
btm.begin(); | ||
|
@@ -177,6 +244,7 @@ public void run() { | |
} | ||
|
||
public void testBeforeCompletionAddsExtraSynchronizationInDifferentPriority() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
btm.begin(); | ||
|
||
btm.getCurrentTransaction().getSynchronizationScheduler().add(new SynchronizationRegisteringSynchronization(btm.getCurrentTransaction()), 5); | ||
|
@@ -185,22 +253,23 @@ public void testBeforeCompletionAddsExtraSynchronizationInDifferentPriority() th | |
} | ||
|
||
public void testDebugZeroResourceTransactionDisabled() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
btm.begin(); | ||
assertNull("Activation stack trace must not be available by default.", btm.getCurrentTransaction().getActivationStackTrace()); | ||
btm.commit(); | ||
} | ||
|
||
public void testDebugZeroResourceTransaction() throws Exception { | ||
btm.shutdown(); // necessary to change the configuration | ||
TransactionManagerServices.getConfiguration().setDebugZeroResourceTransaction(true); | ||
btm = TransactionManagerServices.getTransactionManager(); | ||
BitronixTransactionManager btm = getBtm(); | ||
|
||
btm.begin(); | ||
assertNotNull("Activation stack trace must be available.", btm.getCurrentTransaction().getActivationStackTrace()); | ||
btm.commit(); | ||
} | ||
|
||
public void testBeforeCompletionRuntimeExceptionRethrown() throws Exception { | ||
BitronixTransactionManager btm = getBtm(); | ||
btm.begin(); | ||
|
||
btm.getTransaction().registerSynchronization(new Synchronization() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,9 @@ public abstract class AbstractMockJdbcTest extends TestCase { | |
|
||
@Override | ||
protected void setUp() throws Exception { | ||
// clear event recorder list | ||
EventRecorder.clear(); | ||
|
||
Iterator<String> it = ResourceRegistrar.getResourcesUniqueNames().iterator(); | ||
while (it.hasNext()) { | ||
String name = it.next(); | ||
|
@@ -92,12 +95,6 @@ protected void setUp() throws Exception { | |
registerPoolEventListener(p2); | ||
|
||
TransactionManagerServices.getConfiguration().setGracefulShutdownInterval(2); | ||
|
||
// start TM | ||
TransactionManagerServices.getTransactionManager(); | ||
|
||
// clear event recorder list | ||
EventRecorder.clear(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the call to getTransactionManager() to make it easy to alter configuration in testcases. This also meant we needed to control the EventRecorder in each, but that felt more natural to me anyway since those tests expect very fine grain control over the activity in the ER. |
||
|
||
@SuppressWarnings("unchecked") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed my approach on quick suspend/remove slightly to leave the resource-holder in a started state. This seems to be more aligned with the state transitions below (it has not been ended, and start is not expected).