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();
}
Aggregations