use of org.apache.geode.cache.LowMemoryException in project geode by apache.
the class MemoryThresholdsDUnitTest method testTxCommitInCritical.
@Ignore("this test is DISABLED due to test issues. It sometimes fails with a TransactionDataNotColocatedException. See bug #52222")
@Test
public void testTxCommitInCritical() throws Exception {
final Host host = Host.getHost(0);
final VM accessor = host.getVM(0);
final VM server1 = host.getVM(1);
final VM server2 = host.getVM(2);
final VM server3 = host.getVM(3);
final String regionName = "testPrRejection";
final int redundancy = 1;
final ServerPorts ports1 = startCacheServer(server1, 80f, 90f, regionName, true, /* createPR */
false, /* notifyBySubscription */
redundancy);
ServerPorts ports2 = startCacheServer(server2, 80f, 90f, regionName, true, /* createPR */
false, /* notifyBySubscription */
redundancy);
ServerPorts ports3 = startCacheServer(server3, 80f, 90f, regionName, true, /* createPR */
false, /* notifyBySubscription */
redundancy);
registerTestMemoryThresholdListener(server1);
registerTestMemoryThresholdListener(server2);
registerTestMemoryThresholdListener(server3);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
getSystem(getServerProperties());
getCache();
AttributesFactory factory = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundancy);
paf.setLocalMaxMemory(0);
paf.setTotalNumBuckets(11);
factory.setPartitionAttributes(paf.create());
createRegion(regionName, factory.create());
return null;
}
});
doPuts(accessor, regionName, false, false);
final Range r1 = Range.DEFAULT;
doPutAlls(accessor, regionName, false, false, r1);
SerializableCallable getMyId = new SerializableCallable() {
public Object call() throws Exception {
return ((GemFireCacheImpl) getCache()).getMyId();
}
};
final DistributedMember server1Id = (DistributedMember) server1.invoke(getMyId);
final Integer lastKey = (Integer) accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
final PartitionedRegion pr = (PartitionedRegion) getRootRegion().getSubregion(regionName);
getCache().getCacheTransactionManager().begin();
for (int i = 0; i < 20; i++) {
Integer key = Integer.valueOf(i);
int hKey = PartitionedRegionHelper.getHashKey(pr, key);
Set<InternalDistributedMember> owners = pr.getRegionAdvisor().getBucketOwners(hKey);
if (owners.contains(server1Id)) {
pr.put(key, "txTest");
return i;
}
}
return null;
}
});
assertNotNull(lastKey);
setUsageAboveCriticalThreshold(server1);
verifyListenerValue(server1, MemoryState.CRITICAL, 1, true);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
final PartitionedRegion pr = (PartitionedRegion) getRootRegion().getSubregion(regionName);
assertTrue(getCache().getCacheTransactionManager().exists());
boolean exceptionThrown = false;
for (int i = lastKey; i < 20; i++) {
Integer key = Integer.valueOf(i);
int hKey = PartitionedRegionHelper.getHashKey(pr, key);
Set<InternalDistributedMember> owners = pr.getRegionAdvisor().getBucketOwners(hKey);
if (owners.contains(server1Id)) {
try {
pr.put(key, "txTest");
} catch (LowMemoryException e) {
exceptionThrown = true;
break;
}
}
}
if (!exceptionThrown) {
fail("expected exception not thrown");
}
getCache().getCacheTransactionManager().commit();
int seenCount = 0;
for (int i = 0; i < 20; i++) {
if ("txTest".equals(pr.get(i))) {
seenCount++;
}
}
assertEquals(1, seenCount);
return null;
}
});
}
use of org.apache.geode.cache.LowMemoryException in project geode by apache.
the class MemoryThresholdsOffHeapDUnitTest method doClientServerTest.
private void doClientServerTest(final String regionName, boolean createPR) throws Exception {
// create region on the server
final Host host = Host.getHost(0);
final VM server = host.getVM(0);
final VM client = host.getVM(1);
final Object bigKey = -1;
final Object smallKey = -2;
final int port = startCacheServer(server, 0f, 90f, regionName, createPR, false, 0);
startClient(client, server, port, regionName);
doPuts(client, regionName, false, /* catchServerException */
false);
doPutAlls(client, regionName, false, /* catchServerException */
false, /* catchLowMemoryException */
Range.DEFAULT);
// make the region sick in the server
final long bytesUsedAfterSmallKey = (long) server.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
InternalResourceManager irm = ((GemFireCacheImpl) getCache()).getInternalResourceManager();
final OffHeapMemoryMonitor ohm = irm.getOffHeapMonitor();
assertTrue(ohm.getState().isNormal());
getCache().getLoggerI18n().fine(addExpectedExString);
final LocalRegion r = (LocalRegion) getRootRegion().getSubregion(regionName);
final long bytesUsedAfterSmallKey;
{
OffHeapMemoryMonitorObserverImpl _testHook = new OffHeapMemoryMonitorObserverImpl();
ohm.testHook = _testHook;
try {
r.put(smallKey, "1234567890");
bytesUsedAfterSmallKey = _testHook.verifyBeginUpdateMemoryUsed(false);
} finally {
ohm.testHook = null;
}
}
{
final OffHeapMemoryMonitorObserverImpl th = new OffHeapMemoryMonitorObserverImpl();
ohm.testHook = th;
try {
r.put(bigKey, new byte[943720]);
th.verifyBeginUpdateMemoryUsed(bytesUsedAfterSmallKey + 943720 + 8, true);
WaitCriterion waitForCritical = new WaitCriterion() {
public boolean done() {
return th.checkUpdateStateAndSendEventBeforeProcess(bytesUsedAfterSmallKey + 943720 + 8, MemoryState.EVICTION_DISABLED_CRITICAL);
}
@Override
public String description() {
return null;
}
};
Wait.waitForCriterion(waitForCritical, 30 * 1000, 9, false);
th.validateUpdateStateAndSendEventBeforeProcess(bytesUsedAfterSmallKey + 943720 + 8, MemoryState.EVICTION_DISABLED_CRITICAL);
} finally {
ohm.testHook = null;
}
}
WaitCriterion wc;
if (r instanceof PartitionedRegion) {
final PartitionedRegion pr = (PartitionedRegion) r;
final int bucketId = PartitionedRegionHelper.getHashKey(pr, null, bigKey, null, null);
wc = new WaitCriterion() {
@Override
public String description() {
return "Expected to go critical: isCritical=" + ohm.getState().isCritical();
}
@Override
public boolean done() {
if (!ohm.getState().isCritical())
return false;
// Only done once the bucket has been marked sick
try {
pr.getRegionAdvisor().checkIfBucketSick(bucketId, bigKey);
return false;
} catch (LowMemoryException ignore) {
return true;
}
}
};
} else {
wc = new WaitCriterion() {
@Override
public String description() {
return "Expected to go critical: isCritical=" + ohm.getState().isCritical() + " memoryThresholdReached=" + r.memoryThresholdReached.get();
}
@Override
public boolean done() {
return ohm.getState().isCritical() && r.memoryThresholdReached.get();
}
};
}
Wait.waitForCriterion(wc, 30000, 9, true);
getCache().getLoggerI18n().fine(removeExpectedExString);
return bytesUsedAfterSmallKey;
}
});
// make sure client puts are rejected
doPuts(client, regionName, true, /* catchServerException */
false);
doPutAlls(client, regionName, true, /* catchServerException */
false, /* catchLowMemoryException */
new Range(Range.DEFAULT, Range.DEFAULT.width() + 1));
// make the region healthy in the server
server.invoke(new SerializableRunnable() {
public void run() {
InternalResourceManager irm = ((GemFireCacheImpl) getCache()).getInternalResourceManager();
final OffHeapMemoryMonitor ohm = irm.getOffHeapMonitor();
assertTrue(ohm.getState().isCritical());
getCache().getLogger().fine(MemoryThresholdsOffHeapDUnitTest.this.addExpectedBelow);
OffHeapMemoryMonitorObserverImpl _testHook = new OffHeapMemoryMonitorObserverImpl();
ohm.testHook = _testHook;
try {
getRootRegion().getSubregion(regionName).destroy(bigKey);
_testHook.verifyBeginUpdateMemoryUsed(bytesUsedAfterSmallKey, true);
} finally {
ohm.testHook = null;
}
WaitCriterion wc = new WaitCriterion() {
@Override
public String description() {
return "Expected to go normal";
}
@Override
public boolean done() {
return ohm.getState().isNormal();
}
};
Wait.waitForCriterion(wc, 30000, 9, true);
getCache().getLogger().fine(MemoryThresholdsOffHeapDUnitTest.this.removeExpectedBelow);
return;
}
});
}
use of org.apache.geode.cache.LowMemoryException in project geode by apache.
the class MemoryThresholdsDUnitTest method testDRFunctionExecutionRejection.
@Test
public void testDRFunctionExecutionRejection() throws Exception {
IgnoredException.addIgnoredException("LowMemoryException");
final Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM server2 = host.getVM(1);
final VM client = host.getVM(2);
final String regionName = "drFuncRej";
ServerPorts ports1 = startCacheServer(server1, 80f, 90f, regionName, false, /* createPR */
false, /* notifyBySubscription */
0);
ServerPorts ports2 = startCacheServer(server2, 80f, 90f, regionName, false, /* createPR */
false, /* notifyBySubscription */
0);
startClient(client, server1, ports1.getPort(), regionName);
registerTestMemoryThresholdListener(server1);
registerTestMemoryThresholdListener(server2);
final RejectFunction function = new RejectFunction();
final RejectFunction function2 = new RejectFunction("noRejFunc", false);
Invoke.invokeInEveryVM(new SerializableCallable("register function") {
public Object call() throws Exception {
FunctionService.registerFunction(function);
FunctionService.registerFunction(function2);
return null;
}
});
doPutAlls(server1, regionName, false, false, Range.DEFAULT);
doPuts(server1, regionName, false, false);
server1.invoke(new SerializableCallable() {
public Object call() throws Exception {
FunctionService.onRegion(getRootRegion().getSubregion(regionName)).execute(function);
FunctionService.onRegion(getRootRegion().getSubregion(regionName)).execute(function2);
return null;
}
});
// should not fail
server1.invoke(new SerializableCallable() {
public Object call() throws Exception {
FunctionService.onMembers().execute(function);
FunctionService.onMembers().execute(function2);
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
FunctionService.onRegion(getRootRegion().getSubregion(regionName)).execute(function).getResult(30, TimeUnit.SECONDS);
FunctionService.onRegion(getRootRegion().getSubregion(regionName)).execute(function2).getResult(30, TimeUnit.SECONDS);
return null;
}
});
setUsageAboveCriticalThreshold(server2);
verifyListenerValue(server1, MemoryState.CRITICAL, 1, true);
server1.invoke(new SerializableCallable() {
public Object call() throws Exception {
try {
getCache().getLoggerI18n().fine(addExpectedFunctionExString);
FunctionService.onRegion(getRootRegion().getSubregion(regionName)).execute(function);
getCache().getLoggerI18n().fine(removeExpectedFunctionExString);
fail("expected low memory exception was not thrown");
} catch (LowMemoryException e) {
// expected
}
FunctionService.onRegion(getRootRegion().getSubregion(regionName)).execute(function2);
return null;
}
});
server1.invoke(new SerializableCallable() {
public Object call() throws Exception {
try {
getCache().getLoggerI18n().fine(addExpectedFunctionExString);
FunctionService.onMembers().execute(function);
getCache().getLoggerI18n().fine(removeExpectedFunctionExString);
fail("expected low memory exception was not thrown");
} catch (LowMemoryException e) {
// expected
}
FunctionService.onMembers().execute(function2);
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
try {
getCache().getLoggerI18n().fine(addExpectedFunctionExString);
FunctionService.onRegion(getRootRegion().getSubregion(regionName)).execute(function);
getCache().getLoggerI18n().fine(removeExpectedFunctionExString);
fail("expected low memory exception was not thrown");
} catch (FunctionException e) {
if (!(e.getCause().getCause() instanceof LowMemoryException)) {
Assert.fail("unexpected exception ", e);
}
// expected
}
FunctionService.onRegion(getRootRegion().getSubregion(regionName)).execute(function2);
return null;
}
});
}
Aggregations