Search in sources :

Example 56 with CacheCreation

use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.

the class CacheXml66DUnitTest method testPartitionedRegionAttributesForMemLruWithMaxMem.

@Test
public void testPartitionedRegionAttributesForMemLruWithMaxMem() throws Exception {
    final int redundantCopies = 1;
    final int maxMem = 25;
    CacheCreation cache = new CacheCreation();
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setStatisticsEnabled(true);
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundantCopies);
    paf.setTotalMaxMemory(500);
    paf.setLocalMaxMemory(100);
    AttributesFactory fac = new AttributesFactory(attrs);
    fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(maxMem, null, EvictionAction.LOCAL_DESTROY));
    fac.setPartitionAttributes(paf.create());
    cache.createRegion("parRoot", fac.create());
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    Region region = c.getRegion("parRoot");
    assertNotNull(region);
    RegionAttributes regionAttrs = region.getAttributes();
    PartitionAttributes pa = regionAttrs.getPartitionAttributes();
    EvictionAttributes ea = regionAttrs.getEvictionAttributes();
    assertEquals(pa.getRedundantCopies(), 1);
    assertEquals(pa.getLocalMaxMemory(), 100);
    assertEquals(pa.getTotalMaxMemory(), 500);
    assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
    assertEquals(ea.getAction(), EvictionAction.LOCAL_DESTROY);
    assertNotSame(ea.getMaximum(), maxMem);
    assertEquals(ea.getMaximum(), pa.getLocalMaxMemory());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) 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) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 57 with CacheCreation

use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.

the class CacheXml66DUnitTest method testDataPolicy.

@Test
public void testDataPolicy() 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);
    }
    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)

Example 58 with CacheCreation

use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.

the class CacheXml66DUnitTest method testTwoCacheServerGroups.

@Test
public void testTwoCacheServerGroups() throws Exception {
    CacheCreation cache = new CacheCreation();
    CacheServer bs = cache.addCacheServer();
    bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
    String[] groups = new String[] { "group1", "group2" };
    bs.setGroups(groups);
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    CacheServer server = (CacheServer) cache.getCacheServers().iterator().next();
    assertNotNull(server);
    assertEquals(Arrays.asList(groups), Arrays.asList(server.getGroups()));
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 59 with CacheCreation

use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.

the class CacheXml66DUnitTest method testCustomEntryXml.

/**
   * Test both customEntryIdleTime and customEntryTimeToLife
   */
@Test
public void testCustomEntryXml() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
    RegionCreation root = (RegionCreation) cache.createRegion("root", attrs);
    {
        attrs = new RegionAttributesCreation(cache);
        attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
        attrs.setInitialCapacity(142);
        attrs.setLoadFactor(42.42f);
        attrs.setStatisticsEnabled(true);
        attrs.setCustomEntryIdleTimeout(new Expiry1());
        attrs.setCustomEntryTimeToLive(new Expiry5());
        root.createSubregion("one", attrs);
    }
    {
        attrs = new RegionAttributesCreation(cache);
        attrs.setScope(Scope.DISTRIBUTED_ACK);
        attrs.setInitialCapacity(242);
        attrs.setStatisticsEnabled(true);
        attrs.setCustomEntryIdleTimeout(new Expiry2());
        Region region = root.createSubregion("two", attrs);
        {
            attrs = new RegionAttributesCreation(cache);
            attrs.setScope(Scope.DISTRIBUTED_ACK);
            attrs.setLoadFactor(43.43f);
            attrs.setStatisticsEnabled(true);
            attrs.setCustomEntryIdleTimeout(new Expiry3());
            attrs.setCustomEntryTimeToLive(new Expiry4());
            region.createSubregion("three", attrs);
        }
    }
    testXml(cache);
}
Also used : RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) 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) Test(org.junit.Test)

Example 60 with CacheCreation

use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.

the class CacheXml66DUnitTest method testBridgeAttributesRelatedToClientQueuesHA.

/**
   * Tests the bridge-server attributes ({@code maximum-message-count} and
   * {@code message-time-to-live}) related to HA of client-queues in gemfire cache-server framework
   */
@Test
public void testBridgeAttributesRelatedToClientQueuesHA() throws Exception {
    CacheCreation cache = new CacheCreation();
    cache.setMessageSyncInterval(3445);
    CacheServer bs = cache.addCacheServer();
    bs.setMaximumMessageCount(12345);
    bs.setMessageTimeToLive(56789);
    bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setDataPolicy(DataPolicy.NORMAL);
    cache.createVMRegion("rootNORMAL", attrs);
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    CacheServer server = (CacheServer) cache.getCacheServers().iterator().next();
    assertNotNull(server);
    assertEquals(12345, server.getMaximumMessageCount());
    assertEquals(56789, server.getMessageTimeToLive());
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Aggregations

CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)153 Test (org.junit.Test)143 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)114 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)86 Region (org.apache.geode.cache.Region)62 LocalRegion (org.apache.geode.internal.cache.LocalRegion)57 Cache (org.apache.geode.cache.Cache)53 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)53 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)53 ClientCache (org.apache.geode.cache.client.ClientCache)42 RegionAttributes (org.apache.geode.cache.RegionAttributes)35 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)35 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)35 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)25 CacheServer (org.apache.geode.cache.server.CacheServer)17 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)16 File (java.io.File)15 DiskWriteAttributesFactory (org.apache.geode.cache.DiskWriteAttributesFactory)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)9