Search in sources :

Example 41 with ResultCollector

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

the class FunctionServiceBase method defaultCollectorThrowsExceptionAfterFunctionReturnsIllegalStateExceptionAsIntermediateResult.

@Test()
public void defaultCollectorThrowsExceptionAfterFunctionReturnsIllegalStateExceptionAsIntermediateResult() {
    // GEODE-1762 - clients throw from execute, but peers throw from rc.getResult
    // GEODE-1762 - client throws a ServerOperationException
    thrown.expect(Exception.class);
    // thrown.expect(FunctionException.class);
    // thrown.expectCause(isA(IllegalStateException.class));
    ResultCollector rc = getExecution().execute((context) -> {
        context.getResultSender().sendResult(new IllegalStateException());
        context.getResultSender().lastResult("done");
    });
    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 42 with ResultCollector

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

the class FunctionServiceBase method customCollectorDoesNotSeeExceptionFunctionThrowsFunctionException.

@Test
public void customCollectorDoesNotSeeExceptionFunctionThrowsFunctionException() {
    // GEODE-1762 - clients throw from execute, but peers throw from rc.getResult
    try {
        ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {
            throw new FunctionException();
        });
        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 43 with ResultCollector

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

the class FunctionServiceBase method defaultCollectorThrowsExceptionAfterFunctionThrowsFunctionException.

@Test()
public void defaultCollectorThrowsExceptionAfterFunctionThrowsFunctionException() {
    // GEODE-1762 - clients throw from execute, but peers throw from rc.getResult
    thrown.expect(FunctionException.class);
    ResultCollector rc = getExecution().execute((context) -> {
        throw new FunctionException();
    });
    final Object result = rc.getResult();
}
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 44 with ResultCollector

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

the class FunctionServiceBase method defaultCollectorReturnsSingleResult.

@Test
public void defaultCollectorReturnsSingleResult() {
    ResultCollector rc = getExecution().execute((context) -> {
        context.getResultSender().lastResult("done");
    });
    List<String> results = (List<String>) rc.getResult();
    assertEquals(numberOfExecutions(), results.size());
    results.stream().forEach(element -> assertEquals("done", element));
}
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 45 with ResultCollector

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

the class FunctionServiceBase method defaultCollectorThrowsExceptionAfterFunctionReturnsIllegalStateException.

/**
   * Tests what happens if a function returns an exception as a result. This is kind a weird, but it
   * seems that the default collector will just throw it as an exception
   */
@Test()
public void defaultCollectorThrowsExceptionAfterFunctionReturnsIllegalStateException() {
    // GEODE-1762 - clients throw from execute, but peers throw from rc.getResult
    // GEODE-1762 - clients throw a ServerOperationException
    thrown.expect(Exception.class);
    // thrown.expect(FunctionException.class);
    // thrown.expectCause(isA(IllegalStateException.class));
    ResultCollector rc = getExecution().execute((context) -> {
        context.getResultSender().lastResult(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)

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