use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class SizeExportLogsFunctionTest method noFiles_returnsZeroResult.
@Test
public void noFiles_returnsZeroResult() throws Throwable {
config.setProperty(LOG_FILE, "");
config.setProperty(STATISTIC_ARCHIVE_FILE, "");
server.withProperties(config).startServer();
FunctionContext context = new FunctionContextImpl("functionId", nonFilteringArgs, resultSender);
new SizeExportLogsFunction().execute(context);
getAndVerifySizeEstimate(resultSender, 0L);
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class SizeExportLogsFunctionTest method withFiles_returnsCombinedSizeResult.
@Test
public void withFiles_returnsCombinedSizeResult() throws Throwable {
config.setProperty(LOG_FILE, logFile.getAbsolutePath());
config.setProperty(STATISTIC_ARCHIVE_FILE, statFile.getAbsolutePath());
server.withProperties(config).startServer();
FunctionContext context = new FunctionContextImpl("functionId", nonFilteringArgs, resultSender);
// log and stat files sizes are not constant with a real cache running, so check for the sizer
// estimate within a range
long initialFileSizes = FileUtils.sizeOf(logFile) + FileUtils.sizeOf(statFile);
new SizeExportLogsFunction().execute(context);
long finalFileSizes = FileUtils.sizeOf(logFile) + FileUtils.sizeOf(statFile);
getAndVerifySizeEstimate(resultSender, initialFileSizes, finalFileSizes);
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class LuceneListIndexFunctionJUnitTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
GemFireCacheImpl cache = Fakes.cache();
final String serverName = "mockServer";
LuceneServiceImpl service = mock(LuceneServiceImpl.class);
when(cache.getService(InternalLuceneService.class)).thenReturn(service);
FunctionContext context = mock(FunctionContext.class);
ResultSender resultSender = mock(ResultSender.class);
when(context.getResultSender()).thenReturn(resultSender);
LuceneIndexImpl index1 = getMockLuceneIndex("index1");
LuceneIndexImpl index2 = getMockLuceneIndex("index2");
TreeSet expectedResult = new TreeSet();
expectedResult.add(new LuceneIndexDetails(index1, serverName));
expectedResult.add(new LuceneIndexDetails(index2, serverName));
ArrayList<LuceneIndex> allIndexes = new ArrayList();
allIndexes.add(index1);
allIndexes.add(index2);
when(service.getAllIndexes()).thenReturn(allIndexes);
LuceneListIndexFunction function = new LuceneListIndexFunction();
function = spy(function);
Mockito.doReturn(cache).when(function).getCache();
function.execute(context);
ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class);
verify(resultSender).lastResult(resultCaptor.capture());
Set<String> result = resultCaptor.getValue();
assertEquals(2, result.size());
assertEquals(expectedResult, result);
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class LuceneDescribeIndexFunctionJUnitTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
GemFireCacheImpl cache = Fakes.cache();
final String serverName = "mockServer";
LuceneServiceImpl service = mock(LuceneServiceImpl.class);
when(cache.getService(InternalLuceneService.class)).thenReturn(service);
FunctionContext context = mock(FunctionContext.class);
ResultSender resultSender = mock(ResultSender.class);
LuceneIndexInfo indexInfo = getMockLuceneInfo("index1");
LuceneIndexImpl index1 = getMockLuceneIndex("index1");
LuceneDescribeIndexFunction function = spy(LuceneDescribeIndexFunction.class);
doReturn(indexInfo).when(context).getArguments();
doReturn(resultSender).when(context).getResultSender();
doReturn(cache).when(function).getCache();
when(service.getIndex(indexInfo.getIndexName(), indexInfo.getRegionPath())).thenReturn(index1);
function.execute(context);
ArgumentCaptor<LuceneIndexDetails> resultCaptor = ArgumentCaptor.forClass(LuceneIndexDetails.class);
verify(resultSender).lastResult(resultCaptor.capture());
LuceneIndexDetails result = resultCaptor.getValue();
LuceneIndexDetails expected = new LuceneIndexDetails(index1, "mockServer");
assertEquals(expected.getIndexName(), result.getIndexName());
assertEquals(expected.getRegionPath(), result.getRegionPath());
assertEquals(expected.getIndexStats(), result.getIndexStats());
assertEquals(expected.getFieldAnalyzersString(), result.getFieldAnalyzersString());
assertEquals(expected.getSearchableFieldNamesString(), result.getSearchableFieldNamesString());
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ClientServerFunctionExecutionDUnitTest method serverExecution_Inline.
public static void serverExecution_Inline() {
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 true;
}
});
assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
} catch (Exception ex) {
ex.printStackTrace();
LogWriterUtils.getLogWriter().info("Exception : ", ex);
fail("Test failed after the execute operation nn TRUE");
}
}
Aggregations