use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class ShutdownAllDUnitTest method testShutdownAllWithMembersWaiting.
/**
* Test for 43551. Do a shutdown all with some members waiting on recovery.
*/
@Test
public void testShutdownAllWithMembersWaiting() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final int numBuckets = 5;
createRegion(vm0, "region", "disk", true, 1);
createRegion(vm1, "region", "disk", true, 1);
createData(vm0, 0, numBuckets, "a", "region");
Set<Integer> vm0Buckets = getBucketList(vm0, "region");
Set<Integer> vm1Buckets = getBucketList(vm1, "region");
// shutdown all the members
shutDownAllMembers(vm2, 2);
// restart one of the members (this will hang, waiting for the other members)
// restart vm0
AsyncInvocation a0 = createRegionAsync(vm0, "region", "disk", true, 1);
// Wait a bit for the initialization to get stuck
Wait.pause(20000);
assertTrue(a0.isAlive());
// Do another shutdown all, with a member offline and another stuck
shutDownAllMembers(vm2, 1);
// This should complete (but maybe it will throw an exception?)
try {
a0.getResult(MAX_WAIT);
fail("should have received a cache closed exception");
} catch (AssertionError e) {
if (!CacheClosedException.class.isInstance(getRootCause(e))) {
throw e;
}
}
// now restart both members. This should work, but
// no guarantee they'll do a clean recovery
a0 = createRegionAsync(vm0, "region", "disk", true, 1);
AsyncInvocation a1 = createRegionAsync(vm1, "region", "disk", true, 1);
a0.getResult(MAX_WAIT);
a1.getResult(MAX_WAIT);
assertEquals(vm0Buckets, getBucketList(vm0, "region"));
checkData(vm0, 0, numBuckets, "a", "region");
checkData(vm1, 0, numBuckets, "a", "region");
createData(vm0, numBuckets, numBuckets * 2, "b", "region");
checkData(vm0, numBuckets, numBuckets * 2, "b", "region");
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class ShutdownAllDUnitTest method testShutdownAllTimeout.
@Test
public void testShutdownAllTimeout() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final int numBuckets = 50;
createRegion(vm0, "region", "disk", true, 1);
createRegion(vm1, "region", "disk", true, 1);
createData(vm0, 0, numBuckets, "a", "region");
Set<Integer> vm0Buckets = getBucketList(vm0, "region");
Set<Integer> vm1Buckets = getBucketList(vm1, "region");
assertEquals(vm0Buckets, vm1Buckets);
// Add a cache listener that will cause the system to hang up.
// Then do some puts to get us stuck in a put.
AsyncInvocation async1 = vm0.invokeAsync(new SerializableRunnable() {
public void run() {
Region<Object, Object> region = getCache().getRegion("region");
listener = new HangingCacheListener();
region.getAttributesMutator().addCacheListener(listener);
// get us stuck doing a put.
for (int i = 0; i < numBuckets; i++) {
region.put(i, "a");
}
}
});
// Make sure the we do get stuck
async1.join(1000);
assertTrue(async1.isAlive());
// Do a shutdownall with a timeout.
// This will hit the timeout, because the in progress put will
// prevent us from gracefully shutting down.
long start = System.nanoTime();
shutDownAllMembers(vm2, 0, 2000);
long end = System.nanoTime();
// Make sure we waited for the timeout.
assertTrue(end - start > TimeUnit.MILLISECONDS.toNanos(1500));
// clean up our stuck thread
vm0.invoke(new SerializableRunnable() {
public void run() {
listener.latch.countDown();
listener = null;
}
});
// wait for shutdown to finish
Wait.pause(10000);
// restart vm0
AsyncInvocation a0 = createRegionAsync(vm0, "region", "disk", true, 1);
// restart vm1
AsyncInvocation a1 = createRegionAsync(vm1, "region", "disk", true, 1);
a0.getResult(MAX_WAIT);
a1.getResult(MAX_WAIT);
assertEquals(vm0Buckets, getBucketList(vm0, "region"));
checkData(vm0, 0, numBuckets, "a", "region");
checkData(vm1, 0, numBuckets, "a", "region");
createData(vm0, numBuckets, 113, "b", "region");
checkData(vm0, numBuckets, 113, "b", "region");
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testCloseDuringRegionOperation.
@Test
public void testCloseDuringRegionOperation() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
createPR(vm0, 1, -1, 1);
createPR(vm1, 1, -1, 1);
// Make sure we create a bucket
createData(vm1, 0, 1, "a");
// Try to make sure there are some operations in flight while closing the cache
SerializableCallable createData = new SerializableCallable() {
public Object call() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
int i = 0;
while (true) {
try {
region.put(0, i);
i++;
} catch (CacheClosedException e) {
break;
}
}
return i - 1;
}
};
AsyncInvocation asyncCreate = vm0.invokeAsync(createData);
SerializableCallable waitForIntValue = new SerializableCallable() {
public Object call() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
// The value is initialized as a String so wait
// for it to be changed to an Integer.
await().atMost(60, SECONDS).until(() -> {
return region.get(0) instanceof Integer;
});
return region.get(0);
}
};
vm0.invoke(waitForIntValue);
vm1.invoke(waitForIntValue);
AsyncInvocation close0 = closeCacheAsync(vm0);
AsyncInvocation close1 = closeCacheAsync(vm1);
// wait for the close to finish
close0.getResult();
close1.getResult();
Integer lastSuccessfulInt = (Integer) asyncCreate.getResult();
System.err.println("Cache was closed on integer " + lastSuccessfulInt);
AsyncInvocation create1 = createPRAsync(vm0, 1, -1, 1);
AsyncInvocation create2 = createPRAsync(vm1, 1, -1, 1);
create1.getResult(MAX_WAIT);
create2.getResult(MAX_WAIT);
SerializableCallable getValue = new SerializableCallable() {
public Object call() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
int value = (Integer) region.get(0);
return value;
}
};
int vm1Value = (Integer) vm0.invoke(getValue);
int vm2Value = (Integer) vm1.invoke(getValue);
assertEquals(vm1Value, vm2Value);
assertTrue("value = " + vm1Value + ", lastSuccessfulInt=" + lastSuccessfulInt, vm1Value == lastSuccessfulInt || vm1Value == lastSuccessfulInt + 1);
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class ConcurrentAsyncEventQueueDUnitTest method testReplicatedSerialAsyncEventQueueWithMultipleDispatcherThreadsOrderPolicyThread.
/**
* Test configuration::
*
* Region: Replicated WAN: Serial Dispatcher threads: more than 1 Order policy: Thread ordering
*/
@Test
public void testReplicatedSerialAsyncEventQueueWithMultipleDispatcherThreadsOrderPolicyThread() {
Integer lnPort = (Integer) vm0.invoke(() -> AsyncEventQueueTestBase.createFirstLocatorWithDSId(1));
vm1.invoke(() -> AsyncEventQueueTestBase.createCache(lnPort));
vm2.invoke(() -> AsyncEventQueueTestBase.createCache(lnPort));
vm3.invoke(() -> AsyncEventQueueTestBase.createCache(lnPort));
vm4.invoke(() -> AsyncEventQueueTestBase.createCache(lnPort));
vm1.invoke(() -> AsyncEventQueueTestBase.createConcurrentAsyncEventQueue("ln", false, 100, 10, true, false, null, false, 3, OrderPolicy.THREAD));
vm2.invoke(() -> AsyncEventQueueTestBase.createConcurrentAsyncEventQueue("ln", false, 100, 10, true, false, null, false, 3, OrderPolicy.THREAD));
vm3.invoke(() -> AsyncEventQueueTestBase.createConcurrentAsyncEventQueue("ln", false, 100, 10, true, false, null, false, 3, OrderPolicy.THREAD));
vm4.invoke(() -> AsyncEventQueueTestBase.createConcurrentAsyncEventQueue("ln", false, 100, 10, true, false, null, false, 3, OrderPolicy.THREAD));
vm1.invoke(() -> AsyncEventQueueTestBase.createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "ln", isOffHeap()));
vm2.invoke(() -> AsyncEventQueueTestBase.createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "ln", isOffHeap()));
vm3.invoke(() -> AsyncEventQueueTestBase.createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "ln", isOffHeap()));
vm4.invoke(() -> AsyncEventQueueTestBase.createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "ln", isOffHeap()));
AsyncInvocation inv1 = vm1.invokeAsync(() -> AsyncEventQueueTestBase.doPuts(getTestMethodName() + "_RR", 50));
AsyncInvocation inv2 = vm1.invokeAsync(() -> AsyncEventQueueTestBase.doNextPuts(getTestMethodName() + "_RR", 50, 100));
AsyncInvocation inv3 = vm1.invokeAsync(() -> AsyncEventQueueTestBase.doNextPuts(getTestMethodName() + "_RR", 100, 150));
try {
inv1.join();
inv2.join();
inv3.join();
} catch (InterruptedException ie) {
Assert.fail("Cought interrupted exception while waiting for the task tgo complete.", ie);
}
vm1.invoke(() -> AsyncEventQueueTestBase.waitForAsyncQueueToGetEmpty("ln"));
vm2.invoke(() -> AsyncEventQueueTestBase.waitForAsyncQueueToGetEmpty("ln"));
vm3.invoke(() -> AsyncEventQueueTestBase.waitForAsyncQueueToGetEmpty("ln"));
vm4.invoke(() -> AsyncEventQueueTestBase.waitForAsyncQueueToGetEmpty("ln"));
// primary
vm1.invoke(() -> AsyncEventQueueTestBase.validateAsyncEventListener("ln", 150));
// sender
// secondary
vm2.invoke(() -> AsyncEventQueueTestBase.validateAsyncEventListener("ln", 0));
// secondary
vm3.invoke(() -> AsyncEventQueueTestBase.validateAsyncEventListener("ln", 0));
// secondary
vm4.invoke(() -> AsyncEventQueueTestBase.validateAsyncEventListener("ln", 0));
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class AsyncEventQueueStatsDUnitTest method testReplicatedSerialPropagationHA.
/**
* HA scenario: kill one vm when puts are in progress on the other vm.
*/
@Test
public void testReplicatedSerialPropagationHA() throws Exception {
Integer lnPort = (Integer) vm0.invoke(() -> AsyncEventQueueTestBase.createFirstLocatorWithDSId(1));
vm1.invoke(() -> AsyncEventQueueTestBase.createCache(lnPort));
vm2.invoke(() -> AsyncEventQueueTestBase.createCache(lnPort));
vm3.invoke(() -> AsyncEventQueueTestBase.createCache(lnPort));
vm4.invoke(() -> AsyncEventQueueTestBase.createCache(lnPort));
vm1.invoke(() -> AsyncEventQueueTestBase.createAsyncEventQueue("ln", false, 100, 100, false, false, null, false));
vm2.invoke(() -> AsyncEventQueueTestBase.createAsyncEventQueue("ln", false, 100, 100, false, false, null, false));
vm1.invoke(() -> AsyncEventQueueTestBase.createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "ln", isOffHeap()));
vm2.invoke(() -> AsyncEventQueueTestBase.createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "ln", isOffHeap()));
vm3.invoke(() -> AsyncEventQueueTestBase.createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "ln", isOffHeap()));
vm4.invoke(() -> AsyncEventQueueTestBase.createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "ln", isOffHeap()));
AsyncInvocation inv1 = vm2.invokeAsync(() -> AsyncEventQueueTestBase.doPuts(getTestMethodName() + "_RR", 10000));
Wait.pause(2000);
AsyncInvocation inv2 = vm1.invokeAsync(() -> AsyncEventQueueTestBase.killAsyncEventQueue("ln"));
Boolean isKilled = Boolean.FALSE;
try {
isKilled = (Boolean) inv2.getResult();
} catch (Throwable e) {
fail("Unexpected exception while killing a AsyncEventQueue");
}
AsyncInvocation inv3 = null;
if (!isKilled) {
inv3 = vm2.invokeAsync(() -> AsyncEventQueueTestBase.killSender("ln"));
inv3.join();
}
inv1.join();
inv2.join();
// give some time for system to become stable
Wait.pause(2000);
vm2.invoke(() -> AsyncEventQueueTestBase.checkAsyncEventQueueStats_Failover("ln", 10000));
}
Aggregations