use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class CallbackArgDUnitTest method doTest.
private void doTest() 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());
assertEquals(callbackArg, e.getCallbackArgument());
assertEquals(true, e.isCallbackArgumentAvailable());
}
};
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(callbackArg, ee.getCallbackArgument());
assertEquals(true, ee.isCallbackArgumentAvailable());
}
assertEquals(CallbackArgDUnitTest.this.expectedKeys, keys);
CallbackArgDUnitTest.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);
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class DistributionManagerDUnitTest method getSleepingListener.
static CacheListener getSleepingListener(final boolean playDead) {
regionDestroyedInvoked = false;
return new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
try {
if (playDead) {
MembershipManagerHelper.beSickMember(getSystemStatic());
MembershipManagerHelper.playDead(getSystemStatic());
}
Thread.sleep(15000);
} catch (InterruptedException ie) {
fail("interrupted", ie);
}
}
@Override
public void afterRegionDestroy(RegionEvent event) {
LogWriter logger = myCache.getLogger();
logger.info("afterRegionDestroyed invoked in sleeping listener");
logger.info("<ExpectedException action=remove>service failure</ExpectedException>");
logger.info("<ExpectedException action=remove>org.apache.geode.ForcedDisconnectException</ExpectedException>");
regionDestroyedInvoked = true;
}
};
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class LRUEvictionControllerDUnitTest method testBug31592.
/**
* Tests that a Region with an LRU capacity controller can be accessed from inside a cache
* listener.
*/
@Test
public void testBug31592() throws Exception {
final String name = this.getUniqueName();
final Object key = "KEY";
final Object value = "VALUE";
final Object key2 = "KEY2";
final Object value2 = "VALUE2";
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeapEnabled());
factory.setScope(Scope.LOCAL);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(10));
final Region region = createRegion(name, factory.create());
region.put(key, value);
final Throwable[] errors = new Throwable[1];
region.getAttributesMutator().addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
try {
LogWriterUtils.getLogWriter().info("AFTER CREATE");
region.put(key, value2);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable ex) {
region.getCache().getLogger().severe("failed to access cache from listener", ex);
errors[0] = ex;
}
}
});
region.put(key2, value2);
assertNull(errors[0]);
assertEquals(value2, region.get(key));
assertEquals(value2, region.get(key2));
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class LocalRegionDUnitTest method testLocalCreateModifiedCallbackArgument.
/**
* Tests that a local writer receives a modified version of the callback argument on a create.
*/
@Test
public void testLocalCreateModifiedCallbackArgument() throws CacheException {
final String name = this.getUniqueName();
final Object key = "KEY";
final Object value = "VALUE";
final Object one = "ONE";
final Object two = "TWO";
TestCacheLoader loader = new TestCacheLoader() {
public Object load2(LoaderHelper helper) throws CacheLoaderException {
Object[] array = (Object[]) helper.getArgument();
assertEquals(one, array[0]);
array[0] = two;
return value;
}
};
TestCacheWriter writer = new TestCacheWriter() {
public void beforeCreate2(EntryEvent event) throws CacheWriterException {
Object[] array = (Object[]) event.getCallbackArgument();
assertEquals(two, array[0]);
}
};
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setCacheLoader(loader);
factory.setCacheWriter(writer);
Region region = createRegion(name, factory.create());
Object[] array = new Object[] { one };
assertEquals(value, region.get(key, array));
assertTrue(loader.wasInvoked());
assertTrue(writer.wasInvoked());
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class DistributedNoAckRegionCCEDUnitTest method addBlockingListener.
static void addBlockingListener() {
ListenerBlocking = true;
CCRegion.getAttributesMutator().addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
onEvent(event);
}
private void onEvent(EntryEvent event) {
boolean blocked = false;
if (event.isOriginRemote()) {
synchronized (this) {
while (ListenerBlocking) {
LogWriterUtils.getLogWriter().info("blocking cache operations for " + event.getDistributedMember());
blocked = true;
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LogWriterUtils.getLogWriter().info("blocking cache listener interrupted");
return;
}
}
}
if (blocked) {
LogWriterUtils.getLogWriter().info("allowing cache operations for " + event.getDistributedMember());
}
}
}
@Override
public void close() {
LogWriterUtils.getLogWriter().info("closing blocking listener");
ListenerBlocking = false;
synchronized (this) {
notifyAll();
}
}
@Override
public void afterUpdate(EntryEvent event) {
onEvent(event);
}
@Override
public void afterInvalidate(EntryEvent event) {
onEvent(event);
}
@Override
public void afterDestroy(EntryEvent event) {
onEvent(event);
}
});
}
Aggregations