use of org.apache.geode.cache.execute.Execution 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.Execution 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.Execution 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.Execution in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method testP2PMemberFailure.
@Test
public void testP2PMemberFailure() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final String regionName = getName();
initVM(vm0, "g0,mg", regionName, false);
initVM(vm1, "g1", regionName, false);
initVM(vm2, "g0,g1,g2", regionName, false);
vm0.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
DistributedSystem ds = getSystem();
Execution e1 = FunctionService.onMembers("g1");
ArrayList<String> args = new ArrayList<String>();
args.add("shutdown");
e1 = e1.setArguments(args);
try {
e1.execute(new OnGroupsExceptionFunction()).getResult();
fail("expected exception not thrown");
} catch (FunctionException ex) {
assertTrue(ex.getCause() instanceof FunctionInvocationTargetException);
}
return null;
}
});
}
use of org.apache.geode.cache.execute.Execution in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method testP2PException.
@Test
public void testP2PException() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final String regionName = getName();
// The test function deliberately throws a null pointer exception.
// which is logged.
IgnoredException.addIgnoredException(NullPointerException.class.getSimpleName());
initVM(vm0, "g0,mg", regionName, false);
initVM(vm1, "g1", regionName, false);
initVM(vm2, "g0,g1,g2", regionName, false);
vm0.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
DistributedSystem ds = getSystem();
Execution e = FunctionService.onMembers("mg");
ArrayList<String> args = new ArrayList<String>();
args.add("runtime");
e = e.setArguments(args);
try {
e.execute(new OnGroupsExceptionFunction()).getResult();
fail("expected exception not thrown");
} catch (FunctionException ex) {
assertTrue(ex.getCause() instanceof NullPointerException);
}
Execution e1 = FunctionService.onMembers("g1");
e1 = e1.setArguments(args);
try {
e1.execute(new OnGroupsExceptionFunction()).getResult();
fail("expected exception not thrown");
} catch (FunctionException ex) {
assertTrue(ex.getCause() instanceof NullPointerException);
}
// fail on only one member
Execution e2 = FunctionService.onMembers("g1");
args.add("g2");
e2 = e2.setArguments(args);
try {
e2.execute(new OnGroupsExceptionFunction()).getResult();
fail("expected exception not thrown");
} catch (FunctionException ex) {
assertTrue(ex.getCause() instanceof NullPointerException);
}
return null;
}
});
}
Aggregations