use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class GemFireDeadlockDetectorDUnitTest method testDistributedDeadlockWithFunction.
// @Category(FlakyTest.class) // GEODE-516 & GEODE-576: async actions, thread sleeps, time
// sensitive
@Test
public void testDistributedDeadlockWithFunction() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
getSystem();
InternalDistributedMember member1 = createCache(vm0);
final InternalDistributedMember member2 = createCache(vm1);
getBlackboard().initBlackboard();
// Have two threads lock locks on different members in different orders.
String gateOnMember1 = "gateOnMember1";
String gateOnMember2 = "gateOnMember2";
// This thread locks the lock member1 first, then member2.
AsyncInvocation async1 = lockTheLocks(vm0, member2, gateOnMember1, gateOnMember2);
// This thread locks the lock member2 first, then member1.
AsyncInvocation async2 = lockTheLocks(vm1, member1, gateOnMember2, gateOnMember1);
try {
final LinkedList<Dependency>[] deadlockHolder = new LinkedList[1];
Awaitility.await("waiting for deadlock").atMost(20, TimeUnit.SECONDS).until(() -> {
GemFireDeadlockDetector detect = new GemFireDeadlockDetector();
LinkedList<Dependency> deadlock = detect.find().findCycle();
if (deadlock != null) {
deadlockHolder[0] = deadlock;
}
return deadlock != null;
});
LinkedList<Dependency> deadlock = deadlockHolder[0];
LogWriterUtils.getLogWriter().info("Deadlock=" + DeadlockDetector.prettyFormat(deadlock));
assertEquals(8, deadlock.size());
stopStuckThreads();
} finally {
try {
waitForAsyncInvocation(async1, 45, TimeUnit.SECONDS);
} finally {
waitForAsyncInvocation(async2, 45, TimeUnit.SECONDS);
}
}
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class MyFunctionException method testServerFailoverWithTwoServerAliveHA.
/*
* Ensure that the while executing the function if the servers is down then the execution is
* failover to other available server
*/
@Test
public void testServerFailoverWithTwoServerAliveHA() throws InterruptedException {
VM emptyServer1 = replicate1;
VM client = normal;
emptyServer1.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createCacheInVm());
replicate2.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createCacheInVm());
replicate3.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createCacheInVm());
client.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createCacheInClientVm());
Integer port1 = (Integer) emptyServer1.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createServer(DataPolicy.EMPTY));
Integer port2 = (Integer) replicate2.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createServer(DataPolicy.REPLICATE));
replicate3.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createPeer(DataPolicy.REPLICATE));
client.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createClientAndPopulateClientRegion(DataPolicy.EMPTY, port1, port2));
replicate2.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.stopServerHA());
int AsyncInvocationArrSize = 1;
AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
async[0] = client.invokeAsync(() -> DistributedRegionFunctionExecutionDUnitTest.executeFunctionHA());
replicate2.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.startServerHA());
emptyServer1.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.closeCacheHA());
ThreadUtils.join(async[0], 4 * 60 * 1000);
if (async[0].getException() != null) {
Assert.fail("UnExpected Exception Occurred : ", async[0].getException());
}
List l = (List) async[0].getReturnValue();
assertEquals(5001, l.size());
for (int i = 0; i < 5001; i++) {
assertEquals(l.get(i), Boolean.TRUE);
}
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class MyFunctionException method testDistributedRegionFunctionExecutionHANodeFailure.
@Test
public void testDistributedRegionFunctionExecutionHANodeFailure() {
VM empty = normal;
empty.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createCacheInVm());
replicate1.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createCacheInVm());
empty.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createPeer(DataPolicy.EMPTY));
replicate1.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createPeer(DataPolicy.REPLICATE));
empty.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.populateRegion());
int AsyncInvocationArrSize = 1;
AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
async[0] = empty.invokeAsync(() -> DistributedRegionFunctionExecutionDUnitTest.executeFunctionHA());
replicate2.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createCacheInVm());
replicate2.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.createPeer(DataPolicy.REPLICATE));
replicate1.invoke(() -> DistributedRegionFunctionExecutionDUnitTest.disconnect());
ThreadUtils.join(async[0], 50 * 1000);
if (async[0].getException() != null) {
Assert.fail("UnExpected Exception Occurred : ", async[0].getException());
}
List l = (List) async[0].getReturnValue();
assertEquals(5001, l.size());
for (int i = 0; i < 5001; i++) {
assertEquals(l.get(i), Boolean.TRUE);
}
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PRClientServerRegionFunctionExecutionFailoverDUnitTest method testServerFailoverWithTwoServerAliveHA.
/*
* Ensure that the while executing the function if the servers is down then the execution is
* failover to other available server
*/
@Test
public void testServerFailoverWithTwoServerAliveHA() throws InterruptedException {
IgnoredException.addIgnoredException("FunctionInvocationTargetException");
ArrayList commonAttributes = createCommonServerAttributes("TestPartitionedRegion", null, 1, 13, null);
createClientServerScenarion(commonAttributes, 20, 20, 20);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_HA);
registerFunctionAtServer(function);
server2.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.stopServerHA());
server3.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.stopServerHA());
client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.putOperation());
int AsyncInvocationArrSize = 1;
AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
async[0] = client.invokeAsync(() -> PRClientServerRegionFunctionExecutionDUnitTest.executeFunctionHA());
server2.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.startServerHA());
server3.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.startServerHA());
server1.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.stopServerHA());
client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.verifyDeadAndLiveServers(new Integer(1), new Integer(2)));
ThreadUtils.join(async[0], 6 * 60 * 1000);
if (async[0].getException() != null) {
Assert.fail("UnExpected Exception Occurred : ", async[0].getException());
}
List l = (List) async[0].getReturnValue();
assertEquals(2, l.size());
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method testServerCacheClosedFailoverWithTwoServerAliveHA.
/*
* Ensure that the while executing the function if the servers is down then the execution is
* failover to other available server
*/
@Test
public void testServerCacheClosedFailoverWithTwoServerAliveHA() throws InterruptedException {
IgnoredException.addIgnoredException("FunctionInvocationTargetException");
IgnoredException.addIgnoredException("Connection reset");
IgnoredException.addIgnoredException("SocketTimeoutException");
IgnoredException.addIgnoredException("ServerConnectivityException");
IgnoredException.addIgnoredException("Socket Closed");
ArrayList commonAttributes = createCommonServerAttributes("TestPartitionedRegion", null, 1, 13, null);
createClientServerScenarion(commonAttributes, 20, 20, 20);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_HA);
registerFunctionAtServer(function);
server2.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.stopServerHA());
server3.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.stopServerHA());
client.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.putOperation());
int AsyncInvocationArrSize = 1;
AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
async[0] = client.invokeAsync(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.executeFunctionHA());
server2.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.startServerHA());
server3.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.startServerHA());
server1.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.closeCacheHA());
client.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.verifyDeadAndLiveServers(new Integer(1), new Integer(2)));
ThreadUtils.join(async[0], 5 * 60 * 1000);
if (async[0].getException() != null) {
Assert.fail("UnExpected Exception Occurred : ", async[0].getException());
}
List l = (List) async[0].getReturnValue();
assertEquals(2, l.size());
}
Aggregations