use of org.apache.geode.cache.execute.Function in project geode by apache.
the class MyFunctionException method executeFunction_NoResult.
public static void executeFunction_NoResult() {
Function function = new TestFunction(false, TestFunction.TEST_FUNCTION1);
Execution dataset = FunctionService.onRegion(region);
dataset.execute(function);
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class MyFunctionException method registerFunction.
public static void registerFunction(Boolean isHA, Integer retryCount) {
Function function = new DistribuedRegionFunctionFunctionInvocationException(isHA.booleanValue(), retryCount.intValue());
FunctionService.registerFunction(function);
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method serverSingleKeyExecution.
public static void serverSingleKeyExecution(Boolean isByName, Boolean toRegister) throws Exception {
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);
if (toRegister.booleanValue()) {
FunctionService.registerFunction(function);
} else {
FunctionService.unregisterFunction(function.getId());
assertNull(FunctionService.getFunction(function.getId()));
}
Execution dataSet = FunctionService.onRegion(region);
try {
execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
} catch (Exception ex) {
if (!(ex.getMessage().contains("No target node found for KEY = " + testKey) || ex.getMessage().startsWith("Server could not send the reply") || ex.getMessage().startsWith("Unexpected exception during"))) {
throw ex;
}
}
region.put(testKey, new Integer(1));
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"));
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method testBucketFilterOverride.
@Test
public void testBucketFilterOverride() {
createScenarioForBucketFilter();
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_BUCKET_FILTER);
registerFunctionAtServer(function);
// test multi key filter
Set<Integer> bucketFilterSet = new HashSet<Integer>();
bucketFilterSet.add(3);
bucketFilterSet.add(6);
bucketFilterSet.add(8);
Set<Integer> keyFilterSet = new HashSet<Integer>();
keyFilterSet.add(75);
keyFilterSet.add(25);
client.invoke(() -> PRClientServerTestBase.serverBucketFilterOverrideExecution(bucketFilterSet, keyFilterSet));
}
use of org.apache.geode.cache.execute.Function 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());
}
Aggregations