Search in sources :

Example 31 with SubscriptionAttributes

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

the class Bug41957DUnitTest method createBridgeClient.

private void createBridgeClient(VM client, final String regionName, final String serverHost, final int[] serverPorts) {
    client.invoke(new CacheSerializableRunnable("Create client") {

        public void run2() throws CacheException {
            // Create DS
            Properties config = new Properties();
            config.setProperty(MCAST_PORT, "0");
            config.setProperty(LOCATORS, "");
            getSystem(config);
            // Create Region
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            {
                PoolFactory pf = PoolManager.createFactory();
                pf.setSubscriptionEnabled(true);
                for (int i = 0; i < serverPorts.length; i++) {
                    pf.addServer(serverHost, serverPorts[i]);
                }
                pf.create("myPool");
            }
            int ENTRIES_ON_CLIENT = 2;
            factory.setPoolName("myPool");
            factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
            factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(ENTRIES_ON_CLIENT));
            createRootRegion(regionName, factory.create());
        }
    });
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 32 with SubscriptionAttributes

use of org.apache.geode.cache.SubscriptionAttributes 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 33 with SubscriptionAttributes

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

the class ForceInvalidateEvictionDUnitTest method createAccessor.

private void createAccessor(VM vm, final boolean allContent) {
    final String name = getUniqueName();
    vm.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            RegionFactory rf = new RegionFactory();
            rf.setOffHeap(isOffHeapEnabled());
            rf.setDataPolicy(DataPolicy.PARTITION);
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            paf.setTotalNumBuckets(5);
            paf.setLocalMaxMemory(0);
            rf.setPartitionAttributes(paf.create());
            rf.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1));
            rf.setConcurrencyChecksEnabled(false);
            if (allContent) {
                // rf.initCacheListeners(new CacheListener [] { new MyListener()});
                rf.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
            }
            rf.create(name);
        }
    });
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Cache(org.apache.geode.cache.Cache) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 34 with SubscriptionAttributes

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

the class RemoteTransactionDUnitTest method createRegion.

void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_ACK);
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    getCache().createRegion(D_REFERENCE, af.create());
    af = new AttributesFactory();
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    if (interestPolicy != null) {
        af.setSubscriptionAttributes(new SubscriptionAttributes(interestPolicy));
    }
    af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(redundantCopies).create());
    getCache().createRegion(CUSTOMER, af.create());
    af.setPartitionAttributes(new PartitionAttributesFactory<OrderId, Order>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(redundantCopies).setColocatedWith(CUSTOMER).create());
    getCache().createRegion(ORDER, af.create());
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 35 with SubscriptionAttributes

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

the class RemoteCQTransactionDUnitTest method createRegion.

void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_ACK);
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    getCache().createRegion(D_REFERENCE, af.create());
    af = new AttributesFactory();
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    if (interestPolicy != null) {
        af.setSubscriptionAttributes(new SubscriptionAttributes(interestPolicy));
    }
    af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(redundantCopies).create());
    getCache().createRegion(CUSTOMER, af.create());
    af.setPartitionAttributes(new PartitionAttributesFactory<OrderId, Order>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(redundantCopies).setColocatedWith(CUSTOMER).create());
    getCache().createRegion(ORDER, af.create());
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

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