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);
});
}
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());
}
}
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());
}
}
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());
}
}
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);
}
}
Aggregations