use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class TXJUnitTest method testInternalRegionNotExposed.
/**
* make sure that we do not expose BucketRegion on transactionListener events
*
* @throws Exception
*/
@Test
public void testInternalRegionNotExposed() throws Exception {
TransactionListenerForRegionTest tl = new TransactionListenerForRegionTest();
CacheTransactionManager ctm = this.cache.getCacheTransactionManager();
ctm.addListener(tl);
CacheListenerForRegionTest cl = new CacheListenerForRegionTest();
AttributesFactory af = new AttributesFactory();
PartitionAttributes pa = new PartitionAttributesFactory().setRedundantCopies(0).setTotalNumBuckets(1).create();
af.setPartitionAttributes(pa);
af.addCacheListener(cl);
Region pr = this.cache.createRegion("testTxEventForRegion", af.create());
pr.put(2, "tw");
pr.put(3, "three");
pr.put(4, "four");
ctm.begin();
pr.put(1, "one");
pr.put(2, "two");
pr.invalidate(3);
pr.destroy(4);
ctm.commit();
assertFalse(tl.exceptionOccurred);
assertFalse(cl.exceptionOccurred);
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class TXJUnitTest method testBug51781.
@Test
public void testBug51781() {
AttributesFactory<Integer, String> af = new AttributesFactory<Integer, String>();
af.setDataPolicy(DataPolicy.NORMAL);
Region<Integer, String> r = this.cache.createRegion(getUniqueName(), af.create());
CacheTransactionManager mgr = this.cache.getCacheTransactionManager();
r.put(1, "value1");
r.put(2, "value2");
assertEquals(2, r.size());
mgr.begin();
r.put(3, "value3");
r.destroy(3);
mgr.commit();
assertEquals(2, r.size());
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class TXJUnitTest method testDestroyRegionNotSupported.
/**
* make sure that we throw an UnsupportedOperationInTransactionException
*
* @throws Exception
*/
@Test
public void testDestroyRegionNotSupported() 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());
List list = new ArrayList();
list.add("stuff");
list.add("stuff2");
ctm.begin();
try {
pr.destroyRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during destroyRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
pr.localDestroyRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during localDestroyRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.destroyRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during destroyRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.localDestroyRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during localDestroyRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
assertTrue(!pr.isDestroyed());
assertTrue(!r.isDestroyed());
ctm.commit();
// now we aren't in tx so these shouldn't throw
pr.destroyRegion();
r.destroyRegion();
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class TXJUnitTest method testInvalidateRegionNotSupported.
/**
* make sure that we throw an UnsupportedOperationInTransactionException
*
* @throws Exception
*/
@Test
public void testInvalidateRegionNotSupported() 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.invalidateRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
pr.localInvalidateRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during localInvalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.invalidateRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.localInvalidateRegion();
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 testAfterCommitFailedOnTransactionWriterThrow.
/**
* make sure standard Cache(Listener,Writer) are not called during rollback due to transaction
* writer throw
*/
@Test
public void testAfterCommitFailedOnTransactionWriterThrow() 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 expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() instanceof TransactionWriterException);
}
assertEquals(0, this.cbCount);
assertEquals(1, this.failedCommits);
assertEquals(0, this.afterCommits);
assertEquals(0, this.afterRollbacks);
}
Aggregations