use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class DiskRegionDUnitTest method testTestHookStatistics.
/**
* Tests that the "test hook" {@link DiskRegionStats} work as advertised.
*/
@Test
public void testTestHookStatistics() throws Exception {
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
// factory.setConcurrencyChecksEnabled(false);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
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());
LocalRegion region = (LocalRegion) createRegion(name, factory.create());
DiskRegion dr = region.getDiskRegion();
DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
// Put in stuff until we start evicting
int total;
for (total = 0; lruStats.getEvictions() <= 0; total++) {
int[] array = new int[1];
array[0] = total;
region.put(new Integer(total), array);
if (lruStats.getEvictions() <= 0) {
assertEquals(total + 1, diskStats.getNumEntriesInVM());
}
}
assertEquals(1, diskStats.getNumOverflowOnDisk());
// Net change of zero
region.get(new Integer(0));
assertEquals(region.entryCount(), diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
assertEquals(total - 1, diskStats.getNumEntriesInVM());
assertEquals(1, diskStats.getNumOverflowOnDisk());
// Kick out 4 entries
region.put(new Integer(total + 10), new int[1]);
region.put(new Integer(total + 11), new int[1]);
region.put(new Integer(total + 12), new int[1]);
region.put(new Integer(total + 13), new int[1]);
assertEquals(region.entryCount(), diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
assertEquals(total - 1, diskStats.getNumEntriesInVM());
assertEquals(5, diskStats.getNumOverflowOnDisk());
// Make sure invalidate of inVM entry changes inVM count but not disk
region.invalidate(new Integer(total + 10));
assertEquals(region.entryCount() - 1, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
assertEquals(total - 2, diskStats.getNumEntriesInVM());
assertEquals(5, diskStats.getNumOverflowOnDisk());
// Make sure local-invalidate of inVM entry changes inVM count but not disk
region.localInvalidate(new Integer(total + 11));
assertEquals(region.entryCount() - 2, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
assertEquals(total - 3, diskStats.getNumEntriesInVM());
assertEquals(5, diskStats.getNumOverflowOnDisk());
// Make sure destroy of invalid entry does not change inVM or onDisk but changes entry count
region.destroy(new Integer(total + 10));
// ((LocalRegion)region).dumpBackingMap();
assertEquals(region.entryCount() - 1, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
assertEquals(total - 3, diskStats.getNumEntriesInVM());
assertEquals(5, diskStats.getNumOverflowOnDisk());
// Make sure destroy of inVM entry does change inVM but not onDisk
region.destroy(new Integer(total + 12));
assertEquals(region.entryCount() - 1, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
assertEquals(total - 4, diskStats.getNumEntriesInVM());
assertEquals(5, diskStats.getNumOverflowOnDisk());
// Destroy an entry that has been overflowed
region.destroy(new Integer(3));
assertEquals(region.entryCount() - 1, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
assertEquals(total - 4, diskStats.getNumEntriesInVM());
assertEquals(4, diskStats.getNumOverflowOnDisk());
}
use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class DiskRegionDUnitTest method testDistributedInvalidate.
/**
* Tests that invalidates and updates received from different VMs are handled appropriately by
* overflow regions.
*/
@Test
public void testDistributedInvalidate() 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));
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());
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());
}
});
final Object key = new Integer(20);
vm1.invoke(new CacheSerializableRunnable("Invalidate entry") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
assertNotNull(region.get(key));
region.invalidate(key);
}
});
vm0.invoke(new CacheSerializableRunnable("Verify invalidate") {
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(name);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return region.get(key) == null;
}
public String description() {
return "value for key remains: " + key;
}
};
Wait.waitForCriterion(ev, 500, 200, true);
}
});
final String newValue = "NEW VALUE";
vm1.invoke(new CacheSerializableRunnable("Update entry") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.put(key, newValue);
}
});
vm0.invoke(new CacheSerializableRunnable("Verify update") {
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(name);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return newValue.equals(region.get(key));
}
public String description() {
return "verify update";
}
};
Wait.waitForCriterion(ev, 500, 200, true);
}
});
}
use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class DiskRegionDUnitTest method testInvalidate.
/**
* Tests that once an overflowed entry is {@linkplain Region#invalidate invalidated} its value is
* gone.
*/
@Test
public void testInvalidate() 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() <= 10; total++) {
int[] array = new int[250];
array[0] = total;
region.put(new Integer(total), array);
}
region.invalidate(new Integer(0));
assertNull(region.get(new Integer(0)));
}
use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class TestDiskRegion method main1.
public static void main1(String[] args) throws Exception {
DistributedSystem system = DistributedSystem.connect(new java.util.Properties());
Cache cache = CacheFactory.create(system);
AttributesFactory factory = new AttributesFactory();
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK));
factory.setCacheListener(new CacheListenerAdapter() {
public void afterUpdate(EntryEvent event) {
System.out.println("UPDATE: " + event.getKey() + " -> (" + event.getOldValue() + " -> " + event.getNewValue() + ")");
}
});
LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create());
DiskRegion dr = region.getDiskRegion();
DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Hit enter to perform action");
for (int i = 0; true; i++) {
br.readLine();
// Thread.sleep(500);
Object key = new Integer(i);
Object value = new byte[200000];
region.put(key, value);
System.out.println(key + " -> " + value + " evictions = " + lruStats.getEvictions() + ", writes = " + diskStats.getWrites());
}
}
use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class DiskRegionJUnitTest method testDiskRegionOverflow.
/**
* Tests if region overflows correctly and stats are create and updated correctly.
*/
@Test
public void testDiskRegionOverflow() throws Exception {
DiskRegionProperties props = new DiskRegionProperties();
props.setOverflow(true);
props.setOverFlowCapacity(100);
props.setDiskDirs(dirs);
Region region = DiskRegionHelperFactory.getAsyncOverFlowOnlyRegion(cache, props);
DiskRegion dr = ((LocalRegion) region).getDiskRegion();
assertNotNull(dr);
DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = ((LocalRegion) region).getEvictionController().getLRUHelper().getStats();
assertNotNull(diskStats);
assertNotNull(lruStats);
dr.flushForTesting();
assertEquals(0, diskStats.getWrites());
assertEquals(0, diskStats.getReads());
assertEquals(0, lruStats.getEvictions());
// Put in larger stuff until we start evicting
int total;
for (total = 0; lruStats.getEvictions() <= 0; total++) {
// getLogWriter().info("DEBUG: total " + total + ", evictions " +
// lruStats.getEvictions());
int[] array = new int[250];
array[0] = total;
region.put(new Integer(total), array);
}
dr.flushForTesting();
assertEquals(1, diskStats.getWrites());
assertEquals(0, diskStats.getReads());
assertEquals(1, lruStats.getEvictions());
assertEquals(1, diskStats.getNumOverflowOnDisk());
assertEquals(total - 1, diskStats.getNumEntriesInVM());
Object value = region.get(new Integer(0));
dr.flushForTesting();
assertNotNull(value);
assertEquals(0, ((int[]) value)[0]);
assertEquals(2, diskStats.getWrites());
assertEquals(1, diskStats.getReads());
assertEquals(2, lruStats.getEvictions());
for (int i = 0; i < total; i++) {
int[] array = (int[]) region.get(new Integer(i));
assertNotNull(array);
assertEquals(i, array[0]);
}
}
Aggregations