use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class CompressionStatsDUnitTest method getTotalDecompressionTime.
/**
* Returns the total decompression time stat for a region.
*
* @param regionName a region.
*/
private long getTotalDecompressionTime(String regionName) {
LocalRegion region = (LocalRegion) getCache().getRegion(regionName);
assertNotNull(region);
return region.getCachePerfStats().getTotalDecompressionTime();
}
use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class CompressionStatsDUnitTest method getTotalPostCompressedBytes.
/**
* Returns the number of post-decompressed bytes stat for a region.
*
* @param regionName a region.
*/
private long getTotalPostCompressedBytes(String regionName) {
LocalRegion region = (LocalRegion) getCache().getRegion(regionName);
assertNotNull(region);
return region.getCachePerfStats().getTotalPostCompressedBytes();
}
use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class MemoryThresholdsOffHeapDUnitTest method testLRLoadRejection.
/**
* Test that LocalRegion cache Loads are not stored in the Region if the VM is in a critical
* state, then test that they are allowed once the VM is no longer critical
*/
@Test
public void testLRLoadRejection() throws Exception {
final Host host = Host.getHost(0);
final VM vm = host.getVM(2);
final String rName = getUniqueName();
vm.invoke(() -> disconnectFromDS());
vm.invoke(new CacheSerializableRunnable("test LocalRegion load passthrough when critical") {
@Override
public void run2() throws CacheException {
getSystem(getOffHeapProperties());
InternalResourceManager irm = (InternalResourceManager) getCache().getResourceManager();
final OffHeapMemoryMonitor ohmm = irm.getOffHeapMonitor();
irm.setCriticalOffHeapPercentage(90f);
AttributesFactory<Integer, String> af = new AttributesFactory<Integer, String>();
af.setScope(Scope.LOCAL);
af.setOffHeap(true);
final AtomicInteger numLoaderInvocations = new AtomicInteger(0);
af.setCacheLoader(new CacheLoader<Integer, String>() {
public String load(LoaderHelper<Integer, String> helper) throws CacheLoaderException {
numLoaderInvocations.incrementAndGet();
return helper.getKey().toString();
}
public void close() {
}
});
final LocalRegion r = (LocalRegion) getCache().createRegion(rName, af.create());
assertFalse(ohmm.getState().isCritical());
int expectedInvocations = 0;
assertEquals(expectedInvocations++, numLoaderInvocations.get());
{
Integer k = new Integer(1);
assertEquals(k.toString(), r.get(k));
}
assertEquals(expectedInvocations++, numLoaderInvocations.get());
expectedInvocations++;
expectedInvocations++;
r.getAll(createRanges(10, 12));
assertEquals(expectedInvocations++, numLoaderInvocations.get());
getCache().getLoggerI18n().fine(addExpectedExString);
r.put("oh1", new byte[838860]);
r.put("oh3", new byte[157287]);
getCache().getLoggerI18n().fine(removeExpectedExString);
WaitCriterion wc = new WaitCriterion() {
public String description() {
return "expected region " + r + " to set memoryThresholdReached";
}
public boolean done() {
return r.memoryThresholdReached.get();
}
};
Wait.waitForCriterion(wc, 30 * 1000, 10, true);
{
Integer k = new Integer(2);
assertEquals(k.toString(), r.get(k));
}
assertEquals(expectedInvocations++, numLoaderInvocations.get());
expectedInvocations++;
expectedInvocations++;
r.getAll(createRanges(13, 15));
assertEquals(expectedInvocations++, numLoaderInvocations.get());
getCache().getLoggerI18n().fine(addExpectedBelow);
r.destroy("oh3");
getCache().getLoggerI18n().fine(removeExpectedBelow);
wc = new WaitCriterion() {
public String description() {
return "expected region " + r + " to unset memoryThresholdReached";
}
public boolean done() {
return !r.memoryThresholdReached.get();
}
};
Wait.waitForCriterion(wc, 30 * 1000, 10, true);
{
Integer k = new Integer(3);
assertEquals(k.toString(), r.get(k));
}
assertEquals(expectedInvocations++, numLoaderInvocations.get());
expectedInvocations++;
expectedInvocations++;
r.getAll(createRanges(16, 18));
assertEquals(expectedInvocations, numLoaderInvocations.get());
// Do extra validation that the entry doesn't exist in the local region
for (Integer i : createRanges(2, 2, 13, 15)) {
if (r.containsKey(i)) {
fail("Expected containsKey return false for key" + i);
}
if (r.getEntry(i) != null) {
fail("Expected getEntry to return null for key" + i);
}
}
}
});
}
use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class IndexUseJUnitTest method testMapIndexUsageWithIndexOnMultipleKeys.
@Test
public void testMapIndexUsageWithIndexOnMultipleKeys() throws Exception {
try {
IndexManager.TEST_RANGEINDEX_ONLY = true;
String[] queries = { "SELECT DISTINCT * FROM /testRgn itr1 WHERE itr1.maap['key2'] >= 3", "SELECT DISTINCT * FROM /testRgn itr1 WHERE itr1.maap['key3'] >= 3" };
String[] queriesIndexNotUsed = { "SELECT DISTINCT * FROM /testRgn itr1 WHERE itr1.maap.get('key2') >= 16", "SELECT DISTINCT * FROM /testRgn itr1 WHERE itr1.maap['key4'] >= 16" };
LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
int ID = 1;
// and so on
for (; ID <= 30; ++ID) {
MapKeyIndexData mkid = new MapKeyIndexData(ID);
for (int j = 1; j <= ID; ++j) {
mkid.addKeyValue("key1", j * 1);
mkid.addKeyValue("key2", j * 2);
mkid.addKeyValue("key3", j * 3);
}
testRgn.put(ID, mkid);
}
evaluateMapTypeIndexUsage("objs.maap['key2','key3']", "/testRgn objs", queries, queriesIndexNotUsed, MapRangeIndex.class);
} finally {
IndexManager.TEST_RANGEINDEX_ONLY = false;
}
}
use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class IndexUseJUnitTest method testCompactMapIndexUsageWithIndexOnMultipleKeys.
@Test
public void testCompactMapIndexUsageWithIndexOnMultipleKeys() throws Exception {
String[] queries = { "SELECT DISTINCT * FROM /testRgn itr1 WHERE itr1.maap['key2'] >= 3", "SELECT DISTINCT * FROM /testRgn itr1 WHERE itr1.maap['key3'] >= 3" };
String[] queriesIndexNotUsed = { "SELECT DISTINCT * FROM /testRgn itr1 WHERE itr1.maap.get('key2') >= 16", "SELECT DISTINCT * FROM /testRgn itr1 WHERE itr1.maap['key4'] >= 16" };
LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
int ID = 1;
// and so on
for (; ID <= 30; ++ID) {
MapKeyIndexData mkid = new MapKeyIndexData(ID);
for (int j = 1; j <= ID; ++j) {
mkid.addKeyValue("key1", j * 1);
mkid.addKeyValue("key2", j * 2);
mkid.addKeyValue("key3", j * 3);
}
testRgn.put(ID, mkid);
}
evaluateMapTypeIndexUsage("objs.maap['key2','key3']", "/testRgn objs", queries, queriesIndexNotUsed, CompactMapRangeIndex.class);
}
Aggregations