use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest 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 {
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(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.stopServerHA());
server3.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.stopServerHA());
client.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.putOperation());
int AsyncInvocationArrSize = 1;
AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
async[0] = client.invokeAsync(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.executeFunctionHA());
server2.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.startServerHA());
server3.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.startServerHA());
server1.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.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.internal.cache.functions.TestFunction in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverSingleKeyExecution.
public static void serverSingleKeyExecution(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final String testKey = "execKey";
final Set testKeysSet = new HashSet();
testKeysSet.add(testKey);
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TEST_FUNCTION2);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
} catch (Exception expected) {
assertTrue(expected.getMessage().contains("No target node found for KEY = " + testKey) || expected.getMessage().startsWith("Server could not send the reply") || expected.getMessage().startsWith("Unexpected exception during"));
}
region.put(testKey, new Integer(1));
try {
ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
ResultCollector rs2 = execute(dataSet, testKeysSet, testKey, function, isByName);
assertEquals(new Integer(1), ((List) rs2.getResult()).get(0));
HashMap putData = new HashMap();
putData.put(testKey + "1", new Integer(2));
putData.put(testKey + "2", new Integer(3));
ResultCollector rs1 = execute(dataSet, testKeysSet, putData, function, isByName);
assertEquals(Boolean.TRUE, ((List) rs1.getResult()).get(0));
assertEquals(new Integer(2), region.get(testKey + "1"));
assertEquals(new Integer(3), region.get(testKey + "2"));
} catch (Exception ex) {
ex.printStackTrace();
LogWriterUtils.getLogWriter().info("Exception : ", ex);
Assert.fail("Test failed after the put operation", ex);
}
}
use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverMultiKeyExecutionSocketTimeOut.
public static void serverMultiKeyExecutionSocketTimeOut(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
List l = null;
ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
l = ((List) rc1.getResult());
LogWriterUtils.getLogWriter().info("Result size : " + l.size());
assertEquals(3, l.size());
for (Iterator i = l.iterator(); i.hasNext(); ) {
assertEquals(Boolean.TRUE, i.next());
}
} catch (Exception e) {
Assert.fail("Test failed after the function execution", e);
}
}
use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverSingleKeyExecutionSocketTimeOut.
public static void serverSingleKeyExecutionSocketTimeOut(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final String testKey = "execKey";
final Set testKeysSet = new HashSet();
testKeysSet.add(testKey);
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
region.put(testKey, new Integer(1));
try {
ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
ResultCollector rs2 = execute(dataSet, testKeysSet, testKey, function, isByName);
assertEquals(testKey, ((List) rs2.getResult()).get(0));
} catch (Exception ex) {
ex.printStackTrace();
LogWriterUtils.getLogWriter().info("Exception : ", ex);
Assert.fail("Test failed after the put operation", ex);
}
}
use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method testserverMultiKeyExecution_byName.
/*
* Execution of the function on server with set multiple keys as the routing object and using the
* name of the function
*/
@Test
public void testserverMultiKeyExecution_byName() {
createScenario();
Function function = new TestFunction(true, TEST_FUNCTION2);
registerFunctionAtServer(function);
isByName = new Boolean(true);
client.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.serverMultiKeyExecution(isByName));
server1.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.checkBucketsOnServer());
server2.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.checkBucketsOnServer());
server3.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.checkBucketsOnServer());
}
Aggregations