use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class TXWriterJUnitTest method testNoCallbacksOnTransactionWriterThrow.
/**
* make sure standard Cache(Listener,Writer) are not called during rollback due to transaction
* writer throw
*/
@Test
public void testNoCallbacksOnTransactionWriterThrow() 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();
this.txMgr.begin();
this.region.create("key1", "value1");
this.cbCount = 0;
try {
this.txMgr.commit();
fail("Commit should have thrown CommitConflictException");
} catch (CommitConflictException cce) {
assertNotNull(cce.getCause());
assertTrue(cce.getCause() instanceof TransactionWriterException);
}
assertEquals(0, this.cbCount);
this.cbCount = 0;
this.region.create("key1", "value1");
// do a sanity check to make sure callbacks are installed
// 2 -> 1writer + 1listener
assertEquals(2, this.cbCount);
this.txMgr.begin();
this.region.put("key1", "value2");
this.cbCount = 0;
try {
this.txMgr.commit();
fail("Commit should have thrown CommitConflictException");
} catch (CommitConflictException expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() instanceof TransactionWriterException);
}
assertEquals(0, this.cbCount);
this.region.localDestroy("key1");
this.region.create("key1", "value1");
this.txMgr.begin();
this.region.localDestroy("key1");
this.cbCount = 0;
try {
this.txMgr.commit();
fail("Commit should have thrown CommitConflictException");
} catch (CommitConflictException expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() instanceof TransactionWriterException);
}
assertEquals(0, this.cbCount);
this.region.put("key1", "value1");
this.txMgr.begin();
this.region.destroy("key1");
this.cbCount = 0;
try {
this.txMgr.commit();
fail("Commit should have thrown CommitConflictException");
} catch (CommitConflictException expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() instanceof TransactionWriterException);
}
assertEquals(0, this.cbCount);
this.region.put("key1", "value1");
this.txMgr.begin();
this.region.localInvalidate("key1");
this.cbCount = 0;
try {
this.txMgr.commit();
fail("Commit should have thrown CommitConflictException");
} catch (CommitConflictException expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() instanceof TransactionWriterException);
}
assertEquals(0, this.cbCount);
this.region.localDestroy("key1");
this.region.put("key1", "value1");
this.txMgr.begin();
this.region.invalidate("key1");
this.cbCount = 0;
try {
this.txMgr.commit();
fail("Commit should have thrown CommitConflictException");
} catch (CommitConflictException expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() instanceof TransactionWriterException);
}
assertEquals(0, this.cbCount);
this.region.localDestroy("key1");
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class TXJUnitTest method testClearRegionNotSupported.
/**
* make sure that we throw an UnsupportedOperationInTransactionException
*
* @throws Exception
*/
@Test
public void testClearRegionNotSupported() throws Exception {
CacheTransactionManager ctm = this.cache.getCacheTransactionManager();
AttributesFactory af = new AttributesFactory();
Region r = this.cache.createRegion("dRegion", af.create());
PartitionAttributes pa = new PartitionAttributesFactory().setRedundantCopies(0).setTotalNumBuckets(1).create();
af.setPartitionAttributes(pa);
Region pr = this.cache.createRegion("prRegion", af.create());
ctm.begin();
try {
pr.clear();
fail("Should have thrown UnsupportedOperation during invalidateRegion");
} catch (UnsupportedOperationException ee) {
// expected
}
try {
pr.localClear();
fail("Should have thrown UnsupportedOperation during localInvalidateRegion");
} catch (UnsupportedOperationException ee) {
// expected
}
try {
r.clear();
fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.localClear();
fail("Should have thrown UnsupportedOperationInTransactionException during localInvalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
ctm.commit();
// now we aren't in tx so these shouldn't throw
pr.invalidateRegion();
r.invalidateRegion();
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class TXWriterJUnitTest method testAfterCommitFailedOnThrowNPE.
@Test
public void testAfterCommitFailedOnThrowNPE() throws Exception {
installCacheListenerAndWriter();
((CacheTransactionManager) this.txMgr).setWriter(new TransactionWriter() {
public void beforeCommit(TransactionEvent event) throws TransactionWriterException {
throw new NullPointerException("this is expected!");
}
public void close() {
}
});
installTransactionListener();
this.txMgr.begin();
this.region.create("key1", "value1");
this.cbCount = 0;
try {
this.txMgr.commit();
fail("Commit should have thrown CommitConflictException");
} catch (CommitConflictException expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() instanceof NullPointerException);
}
assertEquals(0, this.cbCount);
assertEquals(1, this.failedCommits);
assertEquals(0, this.afterCommits);
assertEquals(0, this.afterRollbacks);
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class CacheXml66DUnitTest method testTXManagerOnClientCache.
@Test
public void testTXManagerOnClientCache() throws Exception {
ClientCacheCreation cc = new ClientCacheCreation();
// CacheCreation cc = new CacheCreation();
CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation();
txMgrCreation.addListener(new TestTXListener());
cc.addCacheTransactionManagerCreation(txMgrCreation);
testXml(cc);
Cache c = getCache();
assertTrue(c instanceof ClientCache);
c.loadCacheXml(generate(cc));
ClientCache clientC = (ClientCache) c;
CacheTransactionManager mgr = clientC.getCacheTransactionManager();
assertNotNull(mgr);
assertTrue(mgr.getListeners()[0] instanceof TestTXListener);
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class Bug34387DUnitTest method doCommitOtherVm.
private void doCommitOtherVm(final boolean doDestroy) {
VM vm = getOtherVm();
vm.invoke(new CacheSerializableRunnable("create root") {
public void run2() throws CacheException {
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_ACK);
af.setConcurrencyChecksEnabled(true);
Region r1 = createRootRegion("r1", af.create());
CacheTransactionManager ctm = getCache().getCacheTransactionManager();
ctm.begin();
r1.create("createKey", "createValue");
if (doDestroy) {
try {
r1.localDestroy("createKey");
fail("expected exception not thrown");
} catch (UnsupportedOperationInTransactionException e) {
assertEquals(e.getMessage(), LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
}
} else {
try {
r1.localInvalidate("createKey");
fail("expected exception not thrown");
} catch (UnsupportedOperationInTransactionException e) {
assertEquals(e.getMessage(), LocalizedStrings.TXStateStub_LOCAL_INVALIDATE_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
}
}
ctm.commit();
}
});
}
Aggregations