use of org.apache.geode.cache.SynchronizationCommitConflictException in project geode by apache.
the class TXWriterJUnitTest method testAfterCommitFailedOnTransactionWriterThrowWithJTA.
/**
* make sure standard Cache(Listener,Writer) are not called during rollback due to transaction
* writer throw
*/
@Test
public void testAfterCommitFailedOnTransactionWriterThrowWithJTA() throws Exception {
installCacheListenerAndWriter();
((CacheTransactionManager) this.txMgr).setWriter(new TransactionWriter() {
public void beforeCommit(TransactionEvent event) throws TransactionWriterException {
throw new TransactionWriterException("Rollback now!");
}
public void close() {
}
});
installTransactionListener();
UserTransaction userTx = (UserTransaction) this.cache.getJNDIContext().lookup("java:/UserTransaction");
userTx.begin();
this.region.create("key1", "value1");
this.cbCount = 0;
try {
userTx.commit();
fail("Commit should have thrown RollbackException");
} catch (RollbackException expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() + " is not a SynchronizationCommitConflictException", expected.getCause() instanceof SynchronizationCommitConflictException);
}
assertEquals(0, this.cbCount);
assertEquals(1, this.failedCommits);
assertEquals(0, this.afterCommits);
assertEquals(1, this.afterRollbacks);
}
use of org.apache.geode.cache.SynchronizationCommitConflictException in project geode by apache.
the class TXState method beforeCompletion.
//////////////////////////////////////////////////////////////////
// JTA Synchronization implementation //
//////////////////////////////////////////////////////////////////
/*
* (non-Javadoc)
*
* @see org.apache.geode.internal.cache.TXStateInterface#beforeCompletion()
*/
public void beforeCompletion() throws SynchronizationCommitConflictException {
if (this.closed) {
throw new TXManagerCancelledException();
}
this.proxy.getTxMgr().setTXState(null);
final long opStart = CachePerfStats.getStatTime();
this.jtaLifeTime = opStart - getBeginTime();
try {
reserveAndCheck();
/*
* If there is a TransactionWriter plugged in, we need to to give it an opportunity to abort
* the transaction.
*/
TransactionWriter writer = this.proxy.getTxMgr().getWriter();
if (writer != null) {
try {
// need to mark this so we don't fire again in commit
firedWriter = true;
TXEvent event = getEvent();
if (!event.hasOnlyInternalEvents()) {
writer.beforeCommit(event);
}
} catch (TransactionWriterException twe) {
cleanup();
throw new CommitConflictException(twe);
} catch (VirtualMachineError err) {
// cleanup(); this allocates objects so I don't think we can do it - that leaves the TX
// open, but we are poison pilling so we should be ok??
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// rollback the transaction!
cleanup();
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
throw new CommitConflictException(t);
}
}
} catch (CommitConflictException commitConflict) {
this.proxy.getTxMgr().noteCommitFailure(opStart, this.jtaLifeTime, this);
throw new SynchronizationCommitConflictException(LocalizedStrings.TXState_CONFLICT_DETECTED_IN_GEMFIRE_TRANSACTION_0.toLocalizedString(getTransactionId()), commitConflict);
}
}
Aggregations