Search in sources :

Example 6 with TransactionListener

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

the class TXManagerImpl method setListener.

public TransactionListener setListener(TransactionListener newListener) {
    synchronized (this.txListeners) {
        TransactionListener result = getListener();
        this.txListeners.clear();
        if (newListener != null) {
            this.txListeners.add(newListener);
        }
        if (result != null) {
            closeListener(result);
        }
        return result;
    }
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener)

Example 7 with TransactionListener

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

the class CacheTransactionManagerCreation method setListener.

public TransactionListener setListener(TransactionListener newListener) {
    TransactionListener result = getListener();
    this.txListeners.clear();
    if (newListener != null) {
        this.txListeners.add(newListener);
    }
    return result;
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener)

Example 8 with TransactionListener

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

the class CallbackArgDUnitTest method doCommitOtherVm.

private void doCommitOtherVm() {
    VM vm = getOtherVm();
    vm.invoke(new CacheSerializableRunnable("create root") {

        public void run2() throws CacheException {
            AttributesFactory af = new AttributesFactory();
            CacheListener cl1 = new CacheListenerAdapter() {

                public void afterCreate(EntryEvent e) {
                    assertEquals(callbackArg, e.getCallbackArgument());
                }
            };
            af.addCacheListener(cl1);
            af.setScope(Scope.DISTRIBUTED_ACK);
            Region r1 = createRootRegion("r1", af.create());
            Region r2 = r1.createSubregion("r2", af.create());
            Region r3 = r2.createSubregion("r3", af.create());
            CacheTransactionManager ctm = getCache().getCacheTransactionManager();
            TransactionListener tl1 = new TransactionListenerAdapter() {

                public void afterCommit(TransactionEvent e) {
                    assertEquals(6, e.getEvents().size());
                    Iterator it = e.getEvents().iterator();
                    while (it.hasNext()) {
                        EntryEvent ee = (EntryEvent) it.next();
                        assertEquals(callbackArg, ee.getCallbackArgument());
                        assertEquals(true, ee.isCallbackArgumentAvailable());
                    }
                }
            };
            ctm.addListener(tl1);
            ctm.begin();
            r2.put("b", "value1", callbackArg);
            r3.put("c", "value2", callbackArg);
            r1.put("a", "value3", callbackArg);
            r1.put("a2", "value4", callbackArg);
            r3.put("c2", "value5", callbackArg);
            r2.put("b2", "value6", callbackArg);
            ctm.commit();
        }
    });
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener) TransactionListenerAdapter(org.apache.geode.cache.util.TransactionListenerAdapter) CacheException(org.apache.geode.cache.CacheException) CacheListener(org.apache.geode.cache.CacheListener) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) TransactionEvent(org.apache.geode.cache.TransactionEvent) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region)

Example 9 with TransactionListener

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

the class CacheTransactionManagerCreationTest method shouldBeMockable.

@Test
public void shouldBeMockable() throws Exception {
    CacheTransactionManagerCreation mockCacheTransactionManagerCreation = mock(CacheTransactionManagerCreation.class);
    TransactionListener mockTransactionListener = mock(TransactionListener.class);
    TransactionWriter mockTransactionWriter = mock(TransactionWriter.class);
    when(mockCacheTransactionManagerCreation.getListener()).thenReturn(mockTransactionListener);
    mockCacheTransactionManagerCreation.setWriter(mockTransactionWriter);
    verify(mockCacheTransactionManagerCreation, times(1)).setWriter(mockTransactionWriter);
    assertThat(mockCacheTransactionManagerCreation.getListener()).isSameAs(mockTransactionListener);
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener) TransactionWriter(org.apache.geode.cache.TransactionWriter) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 10 with TransactionListener

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

the class CacheXml66DUnitTest method testMultipleTXListener.

/**
   * Tests multiple transaction listeners
   * 
   * @since GemFire 5.0
   */
@Test
public void testMultipleTXListener() throws Exception {
    CacheCreation cache = new CacheCreation();
    CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation();
    TransactionListener l1 = new MyTestTransactionListener();
    TransactionListener l2 = new MySecondTestTransactionListener();
    txMgrCreation.addListener(l1);
    txMgrCreation.addListener(l2);
    cache.addCacheTransactionManagerCreation(txMgrCreation);
    testXml(cache);
    {
        CacheTransactionManager tm = getCache().getCacheTransactionManager();
        assertEquals(Arrays.asList(new TransactionListener[] { l1, l2 }), Arrays.asList(tm.getListeners()));
        tm.removeListener(l2);
        assertEquals(Arrays.asList(new TransactionListener[] { l1 }), Arrays.asList(tm.getListeners()));
        tm.removeListener(l1);
        assertEquals(Arrays.asList(new TransactionListener[] {}), Arrays.asList(tm.getListeners()));
        tm.addListener(l1);
        assertEquals(Arrays.asList(new TransactionListener[] { l1 }), Arrays.asList(tm.getListeners()));
        tm.addListener(l1);
        assertEquals(Arrays.asList(new TransactionListener[] { l1 }), Arrays.asList(tm.getListeners()));
        tm.addListener(l2);
        assertEquals(Arrays.asList(new TransactionListener[] { l1, l2 }), Arrays.asList(tm.getListeners()));
        tm.removeListener(l1);
        assertEquals(Arrays.asList(new TransactionListener[] { l2 }), Arrays.asList(tm.getListeners()));
        tm.removeListener(l1);
        assertEquals(Arrays.asList(new TransactionListener[] { l2 }), Arrays.asList(tm.getListeners()));
        tm.initListeners(new TransactionListener[] { l1, l2 });
        assertEquals(Arrays.asList(new TransactionListener[] { l1, l2 }), Arrays.asList(tm.getListeners()));
    }
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener) CacheTransactionManagerCreation(org.apache.geode.internal.cache.xmlcache.CacheTransactionManagerCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test)

Aggregations

TransactionListener (org.apache.geode.cache.TransactionListener)18 TransactionEvent (org.apache.geode.cache.TransactionEvent)10 Test (org.junit.Test)10 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)7 EntryEvent (org.apache.geode.cache.EntryEvent)6 ArrayList (java.util.ArrayList)5 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)5 Iterator (java.util.Iterator)4 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 Region (org.apache.geode.cache.Region)4 TransactionId (org.apache.geode.cache.TransactionId)4 TransactionListenerAdapter (org.apache.geode.cache.util.TransactionListenerAdapter)4 List (java.util.List)3 CacheException (org.apache.geode.cache.CacheException)3 CacheListener (org.apache.geode.cache.CacheListener)3 CommitConflictException (org.apache.geode.cache.CommitConflictException)3 EntryExistsException (org.apache.geode.cache.EntryExistsException)3 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)3 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)3 NoSuchElementException (java.util.NoSuchElementException)2