use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class LRUEvictionControllerDUnitTest method testCacheLoader.
/**
* Carefully verifies that region operations effect the {@link LRUStatistics} as expected in the
* presense of a {@link CacheLoader}.
*/
@Test
public void testCacheLoader() throws CacheException {
int threshold = 10;
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
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 <= 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);
// Invoke loader
region.get(key);
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 MemberMBeanBridge method removeRegion.
public void removeRegion(Region region) {
if (region.getAttributes().getPartitionAttributes() != null) {
removePartionRegionStats(((PartitionedRegion) region).getPrStats());
}
LocalRegion l = (LocalRegion) region;
if (l.getEvictionController() != null) {
LRUStatistics stats = l.getEvictionController().getLRUHelper().getStats();
if (stats != null) {
removeLRUStats(stats);
}
}
DiskRegion dr = l.getDiskRegion();
if (dr != null) {
for (DirectoryHolder dh : dr.getDirectories()) {
removeDirectoryStats(dh.getDiskDirectoryStats());
}
}
}
use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class TestDiskRegion method main5.
/**
* Filling up the region with keys and values
*/
public static void main5(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));
LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create());
// DiskRegion dr = region.getDiskRegion();
// DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
for (int i = 0; i < 10000; i++) {
int[] array = new int[1000];
array[0] = i;
try {
region.put(array, new Integer(i));
} catch (IllegalStateException ex) {
System.out.println("Ran out of space: " + ex);
return;
}
}
String s = "Limit is " + lruStats.getLimit() + " evictions are " + lruStats.getEvictions();
throw new RuntimeException(s);
}
use of org.apache.geode.internal.cache.lru.LRUStatistics in project geode by apache.
the class TestDiskRegion method main.
public static void main(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));
DiskStoreFactory dsf = cache.createDiskStoreFactory();
File user_dir = new File(System.getProperty("user.dir"));
if (!user_dir.exists()) {
user_dir.mkdir();
}
File[] dirs1 = new File[] { user_dir };
DiskStore ds1 = dsf.setDiskDirs(dirs1).create("TestDiskRegion");
factory.setDiskStoreName("TestDiskRegion");
LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create());
DiskRegion dr = region.getDiskRegion();
Assert.assertTrue(dr != null);
DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
Assert.assertTrue(diskStats != null);
Assert.assertTrue(lruStats != null);
// Put some small stuff
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), String.valueOf(i));
}
Assert.assertTrue(diskStats.getWrites() == 0);
Assert.assertTrue(diskStats.getReads() == 0);
Assert.assertTrue(lruStats.getEvictions() == 0);
// // Make sure we can get them back okay
// for (int i = 0; i < 10; i++) {
// Object value = region.get(new Integer(i));
// Assert.assertTrue(value != null);
// Assert.assertTrue(String.valueOf(i).equals(value));
// }
// Put in larger stuff until we start evicting
int total;
for (total = 0; lruStats.getEvictions() <= 0; total++) {
System.out.println("total puts " + total + ", evictions " + lruStats.getEvictions() + ", total entry size " + lruStats.getCounter());
int[] array = new int[250];
array[0] = total;
region.put(new Integer(total), array);
}
Assert.assertTrue(diskStats.getWrites() == 1);
Assert.assertTrue(diskStats.getReads() == 0);
Assert.assertTrue(lruStats.getEvictions() == 1);
System.out.println("---------- Finished Putting -------------");
Object value = region.get(new Integer(0));
Assert.assertTrue(value != null);
Assert.assertTrue(((int[]) value)[0] == 0);
Assert.assertTrue(diskStats.getWrites() == 2, String.valueOf(diskStats.getWrites()));
Assert.assertTrue(diskStats.getReads() == 1);
Assert.assertTrue(lruStats.getEvictions() == 2, String.valueOf(lruStats.getEvictions()));
System.out.println("---------- Getting ALL -------------");
for (int i = 0; i < total; i++) {
System.out.println("total gets " + i + ", evictions " + lruStats.getEvictions() + ", total entry size " + lruStats.getCounter());
int[] array = (int[]) region.get(new Integer(i));
Assert.assertTrue(array != null);
Assert.assertTrue(i == array[0]);
}
System.out.println("--------- Updating --------------");
long startEvictions = lruStats.getEvictions();
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), new int[251]);
long expected = startEvictions + 1 + i;
long actual = lruStats.getEvictions();
Assert.assertTrue(expected == actual, "For " + i + " expected " + expected + ", got " + actual);
}
System.out.println("Done. Waiting for stats to be written...");
Thread.sleep(5 * 1000);
}
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());
}
}
Aggregations