use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ListDiskStoresFunctionJUnitTest method testExecuteOnMemberWithANonGemFireCache.
@Test
@SuppressWarnings("unchecked")
public void testExecuteOnMemberWithANonGemFireCache() throws Throwable {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache);
function.execute(mockFunctionContext);
final List<?> results = testResultSender.getResults();
assertNotNull(results);
assertEquals(1, results.size());
final Set<DiskStoreDetails> diskStoreDetails = (Set<DiskStoreDetails>) results.get(0);
assertNotNull(diskStoreDetails);
assertTrue(diskStoreDetails.isEmpty());
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ListDiskStoresFunctionJUnitTest method testExecuteThrowsRuntimeException.
@Test(expected = RuntimeException.class)
public void testExecuteThrowsRuntimeException() throws Throwable {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
final InternalDistributedMember mockMember = mockContext.mock(InternalDistributedMember.class, "DistributedMember");
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getMyId();
will(returnValue(mockMember));
oneOf(mockCache).listDiskStoresIncludingRegionOwned();
will(throwException(new RuntimeException("expected")));
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache);
function.execute(mockFunctionContext);
try {
testResultSender.getResults();
} catch (Throwable throwable) {
assertTrue(throwable instanceof RuntimeException);
assertEquals("expected", throwable.getMessage());
throw throwable;
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ListIndexFunctionJUnitTest method testExecuteThrowsException.
@Test(expected = RuntimeException.class)
public void testExecuteThrowsException() throws Throwable {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final QueryService mockQueryService = mockContext.mock(QueryService.class, "QueryService");
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getDistributedSystem();
will(returnValue(mockDistributedSystem));
oneOf(mockCache).getQueryService();
will(returnValue(mockQueryService));
oneOf(mockDistributedSystem).getDistributedMember();
will(returnValue(mockDistributedMember));
oneOf(mockQueryService).getIndexes();
will(throwException(new RuntimeException("expected")));
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final ListIndexFunction function = createListIndexFunction(mockCache);
function.execute(mockFunctionContext);
try {
testResultSender.getResults();
} catch (Throwable t) {
assertTrue(t instanceof RuntimeException);
assertEquals("expected", t.getMessage());
throw t;
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ExportLogsFunctionIntegrationTest method verifyExportLogsFunctionDoesNotBlowUp.
public static void verifyExportLogsFunctionDoesNotBlowUp() throws Throwable {
ExportLogsFunction.Args args = new ExportLogsFunction.Args(null, null, "info", false, false, false);
CapturingResultSender resultSender = new CapturingResultSender();
FunctionContext context = new FunctionContextImpl("functionId", args, resultSender);
new ExportLogsFunction().execute(context);
if (resultSender.getThrowable() != null) {
throw resultSender.getThrowable();
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class FunctionServiceStatsDUnitTest method testP2PMembersFunctionExecutionStats.
/**
* Test the execution of function on all memebers haveResults = true
*
* member1 calls for the function executions sp the results received on memeber 1 should be equal
* to the no of function execution calls. Function Execution should happen on all other members
* too. so the no of function execution calls and no of function executions completed should be
* equal tio the no of functions from member 1
*/
@Test
public void testP2PMembersFunctionExecutionStats() throws Exception {
Host host = Host.getHost(0);
VM member1 = host.getVM(0);
VM member2 = host.getVM(1);
VM member3 = host.getVM(2);
VM member4 = host.getVM(3);
SerializableCallable connectToDistributedSystem = new SerializableCallable("connectToDistributedSystem") {
public Object call() throws Exception {
Properties props = new Properties();
try {
ds = getSystem(props);
assertNotNull(ds);
} catch (Exception e) {
Assert.fail("Failed while creating the Distribued System", e);
}
return Boolean.TRUE;
}
};
member1.invoke(connectToDistributedSystem);
member2.invoke(connectToDistributedSystem);
member3.invoke(connectToDistributedSystem);
member4.invoke(connectToDistributedSystem);
member1.invoke(initializeStats);
member2.invoke(initializeStats);
member3.invoke(initializeStats);
member4.invoke(initializeStats);
final int noOfMembers = 1;
final Function inlineFunction = new FunctionAdapter() {
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
} else {
context.getResultSender().lastResult("Failure");
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return true;
}
};
member1.invoke(new SerializableCallable("excuteOnMembers_InlineFunction") {
public Object call() throws Exception {
assertNotNull(ds);
Execution memberExecution = null;
DistributedMember localmember = ds.getDistributedMember();
memberExecution = FunctionService.onMember(localmember);
memberExecution.setArguments("Key");
try {
ResultCollector rc = memberExecution.execute(inlineFunction);
int size = ((List) rc.getResult()).size();
resultReceived_Aggregate += size;
noOfExecutionCalls_Aggregate++;
noOfExecutionsCompleted_Aggregate++;
resultReceived_Inline += size;
noOfExecutionCalls_Inline++;
noOfExecutionsCompleted_Inline++;
} catch (Exception e) {
LogWriterUtils.getLogWriter().info("Exception Occurred : " + e.getMessage());
e.printStackTrace();
Assert.fail("Test failed", e);
}
return Boolean.TRUE;
}
});
member1.invoke(new SerializableCallable("checkFunctionExecutionStatsForMember1") {
public Object call() throws Exception {
FunctionServiceStats functionServiceStats = ds.getFunctionServiceStats();
waitNoFunctionsRunning(functionServiceStats);
assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
assertEquals(resultReceived_Aggregate, functionServiceStats.getResultsReceived());
FunctionStats functionStats = FunctionStats.getFunctionStats(inlineFunction.getId(), ds);
assertEquals(noOfExecutionCalls_Inline, functionStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Inline, functionStats.getFunctionExecutionsCompleted());
assertEquals(resultReceived_Inline, functionStats.getResultsReceived());
return Boolean.TRUE;
}
});
SerializableCallable checkFunctionExecutionStatsForOtherMember = new SerializableCallable("checkFunctionExecutionStatsForOtherMember") {
public Object call() throws Exception {
FunctionServiceStats functionServiceStats = ds.getFunctionServiceStats();
waitNoFunctionsRunning(functionServiceStats);
// One function Execution took place on there members
// noOfExecutionCalls_Aggregate++;
// noOfExecutionsCompleted_Aggregate++;
assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
FunctionStats functionStats = FunctionStats.getFunctionStats(inlineFunction.getId(), ds);
// noOfExecutionCalls_Inline++;
// noOfExecutionsCompleted_Inline++;
assertEquals(noOfExecutionCalls_Inline, functionStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Inline, functionStats.getFunctionExecutionsCompleted());
return Boolean.TRUE;
}
};
member2.invoke(checkFunctionExecutionStatsForOtherMember);
member3.invoke(checkFunctionExecutionStatsForOtherMember);
member4.invoke(checkFunctionExecutionStatsForOtherMember);
SerializableCallable closeDistributedSystem = new SerializableCallable("closeDistributedSystem") {
public Object call() throws Exception {
if (getCache() != null && !getCache().isClosed()) {
getCache().close();
getCache().getDistributedSystem().disconnect();
}
return Boolean.TRUE;
}
};
member1.invoke(closeDistributedSystem);
member2.invoke(closeDistributedSystem);
member3.invoke(closeDistributedSystem);
member4.invoke(closeDistributedSystem);
}
Aggregations