use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method FunctionExecution_Inline_Bug40714.
public static void FunctionExecution_Inline_Bug40714() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
int j = 0;
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
region.put(i.next(), val);
}
List list = (List) FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
@Override
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
} else if (context.getArguments() instanceof Boolean) {
context.getResultSender().lastResult(Boolean.TRUE);
}
}
@Override
public String getId() {
return "Function";
}
@Override
public boolean hasResult() {
return true;
}
}).getResult();
assertEquals(3, list.size());
Iterator iterator = list.iterator();
for (int i = 0; i < 3; i++) {
Boolean res = (Boolean) iterator.next();
assertEquals(Boolean.TRUE, res);
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method serverSingleKeyExecution_Inline.
public static void serverSingleKeyExecution_Inline() throws Exception {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final String testKey = "execKey";
final Set testKeysSet = new HashSet();
testKeysSet.add(testKey);
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
try {
cache.getLogger().info("<ExpectedException action=add>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
@Override
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
}
context.getResultSender().lastResult("Failure");
}
@Override
public String getId() {
return getClass().getName();
}
@Override
public boolean hasResult() {
return true;
}
});
} 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;
}
} finally {
cache.getLogger().info("<ExpectedException action=remove>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
}
region.put(testKey, new Integer(1));
ResultCollector rs = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
@Override
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
} else {
context.getResultSender().lastResult("Failure");
}
}
@Override
public String getId() {
return getClass().getName();
}
@Override
public boolean hasResult() {
return true;
}
});
assertEquals("Failure", ((List) rs.getResult()).get(0));
ResultCollector rs2 = dataSet.withFilter(testKeysSet).setArguments(testKey).execute(new FunctionAdapter() {
@Override
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
} else {
context.getResultSender().lastResult("Failure");
}
}
@Override
public String getId() {
return getClass().getName();
}
@Override
public boolean hasResult() {
return true;
}
});
assertEquals("Success", ((List) rs2.getResult()).get(0));
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class MemberFunctionExecutionDUnitTest method bug41118.
public static void bug41118() {
ds = new MemberFunctionExecutionDUnitTest().getSystem();
assertNotNull(ds);
ds.disconnect();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
ds = (InternalDistributedSystem) DistributedSystem.connect(props);
DM dm = ds.getDistributionManager();
assertEquals("Distributed System is not loner", true, dm instanceof LonerDistributionManager);
DistributedMember localmember = ds.getDistributedMember();
Execution memberExcution = null;
memberExcution = FunctionService.onMember(localmember);
Execution executor = memberExcution.setArguments("Key");
try {
ResultCollector rc = executor.execute(new FunctionAdapter() {
@Override
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
} else {
context.getResultSender().lastResult("Failure");
}
}
@Override
public String getId() {
return getClass().getName();
}
@Override
public boolean hasResult() {
return true;
}
});
List li = (ArrayList) rc.getResult();
LogWriterUtils.getLogWriter().info("MemberFunctionExecutionDUnitTest#excuteOnMembers: Result : " + li);
assertEquals(li.size(), 1);
for (Object obj : li) {
assertEquals(obj, "Success");
}
ds.disconnect();
} catch (Exception e) {
LogWriterUtils.getLogWriter().info("Exception Occurred : " + e.getMessage());
e.printStackTrace();
Assert.fail("Test failed", e);
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class MemberFunctionExecutionDUnitTest method testBug46129.
@Test
public void testBug46129() throws Exception {
Properties props = new Properties();
member1.invoke(() -> MemberFunctionExecutionDUnitTest.connectToDistributedSystem(props));
member2.invoke(() -> MemberFunctionExecutionDUnitTest.connectToDistributedSystem(props));
member3.invoke(() -> MemberFunctionExecutionDUnitTest.connectToDistributedSystem(props));
member4.invoke(() -> MemberFunctionExecutionDUnitTest.connectToDistributedSystem(props));
connectToDistributedSystem(props);
AbstractExecution exe = (AbstractExecution) FunctionService.onMembers();
exe.setIgnoreDepartedMembers(true);
ResultCollector rs = exe.execute(new FunctionAdapter() {
@Override
public void execute(FunctionContext context) {
try {
Object arg = context.getArguments();
if (arg != null && arg instanceof Map) {
context.getResultSender().lastResult("ok");
} else {
throw new IllegalArgumentException("dummy");
}
} catch (Exception e) {
context.getResultSender().sendException(e);
}
}
@Override
public String getId() {
return "testBug46129";
}
});
List resultList = (List) rs.getResult();
Exception e = (Exception) resultList.get(0);
assertTrue(e instanceof IllegalArgumentException);
IllegalArgumentException ex = (IllegalArgumentException) e;
assertEquals("dummy", ex.getMessage());
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method serverBug43430.
public static void serverBug43430() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final String testKey = "execKey";
final Set testKeysSet = new HashSet();
testKeysSet.add(testKey);
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
region.put(testKey, new Integer(1));
try {
cache.getLogger().info("<ExpectedException action=add>" + "Could not create an instance of org.apache.geode.internal.cache.execute.PRClientServerRegionFunctionExecutionDUnitTest$UnDeserializable" + "</ExpectedException>");
dataSet.withFilter(testKeysSet).setArguments(new UnDeserializable()).execute(new FunctionAdapter() {
@Override
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
}
context.getResultSender().lastResult("Failure");
}
@Override
public String getId() {
return getClass().getName();
}
@Override
public boolean hasResult() {
return true;
}
});
} catch (Exception expected) {
if (!expected.getCause().getMessage().contains("Could not create an instance of org.apache.geode.internal.cache.execute.PRClientServerRegionFunctionExecutionDUnitTest$UnDeserializable")) {
throw expected;
}
;
} finally {
cache.getLogger().info("<ExpectedException action=remove>" + "Could not create an instance of org.apache.geode.internal.cache.execute.PRClientServerRegionFunctionExecutionDUnitTest$UnDeserializable" + "</ExpectedException>");
}
}
Aggregations