Search in sources :

Example 1 with SubscriptionAttributes

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

the class PRDeltaPropagationDUnitTest method createClientCache.

public static void createClientCache(Integer port1, Boolean subscriptionEnable, Boolean isEmpty, Boolean isCq) throws Exception {
    PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    test.createCache(props);
    lastKeyReceived = false;
    queryUpdateExecuted = false;
    queryDestroyExecuted = false;
    notADeltaInstanceObj = false;
    isFailed = false;
    procced = false;
    numValidCqEvents = 0;
    PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer("localhost", port1).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setConcurrencyChecksEnabled(true);
    if (isEmpty.booleanValue()) {
        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
        factory.setDataPolicy(DataPolicy.EMPTY);
    }
    factory.setPoolName(p.getName());
    factory.setCloningEnabled(false);
    factory.addCacheListener(new CacheListenerAdapter() {

        @Override
        public void afterCreate(EntryEvent event) {
            if (LAST_KEY.equals(event.getKey())) {
                lastKeyReceived = true;
            }
        }
    });
    RegionAttributes attrs = factory.create();
    deltaPR = cache.createRegion(REGION_NAME, attrs);
    if (subscriptionEnable.booleanValue()) {
        deltaPR.registerInterest("ALL_KEYS");
    }
    pool = p;
    if (isCq.booleanValue()) {
        CqAttributesFactory cqf = new CqAttributesFactory();
        CqListenerAdapter cqlist = new CqListenerAdapter() {

            @Override
            @SuppressWarnings("synthetic-access")
            public void onEvent(CqEvent cqEvent) {
                if (LAST_KEY.equals(cqEvent.getKey().toString())) {
                    lastKeyReceived = true;
                } else if (!(cqEvent.getNewValue() instanceof Delta)) {
                    notADeltaInstanceObj = true;
                } else if (cqEvent.getQueryOperation().isUpdate() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
                    queryUpdateExecuted = true;
                } else if (cqEvent.getQueryOperation().isDestroy() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
                    queryDestroyExecuted = true;
                }
                if (forOldNewCQVarification) {
                    if (DELTA_KEY.equals(cqEvent.getKey().toString())) {
                        if (numValidCqEvents == 0 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 8) {
                            procced = true;
                        } else if (procced && numValidCqEvents == 1 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 10) {
                            // this tell us that every thing is fine
                            isFailed = true;
                        }
                    }
                }
                numValidCqEvents++;
            }
        };
        cqf.addCqListener(cqlist);
        CqAttributes cqa = cqf.create();
        CqQuery cq = cache.getQueryService().newCq("CQ_Delta", CQ, cqa);
        cq.execute();
    }
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) DeltaTestImpl(org.apache.geode.DeltaTestImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CqListenerAdapter(org.apache.geode.cache.util.CqListenerAdapter) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CqEvent(org.apache.geode.cache.query.CqEvent) Delta(org.apache.geode.Delta) 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 2 with SubscriptionAttributes

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

the class ClientToServerDeltaDUnitTest method createServerCache.

/*
   * create server cache
   */
public static Integer createServerCache(Boolean attachListener, Boolean isEmpty, Boolean clone, Boolean enableDelta) throws Exception {
    // for validation
    updates = 0;
    create = 0;
    firstUpdate = null;
    secondUpdate = null;
    error = false;
    Properties props = new Properties();
    props.setProperty(DELTA_PROPAGATION, enableDelta.toString());
    new ClientToServerDeltaDUnitTest().createCache(props);
    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.REPLICATE);
    }
    factory.setCloningEnabled(clone);
    RegionAttributes attrs = factory.create();
    region = cache.createRegion(REGION_NAME, attrs);
    AttributesMutator am = region.getAttributesMutator();
    if (attachListener) {
        am.addCacheListener(new CacheListenerAdapter() {

            @Override
            public void afterCreate(EntryEvent event) {
                create++;
            }

            @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;
                }
            }
        });
    } else if (!isEmpty) {
        am.addCacheListener(new CacheListenerAdapter() {

            @Override
            public void afterCreate(EntryEvent event) {
                switch(create) {
                    case 1:
                        validateUpdates(event, firstUpdate, "FIRST");
                        create++;
                        break;
                    case 2:
                        validateUpdates(event, secondUpdate, "SECOND");
                        create++;
                        break;
                    default:
                        create++;
                        break;
                }
            }
        });
    }
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    // ensures updates to be sent instead of invalidations
    server.setNotifyBySubscription(true);
    server.start();
    return new Integer(server.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CacheServer(org.apache.geode.cache.server.CacheServer) Properties(java.util.Properties) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) AttributesMutator(org.apache.geode.cache.AttributesMutator)

Example 3 with SubscriptionAttributes

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

the class PartitionedRegionEvictionDUnitTest method testEntryLRUDeadlock.

/**
   * Test that gets do not need to acquire a lock on the region entry when LRU is enabled. This is
   * bug 42265
   */
@Test
public void testEntryLRUDeadlock() {
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final String uniqName = getUniqueName();
    final int redundantCopies = 0;
    final int maxBuckets = 8;
    final int maxEntries = 16;
    final String name = uniqName + "-PR";
    final int extraEntries = 4;
    // final int heapPercentage = 66;
    // final int evictorInterval = 100;
    final SerializableRunnable create = new CacheSerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {

        public void run2() {
            final AttributesFactory factory = new AttributesFactory();
            factory.setOffHeap(isOffHeap());
            factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setTotalNumBuckets(maxBuckets).create());
            factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY));
            final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
            assertNotNull(pr);
        }
    };
    vm0.invoke(create);
    final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {

        public void run() {
            try {
                final AttributesFactory factory = new AttributesFactory();
                factory.setOffHeap(isOffHeap());
                factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).setTotalNumBuckets(maxBuckets).create());
                factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntries));
                factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
                // this listener will cause a deadlock if the get ends up
                // locking the entry.
                factory.addCacheListener(new CacheListenerAdapter() {

                    @Override
                    public void afterCreate(EntryEvent event) {
                        Region region = event.getRegion();
                        Object key = event.getKey();
                        region.get(key);
                    }
                });
                final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
                assertNotNull(pr);
            } catch (final CacheException ex) {
                Assert.fail("While creating Partitioned region", ex);
            }
        }
    };
    vm1.invoke(create2);
    final SerializableRunnable doPuts = new SerializableRunnable("Do Puts") {

        public void run() {
            final PartitionedRegion pr = (PartitionedRegion) getRootRegion(name);
            assertNotNull(pr);
            for (int counter = 0; counter <= maxEntries + extraEntries; counter++) {
                pr.put(new Integer(counter), "value");
            }
        }
    };
    vm0.invoke(doPuts);
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) Region(org.apache.geode.cache.Region) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with SubscriptionAttributes

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

the class ClientServerForceInvalidateDUnitTest method createClientCache.

public static void createClientCache(String h, int port1, int port2, boolean empty, boolean concurrenctChecksEnabled) throws Exception {
    AbstractRegionMap.FORCE_INVALIDATE_EVENT = true;
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    Cache cache = new ClientServerForceInvalidateDUnitTest().createCacheV(props);
    PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(h, port1).addServer(h, port2).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("ClientServerForceInvalidateDUnitTestPool");
    RegionFactory<String, String> factory = cache.createRegionFactory();
    if (empty) {
        factory.setDataPolicy(DataPolicy.EMPTY);
        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
    } else {
        factory.setDataPolicy(DataPolicy.NORMAL);
    }
    factory.setPoolName(p.getName());
    factory.setConcurrencyChecksEnabled(concurrenctChecksEnabled);
    region1 = factory.create(REGION_NAME1);
    region1.registerInterest("ALL_KEYS", InterestResultPolicy.NONE, false, false);
    region1.getAttributesMutator().addCacheListener(new ClientListener());
    assertNotNull(region1);
    with().pollDelay(1, TimeUnit.MILLISECONDS).pollInterval(1, TimeUnit.SECONDS).await().atMost(60, TimeUnit.SECONDS).until(() -> poolReady(p));
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Cache(org.apache.geode.cache.Cache) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 5 with SubscriptionAttributes

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

the class PartitionedRegionDUnitTest method testRegionInvalidationWithAdjunctMessages.

/**
   * Bug #47235 concerns assertion failures being thrown when there is a member that receives
   * adjunct messages (as in a WAN gateway, a peer with clients, etc).
   */
@Test
public void testRegionInvalidationWithAdjunctMessages() throws Exception {
    final String name = getUniqueName();
    VM vm1 = Host.getHost(0).getVM(1);
    Cache cache = getCache();
    RegionFactory fact = getCache().createRegionFactory(RegionShortcut.PARTITION);
    Region pr = fact.create(name + "Region");
    pr.put("Object1", "Value1");
    vm1.invoke(new SerializableRunnable("create PR") {

        @Override
        public void run() {
            RegionFactory fact = getCache().createRegionFactory(RegionShortcut.PARTITION);
            fact.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
            fact.addCacheListener(new CacheListenerAdapter() {

                @Override
                public void afterInvalidate(EntryEvent event) {
                    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("afterInvalidate invoked with " + event);
                    InvalidateInvoked = true;
                }
            });
            fact.create(name + "Region");
        }
    });
    try {
        pr.invalidateRegion();
        assertTrue("vm1 should have invoked the listener for an invalidateRegion operation", (Boolean) vm1.invoke(new SerializableCallable("getStatus") {

            public Object call() {
                return InvalidateInvoked;
            }
        }));
    } finally {
        disconnectAllFromDS();
    }
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

SubscriptionAttributes (org.apache.geode.cache.SubscriptionAttributes)35 AttributesFactory (org.apache.geode.cache.AttributesFactory)24 Region (org.apache.geode.cache.Region)16 Test (org.junit.Test)15 CacheException (org.apache.geode.cache.CacheException)13 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)12 VM (org.apache.geode.test.dunit.VM)11 EntryEvent (org.apache.geode.cache.EntryEvent)10 Properties (java.util.Properties)9 LocalRegion (org.apache.geode.internal.cache.LocalRegion)9 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)8 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)7 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)7 Host (org.apache.geode.test.dunit.Host)7 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)7 RegionAttributes (org.apache.geode.cache.RegionAttributes)6 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)6 StoredObject (org.apache.geode.internal.offheap.StoredObject)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6