use of org.apache.beam.sdk.transforms.SimpleFunction in project beam by apache.
the class SparkPipelineStateTest method testFailedPipeline.
private void testFailedPipeline(final SparkPipelineOptions options) throws Exception {
SparkPipelineResult result = null;
try {
final Pipeline pipeline = Pipeline.create(options);
pipeline.apply(getValues(options)).setCoder(StringUtf8Coder.of()).apply(MapElements.via(new SimpleFunction<String, String>() {
@Override
public String apply(final String input) {
throw new MyCustomException(FAILED_THE_BATCH_INTENTIONALLY);
}
}));
result = (SparkPipelineResult) pipeline.run();
result.waitUntilFinish();
} catch (final Exception e) {
assertThat(e, instanceOf(Pipeline.PipelineExecutionException.class));
assertThat(e.getCause(), instanceOf(MyCustomException.class));
assertThat(e.getCause().getMessage(), is(FAILED_THE_BATCH_INTENTIONALLY));
assertThat(result.getState(), is(PipelineResult.State.FAILED));
result.cancel();
return;
}
fail("An injected failure did not affect the pipeline as expected.");
}
Aggregations