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 DiskRegionDUnitTest method testNoFaults.
/**
* Overflows a region and makes sure that gets of recently-used objects do not cause faults.
*/
@Test
public void testNoFaults() throws Exception {
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
File d = new File("DiskRegions" + OSProcess.getId());
d.mkdirs();
DiskStoreFactory dsf = getCache().createDiskStoreFactory();
dsf.setDiskDirs(new File[] { d });
DiskStore ds = dsf.create(name);
factory.setDiskStoreName(ds.getName());
Region region = createRegion(name, factory.create());
DiskRegion dr = ((LocalRegion) region).getDiskRegion();
DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
// Put in larger stuff until we start evicting
int total;
for (total = 0; lruStats.getEvictions() <= 20; total++) {
// System.out.println("total " + total + ", evictions " +
// lruStats.getEvictions());
int[] array = new int[250];
array[0] = total;
region.put(new Integer(total), array);
}
assertTrue(total > 40);
long firstEvictions = lruStats.getEvictions();
long firstReads = diskStats.getReads();
for (int i = 1; i <= 40; i++) {
int key = total - i;
region.get(new Integer(key));
assertEquals("Key " + key + " caused an eviction", firstEvictions, lruStats.getEvictions());
assertEquals("Key " + key + " caused an eviction", firstReads, diskStats.getReads());
}
}
use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class DiskRegionDUnitTest method testCacheEvents.
/**
* Tests cache listeners in an overflow region are invoked and that their events are reasonable.
*/
@Test
public void testCacheEvents() throws Exception {
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
File d = new File("DiskRegions" + OSProcess.getId());
d.mkdirs();
TestCacheListener listener = new TestCacheListener() {
public void afterCreate2(EntryEvent event) {
}
};
factory.addCacheListener(listener);
DiskStoreFactory dsf = getCache().createDiskStoreFactory();
dsf.setDiskDirs(new File[] { d });
factory.setDiskSynchronous(true);
DiskStore ds = dsf.create(name);
factory.setDiskStoreName(ds.getName());
Region region = createRegion(name, factory.create());
// DiskRegion dr = ((LocalRegion) region).getDiskRegion();
// DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
int total;
for (total = 0; lruStats.getEvictions() < 20; total++) {
region.put(new Integer(total), String.valueOf(total));
assertEquals(String.valueOf(total), region.get(new Integer(total)));
}
assertTrue(listener.wasInvoked());
listener = new TestCacheListener() {
public void close2() {
}
};
region.getAttributesMutator().setCacheListener(listener);
for (int i = 0; i < total; i++) {
String value = (String) region.get(new Integer(i));
assertNotNull(value);
assertEquals(String.valueOf(i), value);
}
assertFalse(listener.wasInvoked());
listener = new TestCacheListener() {
public void afterUpdate2(EntryEvent event) {
Integer key = (Integer) event.getKey();
assertEquals(null, event.getOldValue());
assertEquals(false, event.isOldValueAvailable());
byte[] value = (byte[]) event.getNewValue();
assertEquals(key.intValue(), value.length);
}
};
region.getAttributesMutator().setCacheListener(listener);
for (int i = 0; i < 20; i++) {
region.put(new Integer(i), new byte[i]);
}
assertTrue(listener.wasInvoked());
}
use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class DiskRegionDUnitTest method testLRUCCSizeOne.
/**
* Tests a disk-based region with an {@link LRUCapacityController} with size 1 and an eviction
* action of "overflow".
*/
@Test
public void testLRUCCSizeOne() throws CacheException {
int threshold = 1;
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(threshold, EvictionAction.OVERFLOW_TO_DISK));
factory.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) throws CacheLoaderException {
return "LOADED VALUE";
}
public void close() {
}
});
DiskStoreFactory dsf = getCache().createDiskStoreFactory();
factory.setDiskSynchronous(true);
File d = new File("DiskRegions" + OSProcess.getId());
d.mkdirs();
dsf.setDiskDirs(new File[] { d });
DiskStore ds = dsf.create(name);
factory.setDiskStoreName(ds.getName());
Region 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 DiskRegionDUnitTest method testOverflowMirror.
/**
* Tests overflow with mirrored regions. Note that we have to use <code>byte</code> array values
* in this test. Otherwise, the size of the data in the "puter" VM would be different from the
* size of the data in the receiver VM, thus cause the two VMs to have different LRU eviction
* behavior.
*/
@Test
public void testOverflowMirror() throws Exception {
final String name = this.getUniqueName();
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
factory.setDataPolicy(DataPolicy.REPLICATE);
File d = new File("DiskRegions" + OSProcess.getId());
d.mkdirs();
DiskStoreFactory dsf = getCache().createDiskStoreFactory();
dsf.setDiskDirs(new File[] { d });
factory.setDiskSynchronous(true);
DiskStore ds = dsf.create(name);
factory.setDiskStoreName(ds.getName());
createRegion(name, factory.create());
}
};
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(create);
vm1.invoke(create);
vm0.invoke(new CacheSerializableRunnable("Fill Region") {
public void run2() throws CacheException {
LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
// DiskRegion dr = region.getDiskRegion();
LRUStatistics lruStats = getLRUStats(region);
for (int i = 0; lruStats.getEvictions() < 10; i++) {
LogWriterUtils.getLogWriter().info("Put " + i);
region.put(new Integer(i), new byte[1]);
}
assertEquals(10, lruStats.getEvictions());
}
});
vm1.invoke(new CacheSerializableRunnable("Verify overflow") {
public void run2() throws CacheException {
LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
// DiskRegion dr = region.getDiskRegion();
LRUStatistics lruStats = getLRUStats(region);
assertEquals(10, lruStats.getEvictions());
// entries.
for (int i = 0; i < 10; i++) {
region.get(new Integer(i));
assertEquals("No eviction for " + i, 10 + 1 + i, lruStats.getEvictions());
}
}
});
}
Aggregations