Search in sources :

Example 16 with TransactionEvent

use of org.apache.geode.cache.TransactionEvent in project geode by apache.

the class TXOrderDUnitTest method testFarSideOrder.

/**
   * make sure listeners get invoked in correct order on far side of tx
   */
@Test
public void testFarSideOrder() throws CacheException {
    initOtherId();
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setScope(Scope.DISTRIBUTED_ACK);
    CacheListener cl1 = new CacheListenerAdapter() {

        public void afterCreate(EntryEvent e) {
            assertEquals(getCurrentExpectedKey(), e.getKey());
        }
    };
    af.addCacheListener(cl1);
    Region r1 = createRootRegion("r1", af.create());
    Region r2 = r1.createSubregion("r2", af.create());
    r2.createSubregion("r3", af.create());
    TransactionListener tl1 = new TransactionListenerAdapter() {

        public void afterCommit(TransactionEvent e) {
            assertEquals(6, e.getEvents().size());
            ArrayList keys = new ArrayList();
            Iterator it = e.getEvents().iterator();
            while (it.hasNext()) {
                EntryEvent ee = (EntryEvent) it.next();
                keys.add(ee.getKey());
                assertEquals(null, ee.getCallbackArgument());
                assertEquals(true, ee.isCallbackArgumentAvailable());
            }
            assertEquals(TXOrderDUnitTest.this.expectedKeys, keys);
            TXOrderDUnitTest.this.invokeCount = 1;
        }
    };
    CacheTransactionManager ctm = getCache().getCacheTransactionManager();
    ctm.addListener(tl1);
    this.invokeCount = 0;
    this.clCount = 0;
    this.expectedKeys = Arrays.asList(new String[] { "b", "c", "a", "a2", "c2", "b2" });
    doCommitOtherVm();
    assertEquals(1, this.invokeCount);
    assertEquals(6, this.clCount);
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener) TransactionListenerAdapter(org.apache.geode.cache.util.TransactionListenerAdapter) TransactionEvent(org.apache.geode.cache.TransactionEvent) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) CacheListener(org.apache.geode.cache.CacheListener) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

TransactionEvent (org.apache.geode.cache.TransactionEvent)16 Test (org.junit.Test)14 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)12 TransactionListener (org.apache.geode.cache.TransactionListener)10 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)9 CommitConflictException (org.apache.geode.cache.CommitConflictException)7 EntryEvent (org.apache.geode.cache.EntryEvent)6 TransactionWriter (org.apache.geode.cache.TransactionWriter)6 TransactionWriterException (org.apache.geode.cache.TransactionWriterException)6 ArrayList (java.util.ArrayList)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 Region (org.apache.geode.cache.Region)4 SynchronizationCommitConflictException (org.apache.geode.cache.SynchronizationCommitConflictException)4 TransactionId (org.apache.geode.cache.TransactionId)4 TransactionListenerAdapter (org.apache.geode.cache.util.TransactionListenerAdapter)4 Iterator (java.util.Iterator)3 List (java.util.List)3 CacheException (org.apache.geode.cache.CacheException)3 CacheListener (org.apache.geode.cache.CacheListener)3