Search in sources :

Example 1 with EncodableThrowable

use of org.apache.beam.sdk.values.EncodableThrowable in project beam by apache.

the class WithFailuresTest method testDirectException.

@Test
@Category(NeedsRunner.class)
public void testDirectException() {
    List<PCollection<KV<Integer, EncodableThrowable>>> errorCollections = new ArrayList<>();
    PCollection<Integer> output = pipeline.apply(Create.of(0, 1)).apply(MapElements.into(TypeDescriptors.integers()).via((Integer i) -> 1 / i).exceptionsVia(new ThrowableHandler<Integer>() {
    })).failuresTo(errorCollections);
    PAssert.that(output).containsInAnyOrder(1);
    PAssert.thatSingleton(PCollectionList.of(errorCollections).apply(Flatten.pCollections())).satisfies(kv -> {
        assertEquals(Integer.valueOf(0), kv.getKey());
        Throwable throwable = kv.getValue().throwable();
        assertEquals("java.lang.ArithmeticException", throwable.getClass().getName());
        assertEquals("/ by zero", throwable.getMessage());
        return null;
    });
    pipeline.run();
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) EncodableThrowable(org.apache.beam.sdk.values.EncodableThrowable) ArrayList(java.util.ArrayList) EncodableThrowable(org.apache.beam.sdk.values.EncodableThrowable) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 EncodableThrowable (org.apache.beam.sdk.values.EncodableThrowable)1 PCollection (org.apache.beam.sdk.values.PCollection)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1