use of org.apache.geode.cache.execute.Function in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method serverMultiKeyExecutionNoResult.
public static void serverMultiKeyExecutionNoResult(Boolean isByName) throws Exception {
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(false, TEST_FUNCTION7);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
String msg = "<ExpectedException action=add>" + "FunctionException" + "</ExpectedException>";
cache.getLogger().info(msg);
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);
}
ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
rc1.getResult();
Thread.sleep(20000);
fail("Test failed after the put operation");
} catch (FunctionException expected) {
assertTrue(expected.getMessage().startsWith((LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("return any"))));
} finally {
cache.getLogger().info("<ExpectedException action=remove>" + "FunctionException" + "</ExpectedException>");
}
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method testClientWithoutPool_Bug41832.
@Test
public void testClientWithoutPool_Bug41832() {
createScenarioWith2Regions();
Function function = new TestFunction(true, TEST_FUNCTION2);
registerFunctionAtServer(function);
isByName = new Boolean(true);
toRegister = new Boolean(true);
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.serverSingleKeyExecutionWith2Regions(isByName, toRegister));
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);
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method serverSingleKeyExecution_NoLastResult.
public static void serverSingleKeyExecution_NoLastResult(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, TestFunction.TEST_FUNCTION_NO_LASTRESULT);
if (toRegister.booleanValue()) {
FunctionService.registerFunction(function);
} else {
FunctionService.unregisterFunction(function.getId());
assertNull(FunctionService.getFunction(function.getId()));
}
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));
fail("Expected FunctionException : Function did not send last result");
} catch (Exception ex) {
if (!ex.getMessage().contains("did not send last result")) {
throw ex;
}
}
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method serverMultiKeyExecution_SendException.
public static void serverMultiKeyExecution_SendException(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_SEND_EXCEPTION);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
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);
}
try {
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(); ) {
assertTrue(i.next() instanceof MyFunctionExecutionException);
}
} catch (Exception ex) {
ex.printStackTrace();
fail("No Exception Expected");
}
try {
List l = null;
ResultCollector rc1 = execute(dataSet, testKeysSet, testKeysSet, function, isByName);
List resultList = (List) rc1.getResult();
assertEquals(((testKeysSet.size() * 3) + 3), resultList.size());
Iterator resultIterator = resultList.iterator();
int exceptionCount = 0;
while (resultIterator.hasNext()) {
Object o = resultIterator.next();
if (o instanceof MyFunctionExecutionException) {
exceptionCount++;
}
}
assertEquals(3, exceptionCount);
} catch (Exception ex) {
ex.printStackTrace();
fail("No Exception Expected");
}
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method testServerSingleKeyExecution_SendException.
@Test
public void testServerSingleKeyExecution_SendException() {
createScenario();
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SEND_EXCEPTION);
registerFunctionAtServer(function);
isByName = new Boolean(true);
toRegister = new Boolean(true);
client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.serverSingleKeyExecution_SendException(isByName, toRegister));
}
Aggregations