Search in sources :

Example 6 with SimpleFunction

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.");
}
Also used : SimpleFunction(org.apache.beam.sdk.transforms.SimpleFunction) Pipeline(org.apache.beam.sdk.Pipeline)

Aggregations

Pipeline (org.apache.beam.sdk.Pipeline)6 SimpleFunction (org.apache.beam.sdk.transforms.SimpleFunction)6 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)5 Test (org.junit.Test)4 KV (org.apache.beam.sdk.values.KV)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DirectPipelineResult (org.apache.beam.runners.direct.DirectRunner.DirectPipelineResult)2 TableReference (com.google.api.services.bigquery.model.TableReference)1 TableRow (com.google.api.services.bigquery.model.TableRow)1 TableSchema (com.google.api.services.bigquery.model.TableSchema)1 CoderException (org.apache.beam.sdk.coders.CoderException)1 JsonSchemaToTableSchema (org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.JsonSchemaToTableSchema)1 BigQueryHelpers.createTempTableReference (org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.createTempTableReference)1 BigQueryHelpers.toJsonString (org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.toJsonString)1 DoFn (org.apache.beam.sdk.transforms.DoFn)1 SerializableFunction (org.apache.beam.sdk.transforms.SerializableFunction)1 TypeDescriptor (org.apache.beam.sdk.values.TypeDescriptor)1