use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class CacheListenerTestCase method testCacheListenerAfterDestroy.
/**
* Tests that the <code>CacheListener</code> is called after an entry is
* {@linkplain CacheListener#afterDestroy destroyed}.
*/
@Test
public void testCacheListenerAfterDestroy() throws CacheException {
String name = this.getUniqueName();
final Object key = this.getUniqueName();
final Object value = new Integer(42);
Object arg = "ARG";
// final boolean localScope = getRegionAttributes().getScope().isLocal();
TestCacheListener listener = new TestCacheListener() {
public void afterCreate2(EntryEvent event) {
// This method will get invoked when the region is populated
}
public void afterDestroy2(EntryEvent event) {
assertEquals(key, event.getKey());
assertEquals(value, event.getOldValue());
assertNull(event.getNewValue());
verifyEventProps(event);
}
};
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setCacheListener(listener);
Region region = createRegion(name, factory.create());
region.create(key, value);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
region.create(key, value);
assertTrue(listener.wasInvoked());
region.destroy(key, arg);
assertTrue(listener.wasInvoked());
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class CacheListenerTestCase method testCacheListenerAfterCreate.
/////////////////////// Test Methods ///////////////////////
/**
* Tests that the <code>CacheListener</code> is called after an entry is
* {@linkplain CacheListener#afterCreate created}.
*/
@Test
public void testCacheListenerAfterCreate() throws CacheException {
String name = this.getUniqueName();
final Object key = this.getUniqueName();
final Object value = new Integer(42);
Object arg = "ARG";
TestCacheListener listener = new TestCacheListener() {
public void afterCreate2(EntryEvent event) {
assertEquals(key, event.getKey());
assertEquals(value, event.getNewValue());
assertNull(event.getOldValue());
verifyEventProps(event);
}
public void afterDestroy2(EntryEvent event) {
// This method will get invoked when the entry is destroyed
}
};
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setCacheListener(listener);
Region region = createRegion(name, factory.create());
region.create(key, value);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
region.put(key, value);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
region.create(key, value, arg);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
region.put(key, value, arg);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class CacheListenerTestCase method testCacheListenerAfterUpdate.
/**
* Tests that the <code>CacheListener</code> is called after an entry is
* {@linkplain CacheListener#afterUpdate updated}.
*/
@Test
public void testCacheListenerAfterUpdate() throws CacheException {
String name = this.getUniqueName();
final Object key = this.getUniqueName();
final Object oldValue = new Integer(42);
final Object newValue = new Integer(43);
Object arg = "ARG";
TestCacheListener listener = new TestCacheListener() {
public void afterCreate2(EntryEvent event) {
// This method will get invoked when the region is populated
}
public void afterDestroy2(EntryEvent event) {
// This method will get invoked when an entry is destroyed
}
public void afterUpdate2(EntryEvent event) {
assertEquals(key, event.getKey());
assertEquals(newValue, event.getNewValue());
assertEquals(oldValue, event.getOldValue());
verifyEventProps(event);
}
};
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setCacheListener(listener);
Region region = createRegion(name, factory.create());
region.create(key, oldValue);
assertTrue(listener.wasInvoked());
region.put(key, newValue);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
region.put(key, oldValue);
assertTrue(listener.wasInvoked());
region.put(key, newValue);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
region.create(key, oldValue);
assertTrue(listener.wasInvoked());
region.put(key, newValue, arg);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
region.put(key, oldValue);
assertTrue(listener.wasInvoked());
region.put(key, newValue, arg);
assertTrue(listener.wasInvoked());
region.destroy(key);
assertTrue(listener.wasInvoked());
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class CacheLoaderTestCase method testCacheListenerOnLoad.
/**
* Tests that a <code>CacheListener</code> gets invoked on a <code>load</code>.
*/
@Test
public void testCacheListenerOnLoad() throws CacheException, InterruptedException {
final String name = this.getUniqueName();
final Object key = this.getUniqueName();
final Object oldValue = new Integer(42);
final Object newValue = new Integer(43);
TestCacheLoader loader = new TestCacheLoader() {
public Object load2(LoaderHelper helper) throws CacheLoaderException {
return oldValue;
}
};
TestCacheListener listener = new TestCacheListener() {
public void afterCreate2(EntryEvent event) {
assertEquals(oldValue, event.getNewValue());
assertTrue(event.getOperation().isLoad());
assertTrue(event.getOperation().isLocalLoad());
assertFalse(event.getOperation().isNetLoad());
assertFalse(event.getOperation().isNetSearch());
}
};
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setCacheLoader(loader);
factory.setCacheListener(listener);
Region region = createRegion(name, factory.create());
loader.wasInvoked();
assertEquals(oldValue, region.get(key));
assertTrue(loader.wasInvoked());
Wait.pause(500);
assertTrue(listener.wasInvoked());
listener = new TestCacheListener() {
public void afterUpdate2(EntryEvent event) {
assertEquals(oldValue, event.getOldValue());
assertEquals(newValue, event.getNewValue());
assertFalse(event.getOperation().isLoad());
assertFalse(event.getOperation().isLocalLoad());
assertFalse(event.getOperation().isNetLoad());
assertFalse(event.getOperation().isNetSearch());
}
};
region.getAttributesMutator().setCacheListener(listener);
region.put(key, newValue);
Wait.pause(500);
assertFalse(loader.wasInvoked());
assertTrue(listener.wasInvoked());
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class Bug34387DUnitTest method testCreateAndLD.
////////////////////// Test Methods //////////////////////
/**
* test create followed by localDestroy
*/
@Test
public void testCreateAndLD() throws CacheException {
initOtherId();
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setConcurrencyChecksEnabled(true);
callbackFailure = false;
CacheListener cl1 = new CacheListenerAdapter() {
public void afterCreate(EntryEvent e) {
callbackAssertEquals("Keys not equal", "createKey", e.getKey());
callbackAssertEquals("Values not equal", "createValue", e.getNewValue());
Bug34387DUnitTest.this.invokeCount++;
}
};
af.addCacheListener(cl1);
Region r1 = createRootRegion("r1", af.create());
this.invokeCount = 0;
assertNull(r1.getEntry("createKey"));
doCommitOtherVm(true);
assertNotNull(r1.getEntry("createKey"));
assertEquals("createValue", r1.getEntry("createKey").getValue());
assertEquals(1, this.invokeCount);
assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
Aggregations