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;
}
}
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;
}
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();
}
});
}
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);
}
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()));
}
}
Aggregations