Search in sources :

Example 76 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class TestFunction method executeFunctionReexecuteExceptionOnServer.

private synchronized void executeFunctionReexecuteExceptionOnServer(FunctionContext context) {
    if (context.isPossibleDuplicate()) {
        retryCount++;
    } else {
        firstExecutionCount++;
    }
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (retryCount >= 5) {
        logger.fine("Tried Function Execution 5 times. Now Returning after 5 attempts");
        context.getResultSender().sendResult(new Integer(firstExecutionCount));
        context.getResultSender().lastResult(new Integer(retryCount));
        firstExecutionCount = 0;
        retryCount = 0;
        return;
    }
    if (context.getArguments() instanceof Boolean) {
        logger.fine("MyFunctionExecutionException Exception is intentionally thrown");
        throw new InternalFunctionInvocationTargetException(new MyFunctionExecutionException("I have been thrown from TestFunction"));
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 77 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class TestFunction method executeWithSendException.

private void executeWithSendException(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeWithSendException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (context.getArguments() instanceof Boolean) {
        context.getResultSender().sendException(new MyFunctionExecutionException("I have been send from TestFunction"));
    } else if (context.getArguments() instanceof String) {
        String arg = (String) context.getArguments();
        if (arg.equals("Multiple")) {
            logger.fine("Sending Exception First time");
            context.getResultSender().sendException(new MyFunctionExecutionException("I have been send from TestFunction"));
            logger.fine("Sending Exception Second time");
            context.getResultSender().sendException(new MyFunctionExecutionException("I have been send from TestFunction"));
        }
    } else if (context.getArguments() instanceof Set) {
        Set args = (Set) context.getArguments();
        for (int i = 0; i < args.size(); i++) {
            context.getResultSender().sendResult(new Integer(i));
        }
        context.getResultSender().sendException(new MyFunctionExecutionException("I have been thrown from TestFunction with set"));
    } else {
        logger.fine("Result sent back :" + Boolean.FALSE);
        context.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 78 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class TestFunction method executeException.

private void executeException(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (context.getArguments() instanceof Boolean) {
        logger.fine("MyFunctionExecutionException Exception is intentionally thrown");
        throw new MyFunctionExecutionException("I have been thrown from TestFunction");
    } else if (context.getArguments() instanceof String) {
        String key = (String) context.getArguments();
        logger.fine("Result sent back :" + key);
        context.getResultSender().lastResult(key);
    } else if (context.getArguments() instanceof Set) {
        Set origKeys = (Set) context.getArguments();
        ArrayList vals = new ArrayList();
        for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
            Object val = i.next();
            if (val != null) {
                vals.add(val);
            }
        }
        logger.fine("Result sent back :" + vals);
        context.getResultSender().lastResult(vals);
    } else {
        logger.fine("Result sent back :" + Boolean.FALSE);
        context.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 79 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class TestFunction method execute1.

public void execute1(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.info("Executing executeException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    context.getResultSender().lastResult((Serializable) context.getArguments());
}
Also used : LogWriter(org.apache.geode.LogWriter) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 80 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class TestFunction method execute2.

public void execute2(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    try {
        synchronized (this) {
            this.wait(20000000);
        }
    } catch (InterruptedException e) {
    }
    context.getResultSender().lastResult(Boolean.TRUE);
}
Also used : LogWriter(org.apache.geode.LogWriter) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Aggregations

LogWriter (org.apache.geode.LogWriter)87 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)18 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)17 Host (org.apache.geode.test.dunit.Host)17 Region (org.apache.geode.cache.Region)15 DistributedSystem (org.apache.geode.distributed.DistributedSystem)15 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)15 VM (org.apache.geode.test.dunit.VM)13 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)12 Iterator (java.util.Iterator)11 Set (java.util.Set)11 Cache (org.apache.geode.cache.Cache)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)9 Properties (java.util.Properties)8 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)8 IOException (java.io.IOException)7 HashSet (java.util.HashSet)7