Search in sources :

Example 46 with CacheTransactionManager

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);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 47 with CacheTransactionManager

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());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 48 with CacheTransactionManager

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();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) ArrayList(java.util.ArrayList) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) List(java.util.List) ArrayList(java.util.ArrayList) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 49 with CacheTransactionManager

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();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 50 with CacheTransactionManager

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);
}
Also used : TransactionEvent(org.apache.geode.cache.TransactionEvent) CommitConflictException(org.apache.geode.cache.CommitConflictException) SynchronizationCommitConflictException(org.apache.geode.cache.SynchronizationCommitConflictException) TransactionWriter(org.apache.geode.cache.TransactionWriter) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)120 Region (org.apache.geode.cache.Region)81 Test (org.junit.Test)77 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)53 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)52 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)51 VM (org.apache.geode.test.dunit.VM)51 LocalRegion (org.apache.geode.internal.cache.LocalRegion)46 CommitConflictException (org.apache.geode.cache.CommitConflictException)45 Host (org.apache.geode.test.dunit.Host)45 CustId (org.apache.geode.internal.cache.execute.data.CustId)37 Customer (org.apache.geode.internal.cache.execute.data.Customer)34 BucketRegion (org.apache.geode.internal.cache.BucketRegion)27 AttributesFactory (org.apache.geode.cache.AttributesFactory)26 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)24 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)23 IgnoredException (org.apache.geode.test.dunit.IgnoredException)23 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)22 CacheWriterException (org.apache.geode.cache.CacheWriterException)21 TransactionWriterException (org.apache.geode.cache.TransactionWriterException)21