Search in sources :

Example 36 with ResultCollector

use of org.apache.geode.cache.execute.ResultCollector in project geode by apache.

the class FunctionServiceBase method defaultCollectorReturnsResultOfSendException.

@Test
public void defaultCollectorReturnsResultOfSendException() {
    ResultCollector rc = getExecution().execute((context) -> {
        context.getResultSender().sendException(new IllegalStateException());
    });
    final List<Object> result = (List<Object>) rc.getResult();
    assertEquals(numberOfExecutions(), result.size());
    result.stream().forEach(element -> assertEquals(IllegalStateException.class, element.getClass()));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 37 with ResultCollector

use of org.apache.geode.cache.execute.ResultCollector in project geode by apache.

the class FunctionServiceBase method customCollectorDoesNotSeeExceptionAfterFunctionReturnsIllegalStateException.

@Test
public void customCollectorDoesNotSeeExceptionAfterFunctionReturnsIllegalStateException() {
    // GEODE-1762 - clients throw from execute, but peers throw from rc.getResult
    try {
        ResultCollector rc = getExecution().execute((context) -> {
            context.getResultSender().lastResult(new IllegalStateException());
        });
        rc.getResult();
        fail("should have received an exception");
    // GEODE-1762 - clients throw a ServerOperationException
    } catch (Exception expected) {
    }
    Assert.assertEquals(0, customCollector.getResult().size());
}
Also used : ResultCollector(org.apache.geode.cache.execute.ResultCollector) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ExpectedException(org.junit.rules.ExpectedException) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 38 with ResultCollector

use of org.apache.geode.cache.execute.ResultCollector in project geode by apache.

the class FunctionServiceBase method customCollectorReturnsResultOfSendException.

// GEODE-1981
@Category(FlakyTest.class)
@Test
public void customCollectorReturnsResultOfSendException() {
    ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {
        context.getResultSender().sendException(new IllegalStateException());
    });
    final List<Object> result = (List<Object>) rc.getResult();
    assertEquals(numberOfExecutions(), result.size());
    result.stream().forEach(element -> assertEquals(IllegalStateException.class, element.getClass()));
    assertEquals(result, customCollector.getResult());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 39 with ResultCollector

use of org.apache.geode.cache.execute.ResultCollector in project geode by apache.

the class MyFunctionException method executeFunctionFunctionInvocationTargetExceptionWithoutHA.

public static void executeFunctionFunctionInvocationTargetExceptionWithoutHA() {
    try {
        ResultCollector rc1 = FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute("DistribuedRegionFunctionFunctionInvocationException", true, false);
        rc1.getResult();
        fail("Function Invocation Target Exception should be thrown");
    } catch (Exception e) {
        e.printStackTrace();
        if (!(e.getCause() instanceof FunctionInvocationTargetException)) {
            fail("FunctionInvocationTargetException should be thrown");
        }
    }
}
Also used : FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) IOException(java.io.IOException) DistribuedRegionFunctionFunctionInvocationException(org.apache.geode.internal.cache.functions.DistribuedRegionFunctionFunctionInvocationException)

Example 40 with ResultCollector

use of org.apache.geode.cache.execute.ResultCollector in project geode by apache.

the class MyFunctionException method executeFunctionFunctionInvocationTargetException.

public static void executeFunctionFunctionInvocationTargetException() {
    try {
        ResultCollector rc1 = FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute("DistribuedRegionFunctionFunctionInvocationException");
        List list = (ArrayList) rc1.getResult();
        assertEquals(5, list.get(0));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("This is not expected Exception", e);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ResultCollector(org.apache.geode.cache.execute.ResultCollector) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) IOException(java.io.IOException) DistribuedRegionFunctionFunctionInvocationException(org.apache.geode.internal.cache.functions.DistribuedRegionFunctionFunctionInvocationException)

Aggregations

ResultCollector (org.apache.geode.cache.execute.ResultCollector)235 Execution (org.apache.geode.cache.execute.Execution)164 HashSet (java.util.HashSet)148 ArrayList (java.util.ArrayList)144 FunctionException (org.apache.geode.cache.execute.FunctionException)126 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)122 List (java.util.List)112 Function (org.apache.geode.cache.execute.Function)111 TestFunction (org.apache.geode.internal.cache.functions.TestFunction)106 Test (org.junit.Test)101 IgnoredException (org.apache.geode.test.dunit.IgnoredException)94 Iterator (java.util.Iterator)81 Region (org.apache.geode.cache.Region)77 Set (java.util.Set)69 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)65 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)63 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)56 AttributesFactory (org.apache.geode.cache.AttributesFactory)53 Host (org.apache.geode.test.dunit.Host)53 VM (org.apache.geode.test.dunit.VM)53