Search in sources :

Example 11 with LRUStatistics

use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.

the class RegionManagementDUnitTest method createDiskRegion.

private void createDiskRegion(final VM memberVM) {
    memberVM.invoke("createDiskRegion", () -> {
        AttributesFactory factory = new AttributesFactory();
        factory.setScope(Scope.LOCAL);
        factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(20, new TestObjectSizerImpl(), EvictionAction.LOCAL_DESTROY));
        Region region = getCache_tmp().createRegion(REGION_NAME, factory.create());
        LRUStatistics lruStats = ((AbstractRegion) region).getEvictionController().getLRUHelper().getStats();
        assertThat(lruStats).isNotNull();
        RegionMXBean regionMXBean = getManagementService_tmp().getLocalRegionMBean(REGION_PATH);
        assertThat(regionMXBean).isNotNull();
        int total;
        for (total = 0; total < 100; total++) {
            // TODO: why so many?
            int[] array = new int[250];
            array[0] = total;
            region.put(new Integer(total), array);
        }
        assertThat(regionMXBean.getEntrySize()).isGreaterThan(0);
    });
}
Also used : TestObjectSizerImpl(org.apache.geode.internal.cache.TestObjectSizerImpl) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) Region(org.apache.geode.cache.Region) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion)

Example 12 with LRUStatistics

use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.

the class LRUEvictionControllerDUnitTest method testRegionOperations.

//////// Test Methods
/**
   * Carefully verifies that region operations effect the {@link LRUStatistics} as expected.
   */
@Test
public void testRegionOperations() throws CacheException {
    int threshold = 10;
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(threshold));
    Region region;
    if (usingMain) {
        DistributedSystem system = DistributedSystem.connect(new Properties());
        Cache cache = CacheFactory.create(system);
        region = cache.createRegion("Test", factory.create());
    } else {
        region = createRegion(name, factory.create());
    }
    LRUStatistics lruStats = getLRUStats(region);
    assertNotNull(lruStats);
    for (int i = 1; i <= 10; i++) {
        Object key = new Integer(i);
        Object value = String.valueOf(i);
        region.put(key, value);
        assertEquals(i, lruStats.getCounter());
        assertEquals(0, lruStats.getEvictions());
    }
    for (int i = 11; i <= 20; i++) {
        Object key = new Integer(i);
        Object value = String.valueOf(i);
        region.put(key, value);
        assertEquals(10, lruStats.getCounter());
        assertEquals(i - 10, lruStats.getEvictions());
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 13 with LRUStatistics

use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.

the class LRUEvictionControllerDUnitTest method testSizeOne.

/**
   * Tests an <code>LRUCapacityController</code> of size 1.
   */
@Test
public void testSizeOne() throws CacheException {
    int threshold = 1;
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setOffHeap(isOffHeapEnabled());
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(threshold));
    factory.setCacheLoader(new CacheLoader() {

        public Object load(LoaderHelper helper) throws CacheLoaderException {
            return "LOADED VALUE";
        }

        public void close() {
        }
    });
    Region region;
    if (usingMain) {
        DistributedSystem system = DistributedSystem.connect(new Properties());
        Cache cache = CacheFactory.create(system);
        region = cache.createRegion("Test", factory.create());
    } else {
        region = createRegion(name, factory.create());
    }
    LRUStatistics lruStats = getLRUStats(region);
    assertNotNull(lruStats);
    for (int i = 1; i <= 1; i++) {
        Object key = new Integer(i);
        Object value = String.valueOf(i);
        region.put(key, value);
        assertEquals(1, lruStats.getCounter());
        assertEquals(0, lruStats.getEvictions());
    }
    for (int i = 2; i <= 10; i++) {
        Object key = new Integer(i);
        Object value = String.valueOf(i);
        region.put(key, value);
        assertEquals(1, lruStats.getCounter());
        assertEquals(i - 1, lruStats.getEvictions());
    }
    for (int i = 11; i <= 20; i++) {
        Object key = new Integer(i);
        // Object value = String.valueOf(i);
        // Invoke loader
        region.get(key);
        assertEquals(1, lruStats.getCounter());
        assertEquals(i - 1, lruStats.getEvictions());
    }
}
Also used : Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 14 with LRUStatistics

use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.

the class MemLRUEvictionControllerDUnitTest method testRegionOperations.

// ////// Test Methods
/**
   * Carefully verifies that region operations effect the {@link LRUStatistics} as expected.
   */
@Test
public void testRegionOperations() throws CacheException {
    int threshold = 4;
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(threshold));
    Region region;
    if (usingMain) {
        DistributedSystem system = DistributedSystem.connect(new Properties());
        Cache cache = CacheFactory.create(system);
        region = cache.createRegion("Test", factory.create());
    } else {
        region = createRegion(name, factory.create());
    }
    LRUStatistics lruStats = getLRUStats(region);
    assertNotNull(lruStats);
    String sampleKey = new String("10000");
    int stringSize = // String object
    SharedLibrary.getObjectHeaderSize() + (2 * 4) + // 2 ints and a reference on a string
    SharedLibrary.getReferenceSize();
    stringSize = (int) ReflectionSingleObjectSizer.roundUpSize(stringSize);
    int charArraySize = // char array
    sampleKey.length() * 2 + SharedLibrary.getObjectHeaderSize() + // object
    4;
    // length of char array
    charArraySize = (int) ReflectionSingleObjectSizer.roundUpSize(charArraySize);
    assertEquals(stringSize, ReflectionSingleObjectSizer.sizeof(String.class));
    assertEquals(ReflectionSingleObjectSizer.roundUpSize(SharedLibrary.getObjectHeaderSize() + 4), (new ReflectionSingleObjectSizer()).sizeof(new char[0]));
    assertEquals(charArraySize, (new ReflectionSingleObjectSizer()).sizeof(new char[5]));
    int keySize = stringSize + charArraySize;
    assertEquals(keySize, WellKnownClassSizer.sizeof(sampleKey));
    assertEquals(keySize, ObjectSizer.DEFAULT.sizeof(sampleKey));
    // now that keys are inlined the keySize is 0
    keySize = 0;
    byte[] sampleValue = new byte[1000];
    int valueSize = // byte array object;
    sampleValue.length + SharedLibrary.getObjectHeaderSize() + // length of byte array
    4;
    valueSize = (int) ReflectionSingleObjectSizer.roundUpSize(valueSize);
    int entrySize = keySize + valueSize + getEntryOverhead(region);
    assertEquals(valueSize, ObjectSizer.DEFAULT.sizeof(sampleValue));
    for (int i = 1; i <= 100; i++) {
        Object key = String.valueOf(10000 + i);
        Object value = new byte[1000];
        region.put(key, value);
        assertEquals(i * entrySize, lruStats.getCounter());
        assertEquals(0, lruStats.getEvictions());
    }
    for (int i = 100; i >= 1; i--) {
        Object key = String.valueOf(10000 + i);
        region.destroy(key);
        assertEquals((i - 1) * entrySize, lruStats.getCounter());
        assertEquals(0, lruStats.getEvictions());
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) ReflectionSingleObjectSizer(org.apache.geode.internal.size.ReflectionSingleObjectSizer) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 15 with LRUStatistics

use of org.apache.geode.internal.cache.lru.LRUStatistics 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)

Aggregations

LRUStatistics (org.apache.geode.internal.cache.lru.LRUStatistics)34 LocalRegion (org.apache.geode.internal.cache.LocalRegion)25 AttributesFactory (org.apache.geode.cache.AttributesFactory)24 Test (org.junit.Test)23 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)20 Region (org.apache.geode.cache.Region)18 File (java.io.File)16 DiskStore (org.apache.geode.cache.DiskStore)16 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)16 DiskRegion (org.apache.geode.internal.cache.DiskRegion)16 Cache (org.apache.geode.cache.Cache)7 DistributedSystem (org.apache.geode.distributed.DistributedSystem)7 DiskRegionStats (org.apache.geode.internal.cache.DiskRegionStats)7 Properties (java.util.Properties)4 Iterator (java.util.Iterator)3 CacheException (org.apache.geode.cache.CacheException)3 CacheLoader (org.apache.geode.cache.CacheLoader)3 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)3 LoaderHelper (org.apache.geode.cache.LoaderHelper)3 ObjectSizer (org.apache.geode.cache.util.ObjectSizer)3