Search in sources :

Example 6 with EvictionAttributes

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

the class RegionStatus method initialize.

private void initialize(Region region) {
    setNumberOfEntries(region.size());
    EvictionAttributes ea = region.getAttributes().getEvictionAttributes();
    if (ea != null && ea.getAlgorithm().isLRUMemory()) {
        LocalRegion lr = (LocalRegion) region;
        LRUStatistics stats = ((AbstractLRURegionMap) lr.getRegionMap())._getLruList().stats();
        setHeapSize(stats.getCounter());
    } else {
        setHeapSize(-1);
    }
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics)

Example 7 with EvictionAttributes

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

the class CacheXml66DUnitTest method testPartitionedRegionAttributesForEviction.

/**
   * Tests that a Partitioned Region can be created with a named attributes set programmatically for
   * ExpirationAttributes
   */
@Test
public void testPartitionedRegionAttributesForEviction() throws Exception {
    final int redundantCopies = 1;
    CacheCreation cache = new CacheCreation();
    if (getGemFireVersion().equals(CacheXml.VERSION_6_0)) {
        ResourceManagerCreation rm = new ResourceManagerCreation();
        rm.setCriticalHeapPercentage(95);
        cache.setResourceManagerCreation(rm);
    }
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setStatisticsEnabled(true);
    RegionAttributes rootAttrs = null;
    ExpirationAttributes expiration = new ExpirationAttributes(60, ExpirationAction.DESTROY);
    CacheXMLPartitionResolver partitionResolver = new CacheXMLPartitionResolver();
    Properties params = new Properties();
    params.setProperty("initial-index-value", "1000");
    params.setProperty("secondary-index-value", "5000");
    partitionResolver.init(params);
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundantCopies);
    paf.setTotalMaxMemory(500);
    paf.setLocalMaxMemory(100);
    paf.setPartitionResolver(partitionResolver);
    AttributesFactory fac = new AttributesFactory(attrs);
    // TODO: Move test back to using LRUHeap when config issues have settled
    // if (getGemFireVersion().equals(CacheXml.GEMFIRE_6_0)) {
    // fac.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(null,
    // EvictionAction.OVERFLOW_TO_DISK));
    // } else {
    fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
    // }
    fac.setEntryTimeToLive(expiration);
    fac.setEntryIdleTimeout(expiration);
    DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
    dwaf.setSynchronous(true);
    fac.setPartitionAttributes(paf.create());
    rootAttrs = fac.create();
    cache.createRegion("parRoot", rootAttrs);
    Region r = cache.getRegion("parRoot");
    assertNotNull(r);
    assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(), redundantCopies);
    assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(), 100);
    assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(), 500);
    assertEquals(r.getAttributes().getPartitionAttributes().getPartitionResolver(), partitionResolver);
    assertEquals(r.getAttributes().getEntryIdleTimeout().getTimeout(), expiration.getTimeout());
    assertEquals(r.getAttributes().getEntryTimeToLive().getTimeout(), expiration.getTimeout());
    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);
    assertNotNull(pa.getPartitionResolver().getClass());
    assertEquals(pa.getPartitionResolver(), partitionResolver);
    assertEquals(regionAttrs.getEntryIdleTimeout().getTimeout(), expiration.getTimeout());
    assertEquals(regionAttrs.getEntryTimeToLive().getTimeout(), expiration.getTimeout());
    // TODO: Move test back to using LRUHeap when config issues have settled
    // if (getGemFireVersion().equals(CacheXml.GEMFIRE_6_0)) {
    // assertIndexDetailsEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_HEAP);
    // } else {
    assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
    // }
    assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ResourceManagerCreation(org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation) Properties(java.util.Properties) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) 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) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 8 with EvictionAttributes

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

the class CacheXml66DUnitTest method testPartitionedRegionAttributesForMemLruWithoutMaxMem.

@Test
public void testPartitionedRegionAttributesForMemLruWithoutMaxMem() throws Exception {
    final int redundantCopies = 1;
    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(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);
    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 9 with EvictionAttributes

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

the class DeltaPropagationDUnitTest method testS2CWithLocallyDestroyedOldValueAtClient.

@Test
public void testS2CWithLocallyDestroyedOldValueAtClient() throws Exception {
    PORT1 = ((Integer) VM0.invoke(() -> DeltaPropagationDUnitTest.createServerCache(HARegionQueue.HA_EVICTION_POLICY_MEMORY))).intValue();
    EvictionAttributes evAttr = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.LOCAL_DESTROY);
    createClientCache(new Integer(PORT1), new Integer(-1), "0", Boolean.TRUE, /* add listener */
    evAttr);
    registerInterestListAll();
    VM0.invoke(() -> DeltaPropagationDUnitTest.prepareDeltas());
    prepareDeltas();
    VM0.invoke(() -> DeltaPropagationDUnitTest.createDelta());
    VM0.invoke(() -> DeltaPropagationDUnitTest.createAnEntry());
    // TODO: Find a better 'n reliable alternative
    Thread.sleep(5000);
    // assert overflow occurred on client vm
    verifyOverflowOccurred(1L, 1);
    VM0.invoke(() -> DeltaPropagationDUnitTest.updateDelta());
    waitForLastKey();
    long toDeltas = ((Long) VM0.invoke(() -> DeltaTestImpl.getToDeltaInvokations())).longValue();
    long fromDeltas = DeltaTestImpl.getFromDeltaInvokations().longValue();
    assertTrue((EVENTS_SIZE - 1) + " deltas were to be sent but were " + toDeltas, toDeltas == (EVENTS_SIZE - 1));
    assertTrue((EVENTS_SIZE - 1 - 1) + " deltas were to be received but were " + fromDeltas, fromDeltas == (EVENTS_SIZE - 1 - 1));
    verifyData(4, EVENTS_SIZE - 2);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ConflationDUnitTest(org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest) Test(org.junit.Test)

Example 10 with EvictionAttributes

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

the class DescribeDiskStoreFunctionJUnitTest method setupRegionsForTestExecute.

private Set<DiskStoreDetails.RegionDetails> setupRegionsForTestExecute(final InternalCache mockCache, final String diskStoreName) {
    final Region mockUserRegion = mockContext.mock(Region.class, "/UserRegion");
    final Region mockSessionRegion = mockContext.mock(Region.class, "/UserRegion/SessionRegion");
    final Region mockGuestRegion = mockContext.mock(Region.class, "/GuestRegion");
    final RegionAttributes mockUserRegionAttributes = mockContext.mock(RegionAttributes.class, "UserRegionAttributes");
    final RegionAttributes mockSessionRegionAttributes = mockContext.mock(RegionAttributes.class, "SessionRegionAttributes");
    final RegionAttributes mockGuestRegionAttributes = mockContext.mock(RegionAttributes.class, "GuestRegionAttributes");
    final EvictionAttributes mockUserEvictionAttributes = mockContext.mock(EvictionAttributes.class, "UserEvictionAttributes");
    final EvictionAttributes mockSessionEvictionAttributes = mockContext.mock(EvictionAttributes.class, "SessionEvictionAttributes");
    final EvictionAttributes mockGuestEvictionAttributes = mockContext.mock(EvictionAttributes.class, "GuestEvictionAttributes");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).rootRegions();
            will(returnValue(CollectionUtils.asSet(mockUserRegion, mockGuestRegion)));
            exactly(5).of(mockUserRegion).getAttributes();
            will(returnValue(mockUserRegionAttributes));
            oneOf(mockUserRegion).getFullPath();
            will(returnValue("/UserRegion"));
            oneOf(mockUserRegion).getName();
            will(returnValue("UserRegion"));
            oneOf(mockUserRegion).subregions(false);
            will(returnValue(CollectionUtils.asSet(mockSessionRegion)));
            exactly(2).of(mockUserRegionAttributes).getDataPolicy();
            will(returnValue(DataPolicy.PERSISTENT_PARTITION));
            oneOf(mockUserRegionAttributes).getDiskStoreName();
            will(returnValue(diskStoreName));
            exactly(2).of(mockUserRegionAttributes).getEvictionAttributes();
            will(returnValue(mockUserEvictionAttributes));
            oneOf(mockUserEvictionAttributes).getAction();
            will(returnValue(EvictionAction.LOCAL_DESTROY));
            exactly(7).of(mockSessionRegion).getAttributes();
            will(returnValue(mockSessionRegionAttributes));
            oneOf(mockSessionRegion).getFullPath();
            will(returnValue("/UserRegion/SessionRegion"));
            oneOf(mockSessionRegion).getName();
            will(returnValue("SessionRegion"));
            oneOf(mockSessionRegion).subregions(false);
            will(returnValue(Collections.emptySet()));
            exactly(2).of(mockSessionRegionAttributes).getDataPolicy();
            will(returnValue(DataPolicy.REPLICATE));
            oneOf(mockSessionRegionAttributes).getDiskStoreName();
            will(returnValue(diskStoreName));
            exactly(4).of(mockSessionRegionAttributes).getEvictionAttributes();
            will(returnValue(mockSessionEvictionAttributes));
            exactly(2).of(mockSessionEvictionAttributes).getAction();
            will(returnValue(EvictionAction.OVERFLOW_TO_DISK));
            exactly(4).of(mockGuestRegion).getAttributes();
            will(returnValue(mockGuestRegionAttributes));
            oneOf(mockGuestRegion).subregions(false);
            will(returnValue(Collections.emptySet()));
            oneOf(mockGuestRegionAttributes).getDataPolicy();
            will(returnValue(DataPolicy.REPLICATE));
            oneOf(mockGuestRegionAttributes).getDiskStoreName();
            will(returnValue(DiskStoreDetails.DEFAULT_DISK_STORE_NAME));
            exactly(2).of(mockGuestRegionAttributes).getEvictionAttributes();
            will(returnValue(mockGuestEvictionAttributes));
            oneOf(mockGuestEvictionAttributes).getAction();
            will(returnValue(EvictionAction.OVERFLOW_TO_DISK));
        }
    });
    return CollectionUtils.asSet(createRegionDetails("/UserRegion", "UserRegion", true, false), createRegionDetails("/UserRegion/SessionRegion", "SessionRegion", false, true));
}
Also used : Expectations(org.jmock.Expectations) EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region)

Aggregations

EvictionAttributes (org.apache.geode.cache.EvictionAttributes)41 AttributesFactory (org.apache.geode.cache.AttributesFactory)25 Region (org.apache.geode.cache.Region)24 Test (org.junit.Test)24 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)21 RegionAttributes (org.apache.geode.cache.RegionAttributes)17 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)12 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)11 Host (org.apache.geode.test.dunit.Host)10 VM (org.apache.geode.test.dunit.VM)10 Cache (org.apache.geode.cache.Cache)9 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 DiskWriteAttributesFactory (org.apache.geode.cache.DiskWriteAttributesFactory)7 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)6 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)6 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)6 File (java.io.File)5