use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class MyFunctionException method executeInlineFunction.
public static void executeInlineFunction() {
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(1, list.size());
assertEquals(Boolean.TRUE, list.get(0));
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ClientServerFunctionExecutionDUnitTest method serverExecution_Inline_InvalidAttributes.
public static void serverExecution_Inline_InvalidAttributes() {
DistributedSystem.setThreadsSocketPolicy(false);
Execution member = FunctionService.onServer(pool);
try {
ResultCollector rs = member.setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
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);
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return false;
}
public boolean isHA() {
return true;
}
});
fail("Should have failed with Invalid attributes.");
} catch (Exception ex) {
LogWriterUtils.getLogWriter().info("Exception : ", ex);
assertTrue(ex.getMessage().contains("For Functions with isHA true, hasResult must also be true."));
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest 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);
}
HashMap resultMap = (HashMap) FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
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);
}
}
public String getId() {
return "Function";
}
public boolean hasResult() {
return true;
}
}).getResult();
assertEquals(3, resultMap.size());
Iterator mapIterator = resultMap.entrySet().iterator();
Map.Entry entry = null;
DistributedMember key = null;
ArrayList resultListForMember = null;
while (mapIterator.hasNext()) {
entry = (Map.Entry) mapIterator.next();
key = (DistributedMember) entry.getKey();
resultListForMember = (ArrayList) entry.getValue();
for (Object result : resultListForMember) {
assertEquals(Boolean.TRUE, result);
}
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest 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);
}
HashMap resultMap = (HashMap) FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
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);
}
}
public String getId() {
return "Function";
}
public boolean hasResult() {
return true;
}
}).getResult();
assertEquals(3, resultMap.size());
Iterator mapIterator = resultMap.entrySet().iterator();
Map.Entry entry = null;
DistributedMember key = null;
ArrayList resultListForMember = null;
while (mapIterator.hasNext()) {
entry = (Map.Entry) mapIterator.next();
key = (DistributedMember) entry.getKey();
resultListForMember = (ArrayList) entry.getValue();
for (Object result : resultListForMember) {
assertEquals(Boolean.TRUE, result);
}
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class SizeExportLogsFunctionTest method sizeGreaterThanDiskAvailable_sendsErrorResult.
@Test
public void sizeGreaterThanDiskAvailable_sendsErrorResult() throws Throwable {
server.withProperties(config).startServer();
FunctionContext context = new FunctionContextImpl("functionId", nonFilteringArgs, resultSender);
SizeExportLogsFunction testFunction = new SizeExportLogsFunction();
SizeExportLogsFunction spyFunction = spy(testFunction);
long fakeDiskAvailable = 1024;
doReturn(fakeDiskAvailable).when(spyFunction).getDiskAvailable(Matchers.any(DistributionConfig.class));
spyFunction.execute(context);
assertThatThrownBy(resultSender::getResults).isInstanceOf(ManagementException.class);
}
Aggregations