Search in sources :

Example 66 with EntryEvent

use of org.apache.geode.cache.EntryEvent in project geode by apache.

the class ExportLogsCacheWriterUnitTest method writerReturnsPathIfWritten.

@Test
public void writerReturnsPathIfWritten() throws Exception {
    writer.startFile("server-1");
    EntryEvent event = mock(EntryEvent.class);
    when(event.getNewValue()).thenReturn(new byte[] {});
    writer.beforeCreate(event);
    assertThat(writer.endFile()).isNotNull();
}
Also used : EntryEvent(org.apache.geode.cache.EntryEvent) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 67 with EntryEvent

use of org.apache.geode.cache.EntryEvent in project geode by apache.

the class ClientToServerDeltaDUnitTest method createClientCache.

/*
   * create client cache
   */
public static void createClientCache(String host, Integer port, Boolean attachListener, Boolean isEmpty, Boolean isCq, String[] cqQueryString, Boolean registerInterestAll, Boolean enableSubscription) throws Exception {
    updates = 0;
    create = 0;
    firstUpdate = null;
    secondUpdate = null;
    error = false;
    lastKeyReceived = false;
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new ClientToServerDeltaDUnitTest().createCache(props);
    pool = (PoolImpl) PoolManager.createFactory().addServer(host, port.intValue()).setThreadLocalConnections(true).setMinConnections(2).setSubscriptionEnabled(enableSubscription).setSubscriptionRedundancy(0).setReadTimeout(10000).setPingInterval(1000).setSocketBufferSize(32768).create("ClientToServerDeltaDunitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setConcurrencyChecksEnabled(true);
    if (isEmpty) {
        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
        factory.setDataPolicy(DataPolicy.EMPTY);
    } else {
        factory.setDataPolicy(DataPolicy.NORMAL);
    }
    factory.setPoolName(pool.getName());
    factory.setCloningEnabled(false);
    // region with empty data policy
    RegionAttributes attrs = factory.create();
    region = cache.createRegion(REGION_NAME, attrs);
    if (attachListener) {
        region.getAttributesMutator().addCacheListener(new CacheListenerAdapter() {

            @Override
            public void afterCreate(EntryEvent event) {
                create++;
                if (LAST_KEY.equals(event.getKey())) {
                    lastKeyReceived = true;
                }
                ;
            }

            @Override
            public void afterUpdate(EntryEvent event) {
                switch(updates) {
                    case 0:
                        // first delta
                        validateUpdates(event, firstUpdate, "FIRST");
                        updates++;
                        break;
                    case 1:
                        // combine delta
                        validateUpdates(event, firstUpdate, "FIRST");
                        validateUpdates(event, secondUpdate, "SECOND");
                        updates++;
                        break;
                    default:
                        break;
                }
            }
        });
    }
    if (registerInterestAll) {
        region.registerInterest("ALL_KEYS");
    }
    if (isCq) {
        CqAttributesFactory cqf = new CqAttributesFactory();
        CqListenerAdapter cqlist = new CqListenerAdapter() {

            @Override
            public void onEvent(CqEvent cqEvent) {
                Object key = cqEvent.getKey();
                if (LAST_KEY.equals(key)) {
                    lastKeyReceived = true;
                }
                logger.fine("CQ event received for (key, value): (" + key + ", " + cqEvent.getNewValue() + ")");
            }

            @Override
            public void onError(CqEvent cqEvent) {
                logger.fine("CQ error received for key: " + cqEvent.getKey());
            }
        };
        cqf.addCqListener(cqlist);
        CqAttributes cqa = cqf.create();
        for (int i = 0; i < cqQueryString.length; i++) {
            CqQuery cq = cache.getQueryService().newCq("Delta_Query_" + i, cqQueryString[i], cqa);
            cq.execute();
        }
    }
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) Properties(java.util.Properties) CqListenerAdapter(org.apache.geode.cache.util.CqListenerAdapter) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CqEvent(org.apache.geode.cache.query.CqEvent) CqAttributes(org.apache.geode.cache.query.CqAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 68 with EntryEvent

use of org.apache.geode.cache.EntryEvent in project geode by apache.

the class P2PDeltaPropagationDUnitTest method createServerCache.

public static void createServerCache(Boolean flag, DataPolicy policy, Scope scope, Boolean listener, Boolean interestPolicyAll, Integer port) throws Exception {
    P2PDeltaPropagationDUnitTest test = new P2PDeltaPropagationDUnitTest();
    Properties props = new Properties();
    if (!flag) {
        props.setProperty(DELTA_PROPAGATION, "false");
    }
    cache = test.createCache(props);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(scope);
    factory.setDataPolicy(policy);
    if (policy == DataPolicy.EMPTY && interestPolicyAll) {
        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
    }
    if (listener) {
        factory.addCacheListener(new CacheListenerAdapter() {

            @SuppressWarnings("synthetic-access")
            public void afterUpdate(EntryEvent event) {
                numOfUpdates++;
                cache.getLoggerI18n().fine("afterUpdate(): numOfUpdates = " + numOfUpdates);
                cache.getLoggerI18n().fine("(key, val): " + event.getKey() + ", " + event.getNewValue());
                if (event.getOldValue() != null) {
                    if (event.getOldValue() == event.getNewValue()) {
                        check = Boolean.TRUE;
                    }
                }
                if (((EntryEventImpl) event).getDeltaBytes() != null) {
                    cache.getLoggerI18n().fine("delta bytes received. " + hasDeltaBytes);
                    assertTrue("No full value received for event " + event, ((EntryEventImpl) event).getNewValue() != null);
                    hasDeltaBytes++;
                } else {
                    cache.getLoggerI18n().fine("delta bytes not received.");
                }
            }
        });
    }
    Region region = cache.createRegion(REGION_NAME, factory.create());
    if (!policy.isReplicate()) {
        region.create("KEY", "KEY");
    }
    if (port != null) {
        CacheServer server1 = cache.addCacheServer();
        server1.setPort(port);
        server1.start();
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 69 with EntryEvent

use of org.apache.geode.cache.EntryEvent in project geode by apache.

the class HARegionJUnitTest method testEventIdSetForEvictDestroy.

/**
   * Test to verify event id exists when evict destroy happens.
   */
@Test
public void testEventIdSetForEvictDestroy() throws Exception {
    AttributesFactory factory = new AttributesFactory();
    factory.setCacheListener(new CacheListenerAdapter() {

        public void afterDestroy(EntryEvent event) {
            assertTrue("eventId has not been set for " + event, ((EntryEventImpl) event).getEventId() != null);
        }
    });
    EvictionAttributes evAttr = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.LOCAL_DESTROY);
    factory.setEvictionAttributes(evAttr);
    RegionAttributes attrs = factory.createRegionAttributes();
    Region region = cache.createVMRegion("TEST_REGION", attrs);
    region.put("key1", "value1");
    region.put("key2", "value2");
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) 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) HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 70 with EntryEvent

use of org.apache.geode.cache.EntryEvent in project geode by apache.

the class HARQueueNewImplDUnitTest method createClientCache.

public static void createClientCache(String host, Integer port1, Integer port2, String rLevel, Boolean addListener) throws Exception {
    CacheServerTestUtil.disableShufflingOfEndpoints();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new HARQueueNewImplDUnitTest().createCache(props);
    AttributesFactory factory = new AttributesFactory();
    ClientServerTestCase.configureConnectionPool(factory, host, port1.intValue(), port2.intValue(), true, Integer.parseInt(rLevel), 2, null, 1000, 250, false);
    factory.setScope(Scope.LOCAL);
    if (addListener.booleanValue()) {
        factory.addCacheListener(new CacheListenerAdapter() {

            public void afterInvalidate(EntryEvent event) {
                logger.fine("Invalidate Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
                numOfInvalidates++;
            }

            public void afterCreate(EntryEvent event) {
                logger.fine("Create Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
                numOfCreates++;
            }

            public void afterUpdate(EntryEvent event) {
                logger.fine("Update Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
                numOfUpdates++;
            }
        });
    }
    RegionAttributes attrs = factory.create();
    cache.createRegion(regionName, attrs);
    logger = cache.getLogger();
}
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) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

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