Search in sources :

Example 16 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 17 with SubscriptionAttributes

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

the class ClientRegionFactoryImpl method initAttributeFactoryDefaults.

private void initAttributeFactoryDefaults() {
    this.attrsFactory.setScope(Scope.LOCAL);
    this.attrsFactory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
// this.attrsFactory.setIgnoreJTA(true); in 6.6 and later releases client regions support JTA
}
Also used : SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 18 with SubscriptionAttributes

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

the class CacheXml66DUnitTest method testREPLICATE_HEAP_LRU.

@Test
public void testREPLICATE_HEAP_LRU() throws Exception, IOException {
    CacheCreation cache = new CacheCreation();
    RegionCreation root = (RegionCreation) cache.createRegion("replicatelru", "REPLICATE_HEAP_LRU");
    testXml(cache);
    GemFireCacheImpl c = (GemFireCacheImpl) getCache();
    Region r = c.getRegion("replicatelru");
    assertNotNull(r);
    RegionAttributes ra = r.getAttributes();
    assertEquals(DataPolicy.PRELOADED, ra.getDataPolicy());
    assertEquals(new SubscriptionAttributes(InterestPolicy.ALL), ra.getSubscriptionAttributes());
    assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope());
    assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes());
    assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, c.getResourceManager().getEvictionHeapPercentage(), 0);
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) Test(org.junit.Test)

Example 19 with SubscriptionAttributes

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

the class CachedAllEventsDUnitTest method remoteCreate.

/**
   * make sure a remote create will be done in a NORMAL+ALL region
   * 
   * @param rmtCreate is true if create should happen in remote region
   */
private void remoteCreate(DataPolicy dp, InterestPolicy ip, boolean rmtCreate) throws CacheException {
    initOtherId();
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(dp);
    af.setSubscriptionAttributes(new SubscriptionAttributes(ip));
    af.setScope(Scope.DISTRIBUTED_ACK);
    Region r1 = createRootRegion("r1", af.create());
    assertEquals(false, r1.containsKey("key"));
    doCreateOtherVm();
    if (rmtCreate) {
        assertEquals(true, r1.containsKey("key"));
        assertEquals("value", r1.getEntry("key").getValue());
    } else {
        assertEquals(false, r1.containsKey("key"));
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) Region(org.apache.geode.cache.Region) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 20 with SubscriptionAttributes

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

the class CacheXml66DUnitTest method testPreloadDataPolicy.

@Test
public void testPreloadDataPolicy() throws Exception {
    CacheCreation cache = new CacheCreation();
    {
        RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
        attrs.setDataPolicy(DataPolicy.NORMAL);
        cache.createRegion("rootNORMAL", attrs);
    }
    {
        RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
        attrs.setDataPolicy(DataPolicy.NORMAL);
        attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
        cache.createRegion("rootNORMAL_ALL", attrs);
    }
    {
        RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
        attrs.setMirrorType(MirrorType.KEYS_VALUES);
        cache.createRegion("rootREPLICATE", attrs);
    }
    {
        RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
        attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
        cache.createRegion("rootPERSISTENT_REPLICATE", attrs);
    }
    {
        RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
        attrs.setDataPolicy(DataPolicy.EMPTY);
        cache.createRegion("rootEMPTY", attrs);
    }
    {
        RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
        attrs.setDataPolicy(DataPolicy.EMPTY);
        attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
        cache.createRegion("rootEMPTY_ALL", attrs);
    }
    {
        RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
        attrs.setDataPolicy(DataPolicy.PRELOADED);
        attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
        cache.createRegion("rootPRELOADED_ALL", attrs);
    }
    testXml(cache);
}
Also used : RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) Test(org.junit.Test)

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