use of org.apache.geode.internal.cache.execute.FunctionContextImpl in project geode by apache.
the class DeployedJarJUnitTest method testDeclarableFunctionsWithNoCacheXml.
@Test
public void testDeclarableFunctionsWithNoCacheXml() throws Exception {
final String jarName = "JarClassLoaderJUnitNoXml.jar";
// Add a Declarable Function without parameters for the class to the Classpath
String functionString = "import java.util.Properties;" + "import org.apache.geode.cache.Declarable;" + "import org.apache.geode.cache.execute.Function;" + "import org.apache.geode.cache.execute.FunctionContext;" + "public class JarClassLoaderJUnitFunctionNoXml implements Function, Declarable {" + "public String getId() {return \"JarClassLoaderJUnitFunctionNoXml\";}" + "public void init(Properties props) {}" + "public void execute(FunctionContext context) {context.getResultSender().lastResult(\"NOPARMSv1\");}" + "public boolean hasResult() {return true;}" + "public boolean optimizeForWrite() {return false;}" + "public boolean isHA() {return false;}}";
byte[] jarBytes = this.classBuilder.createJarFromClassContent("JarClassLoaderJUnitFunctionNoXml", functionString);
ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, jarBytes);
ClassPathLoader.getLatest().forName("JarClassLoaderJUnitFunctionNoXml");
// Check to see if the function without parameters executes correctly
Function function = FunctionService.getFunction("JarClassLoaderJUnitFunctionNoXml");
assertThat(function).isNotNull();
TestResultSender resultSender = new TestResultSender();
function.execute(new FunctionContextImpl(function.getId(), null, resultSender));
assertThat((String) resultSender.getResults()).isEqualTo("NOPARMSv1");
}
use of org.apache.geode.internal.cache.execute.FunctionContextImpl 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.internal.cache.execute.FunctionContextImpl 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);
}
Aggregations