use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class Bug36853EventsExpiryDUnitTest method createClientCache.
/**
* Creates the client cache
*
* @param hostName the name of the server's machine
* @param port - bridgeserver port
* @throws Exception - thrown if any problem occurs in setting up the client
*/
private static void createClientCache(String hostName, Integer port) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new Bug36853EventsExpiryDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
ClientServerTestCase.configureConnectionPool(factory, hostName, port.intValue(), -1, true, -1, 2, null);
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
String key = (String) event.getKey();
LogWriterUtils.getLogWriter().info("client2 : afterCreate : key =" + key);
if (key.equals(LAST_KEY)) {
synchronized (Bug36853EventsExpiryDUnitTest.class) {
LogWriterUtils.getLogWriter().info("Notifying client2 to proceed for validation");
proceedForValidation = true;
Bug36853EventsExpiryDUnitTest.class.notify();
}
} else {
putsRecievedByClient++;
}
}
});
RegionAttributes attrs = factory.create();
Region region = cache.createRegion(REGION_NAME, attrs);
region.registerInterest("ALL_KEYS");
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class EventIdOptimizationDUnitTest method createClientCache2.
/**
* Creates the client cache2, connected to server3
*
* @param port - bridgeserver port
* @throws Exception - thrown if any problem occurs in setting up the client
*/
public static void createClientCache2(String hostName, Integer port) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new EventIdOptimizationDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
ClientServerTestCase.configureConnectionPool(factory, hostName, port.intValue(), -1, true, -1, 2, null);
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
String key = (String) event.getKey();
validateEventsAtReceivingClientListener(key);
}
public void afterDestroy(EntryEvent event) {
String key = (String) event.getKey();
validateEventsAtReceivingClientListener(key);
}
public void afterRegionDestroy(RegionEvent event) {
validateEventsAtReceivingClientListener(" <destroyRegion Event> ");
}
public void afterRegionClear(RegionEvent event) {
validateEventsAtReceivingClientListener(" <clearRegion Event> ");
}
});
RegionAttributes attrs = factory.create();
Region region = cache.createRegion(REGION_NAME, attrs);
region.registerInterest("ALL_KEYS");
for (int i = 0; i < eventIds.length; i++) {
region = cache.createRegion(REGION_NAME + i, attrs);
region.registerInterest("ALL_KEYS");
}
pool = (PoolImpl) PoolManager.find("testPool");
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class VerifyEventIDGenerationInP2PDUnitTest method createServerCache.
public static void createServerCache() throws Exception {
new VerifyEventIDGenerationInP2PDUnitTest().createCache(new Properties());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setMirrorType(MirrorType.NONE);
factory.setCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
if (!receiver) {
vm0.invoke(() -> VerifyEventIDGenerationInP2PDUnitTest.setEventIDData(((EntryEventImpl) event).getEventId()));
} else {
testEventIDResult = ((EntryEventImpl) event).getEventId().equals(eventId);
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class UpdatePropagationDUnitTest method verifySenderUpdateCount.
private void verifySenderUpdateCount() {
Region r = getCache().getRegion(Region.SEPARATOR + REGION_NAME);
EventTrackingCacheListener listener = (EventTrackingCacheListener) r.getAttributes().getCacheListeners()[0];
final List<EntryEvent> events = listener.receivedEvents;
// We only expect to see 1 create and 1 update from the original put
assertEquals("Expected only 2 events for key1", 2, events.stream().filter(event -> event.getKey().equals("key1")).count());
assertEquals("Expected only 2 events for key2", 2, events.stream().filter(event -> event.getKey().equals("key2")).count());
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class GemcachedBinaryClientJUnitTest method testCacheWriterException.
@SuppressWarnings("unchecked")
public void testCacheWriterException() throws Exception {
MemcachedClient client = createMemcachedClient();
assertTrue(client.set("key", 0, "value".getBytes()).get());
client.set("exceptionkey", 0, "exceptionvalue").get();
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
Region region = cache.getRegion(GemFireMemcachedServer.REGION_NAME);
region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter() {
@Override
public void beforeCreate(EntryEvent event) throws CacheWriterException {
if (event.getKey().equals(KeyWrapper.getWrappedKey("exceptionkey".getBytes()))) {
throw new RuntimeException("ExpectedStrings: Cache writer exception");
}
}
@Override
public void beforeUpdate(EntryEvent event) throws CacheWriterException {
if (event.getKey().equals(KeyWrapper.getWrappedKey("exceptionkey".getBytes()))) {
throw new RuntimeException("ExpectedStrings: Cache writer exception");
}
}
});
long start = System.nanoTime();
try {
client.set("exceptionkey", 0, "exceptionvalue").get();
throw new RuntimeException("expected exception not thrown");
} catch (ExecutionException e) {
// expected
}
assertTrue(client.set("key2", 0, "value2".getBytes()).get());
}
Aggregations