Search in sources :

Example 11 with FunctionContextImpl

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");
}
Also used : Function(org.apache.geode.cache.execute.Function) FunctionContextImpl(org.apache.geode.internal.cache.execute.FunctionContextImpl) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 12 with FunctionContextImpl

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);
}
Also used : FunctionContextImpl(org.apache.geode.internal.cache.execute.FunctionContextImpl) FunctionContext(org.apache.geode.cache.execute.FunctionContext) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with FunctionContextImpl

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);
}
Also used : FunctionContextImpl(org.apache.geode.internal.cache.execute.FunctionContextImpl) FunctionContext(org.apache.geode.cache.execute.FunctionContext) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

FunctionContextImpl (org.apache.geode.internal.cache.execute.FunctionContextImpl)13 FunctionContext (org.apache.geode.cache.execute.FunctionContext)10 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)7 Test (org.junit.Test)7 Function (org.apache.geode.cache.execute.Function)6 IOException (java.io.IOException)4 FunctionException (org.apache.geode.cache.execute.FunctionException)4 FunctionStats (org.apache.geode.internal.cache.execute.FunctionStats)4 LowMemoryException (org.apache.geode.cache.LowMemoryException)3 ResultSender (org.apache.geode.cache.execute.ResultSender)3 ExecuteFunctionOperationContext (org.apache.geode.cache.operations.ExecuteFunctionOperationContext)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 InternalCache (org.apache.geode.internal.cache.InternalCache)3 HeapMemoryMonitor (org.apache.geode.internal.cache.control.HeapMemoryMonitor)3 InternalResourceManager (org.apache.geode.internal.cache.control.InternalResourceManager)3 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)3 MemberMappedArgument (org.apache.geode.internal.cache.execute.MemberMappedArgument)3 ChunkedMessage (org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)3 HandShake (org.apache.geode.internal.cache.tier.sockets.HandShake)3