Search in sources :

Example 46 with ResultCollector

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

the class FunctionServiceBase method defaultCollectorReturnsResultOfSendFunctionException.

@Test
public void defaultCollectorReturnsResultOfSendFunctionException() {
    ResultCollector rc = getExecution().execute((context) -> {
        context.getResultSender().sendException(new FunctionException());
    });
    final List<Object> result = (List<Object>) rc.getResult();
    assertEquals(numberOfExecutions(), result.size());
    result.stream().forEach(element -> assertEquals(FunctionException.class, element.getClass()));
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) 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 47 with ResultCollector

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

the class FunctionServiceBase method defaultCollectorThrowsExceptionAfterFunctionThrowsIllegalState.

@Test()
public void defaultCollectorThrowsExceptionAfterFunctionThrowsIllegalState() {
    // GEODE-1762 - clients throw from execute, but peers throw from rc.getResult
    thrown.expect(FunctionException.class);
    // GEODE-1762 - clients wrap cause in a ServerOperationException
    // thrown.expectCause(isA(IllegalStateException.class));
    ResultCollector rc = getExecution().execute((context) -> {
        throw new IllegalStateException();
    });
    final Object result = rc.getResult();
}
Also used : ResultCollector(org.apache.geode.cache.execute.ResultCollector) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 48 with ResultCollector

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

the class FunctionServiceBase method customCollectorReturnsResultOfSendFunctionException.

// GEODE-1827
@Category(FlakyTest.class)
@Test
public void customCollectorReturnsResultOfSendFunctionException() {
    ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {
        context.getResultSender().sendException(new FunctionException());
    });
    final List<Object> result = (List<Object>) rc.getResult();
    assertEquals(numberOfExecutions(), result.size());
    result.stream().forEach(element -> assertEquals(FunctionException.class, element.getClass()));
    assertEquals(result, customCollector.getResult());
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) 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 49 with ResultCollector

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

the class FunctionServiceBase method customCollectorDoesNotSeeExceptionFunctionThrowsIllegalState.

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

Example 50 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method executeRegisteredFunction.

public static void executeRegisteredFunction() {
    DistributedSystem.setThreadsSocketPolicy(false);
    Execution member = FunctionService.onServer(pool);
    // remove any existing attributes
    ((AbstractExecution) member).removeFunctionAttributes(TestFunction.TEST_FUNCTION1);
    ResultCollector rs = member.setArguments(Boolean.TRUE).execute(TestFunction.TEST_FUNCTION1);
    assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
    byte[] functionAttributes = ((AbstractExecution) member).getFunctionAttributes(TestFunction.TEST_FUNCTION1);
    assertNotNull(functionAttributes);
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

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