use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PartitionedRegionDelayedRecoveryDUnitTest method postTearDownCacheTestCase.
@Override
public final void postTearDownCacheTestCase() throws Exception {
Invoke.invokeInEveryVM(new SerializableRunnable() {
public void run() {
InternalResourceManager.setResourceObserver(null);
}
});
InternalResourceManager.setResourceObserver(null);
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUMaximum.
// Test to validate the Eviction Attribute : LRU Maximum
@Test
public void testEvictionValidationForLRUMaximum() {
final Host host = Host.getHost(0);
final VM testDatastore = host.getVM(2);
final VM firstDatastore = host.getVM(3);
final String uniqName = getUniqueName();
final int redundantCopies = 1;
final int maxEntries = 226;
final String name = uniqName + "-PR";
final EvictionAttributes firstEvictionAttributes = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY);
// Creating LRU Entry Count Eviction Attribute : maxentries : 2
final SerializableRunnable create = new CacheSerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {
public void run2() {
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
factory.setEvictionAttributes(firstEvictionAttributes);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
assertEquals(firstEvictionAttributes, pr.getAttributes().getEvictionAttributes());
}
};
firstDatastore.invoke(create);
final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with Overflow to disk partitioned Region") {
public void run() {
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
final EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(firstEvictionAttributes.getMaximum() + 10, firstEvictionAttributes.getAction());
factory.setEvictionAttributes(ea);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
testDatastore.invoke(create2);
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PartitionedRegionEvictionDUnitTest method testEntryLRUDeadlock.
/**
* Test that gets do not need to acquire a lock on the region entry when LRU is enabled. This is
* bug 42265
*/
@Test
public void testEntryLRUDeadlock() {
final Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
final String uniqName = getUniqueName();
final int redundantCopies = 0;
final int maxBuckets = 8;
final int maxEntries = 16;
final String name = uniqName + "-PR";
final int extraEntries = 4;
// final int heapPercentage = 66;
// final int evictorInterval = 100;
final SerializableRunnable create = new CacheSerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {
public void run2() {
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setTotalNumBuckets(maxBuckets).create());
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY));
final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
vm0.invoke(create);
final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {
public void run() {
try {
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).setTotalNumBuckets(maxBuckets).create());
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntries));
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
// this listener will cause a deadlock if the get ends up
// locking the entry.
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
Region region = event.getRegion();
Object key = event.getKey();
region.get(key);
}
});
final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
assertNotNull(pr);
} catch (final CacheException ex) {
Assert.fail("While creating Partitioned region", ex);
}
}
};
vm1.invoke(create2);
final SerializableRunnable doPuts = new SerializableRunnable("Do Puts") {
public void run() {
final PartitionedRegion pr = (PartitionedRegion) getRootRegion(name);
assertNotNull(pr);
for (int counter = 0; counter <= maxEntries + extraEntries; counter++) {
pr.put(new Integer(counter), "value");
}
}
};
vm0.invoke(doPuts);
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class RemoveGlobalDUnitTest method testRemoveGlobalSingleVM.
// test methods
@Test
public void testRemoveGlobalSingleVM() throws Throwable {
SerializableRunnable createRegionWithWriter = new CacheSerializableRunnable("create region with cache writer") {
public void run2() throws CacheException {
cache.setLockTimeout(5);
CacheWriter cacheWriter = new CacheWriterCallBack();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.GLOBAL);
factory.setCacheWriter(cacheWriter);
region = cache.createRegion("map", factory.create());
}
};
vm0.invoke(createRegionWithWriter);
AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("put object") {
public void run2() throws CacheException {
for (int i = 1; i < 5; i++) {
region.put(new Integer(i), java.lang.Integer.toString(i));
}
region.remove(new Integer(2));
}
});
vm0.invoke(new CacheSerializableRunnable("verify locking") {
public void run2() throws CacheException {
synchronized (RemoveGlobalDUnitTest.class) {
if (!lockedForRemove) {
try {
RemoveGlobalDUnitTest.class.wait();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
try {
// getLogWriter().fine("000000000000000");
region.put(new Integer(2), "newEntry");
fail("Should have thrown TimeoutException");
} catch (TimeoutException tme) {
// pass
}
}
});
ThreadUtils.join(async, 30 * 1000);
if (async.exceptionOccurred())
throw async.getException();
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method testBug43430.
/**
* Attempt to do a client server function execution with an arg that fail deserialization on the
* server. The client should see an exception instead of a hang if bug 43430 is fixed.
*/
@Test
public void testBug43430() {
createScenario();
Function function = new TestFunction(true, TEST_FUNCTION2);
registerFunctionAtServer(function);
SerializableRunnable suspect = new SerializableRunnable() {
public void run() {
cache.getLogger().info("<ExpectedException action=add>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
}
};
runOnAllServers(suspect);
client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.serverBug43430());
SerializableRunnable endSuspect = new SerializableRunnable() {
public void run() {
cache.getLogger().info("<ExpectedException action=remove>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
}
};
runOnAllServers(endSuspect);
}
Aggregations