Search in sources :

Example 21 with EntryEvent

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");
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 22 with EntryEvent

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");
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) RegionEvent(org.apache.geode.cache.RegionEvent)

Example 23 with EntryEvent

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);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) Properties(java.util.Properties)

Example 24 with EntryEvent

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());
}
Also used : EntryEvent(org.apache.geode.cache.EntryEvent) Region(org.apache.geode.cache.Region)

Example 25 with EntryEvent

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());
}
Also used : CacheWriterAdapter(org.apache.geode.cache.util.CacheWriterAdapter) MemcachedClient(net.spy.memcached.MemcachedClient) EntryEvent(org.apache.geode.cache.EntryEvent) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) ExecutionException(java.util.concurrent.ExecutionException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Aggregations

EntryEvent (org.apache.geode.cache.EntryEvent)111 AttributesFactory (org.apache.geode.cache.AttributesFactory)75 Region (org.apache.geode.cache.Region)69 Test (org.junit.Test)66 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)55 RegionAttributes (org.apache.geode.cache.RegionAttributes)37 LocalRegion (org.apache.geode.internal.cache.LocalRegion)32 CacheException (org.apache.geode.cache.CacheException)30 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)30 VM (org.apache.geode.test.dunit.VM)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)26 CacheWriterException (org.apache.geode.cache.CacheWriterException)22 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)22 Host (org.apache.geode.test.dunit.Host)21 Properties (java.util.Properties)20 RegionEvent (org.apache.geode.cache.RegionEvent)18 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)17 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)15 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)15 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)15