Repository: incubator-beam Updated Branches: refs/heads/master 2f902582c -> 63490fd63
Improve PipelineOptionsFactoryTest Currently the test uses the literal string for the default runner and available runners. Instead, refer to the default runner class and extract the simple name from that class. Automatically figure out portions of the error message for unknown runners. Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/53ffc014 Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/53ffc014 Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/53ffc014 Branch: refs/heads/master Commit: 53ffc0145d07c33b7f621afc4dc695631c60636f Parents: 2f90258 Author: Thomas Groh <tg...@google.com> Authored: Fri Mar 18 15:20:49 2016 -0700 Committer: Davor Bonaci <da...@google.com> Committed: Wed Mar 23 12:10:55 2016 -0700 ---------------------------------------------------------------------- .../sdk/options/PipelineOptionsFactoryTest.java | 39 ++++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/53ffc014/sdk/src/test/java/com/google/cloud/dataflow/sdk/options/PipelineOptionsFactoryTest.java ---------------------------------------------------------------------- diff --git a/sdk/src/test/java/com/google/cloud/dataflow/sdk/options/PipelineOptionsFactoryTest.java b/sdk/src/test/java/com/google/cloud/dataflow/sdk/options/PipelineOptionsFactoryTest.java index 045a8ad..8b5dff5 100644 --- a/sdk/src/test/java/com/google/cloud/dataflow/sdk/options/PipelineOptionsFactoryTest.java +++ b/sdk/src/test/java/com/google/cloud/dataflow/sdk/options/PipelineOptionsFactoryTest.java @@ -17,6 +17,7 @@ package com.google.cloud.dataflow.sdk.options; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -53,10 +54,14 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.List; import java.util.Map; +import java.util.Set; /** Tests for {@link PipelineOptionsFactory}. */ @RunWith(JUnit4.class) public class PipelineOptionsFactoryTest { + private static final Class<? extends PipelineRunner<?>> DEFAULT_RUNNER_CLASS = + DirectPipelineRunner.class; + @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule public TestRule restoreSystemProperties = new RestoreSystemProperties(); @Rule public ExpectedLogs expectedLogs = ExpectedLogs.none(PipelineOptionsFactory.class); @@ -68,8 +73,9 @@ public class PipelineOptionsFactoryTest { @Test public void testAutomaticRegistrationOfRunners() { - assertEquals(DirectPipelineRunner.class, - PipelineOptionsFactory.getRegisteredRunners().get("DirectPipelineRunner")); + assertEquals( + DEFAULT_RUNNER_CLASS, + PipelineOptionsFactory.getRegisteredRunners().get(DEFAULT_RUNNER_CLASS.getSimpleName())); } @Test @@ -840,9 +846,14 @@ public class PipelineOptionsFactoryTest { public void testSettingUnknownRunner() { String[] args = new String[] {"--runner=UnknownRunner"}; expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Unknown 'runner' specified 'UnknownRunner', supported " - + "pipeline runners [BlockingDataflowPipelineRunner, DataflowPipelineRunner, " - + "DirectPipelineRunner]"); + expectedException.expectMessage( + "Unknown 'runner' specified 'UnknownRunner', supported " + "pipeline runners"); + Set<String> registeredRunners = PipelineOptionsFactory.getRegisteredRunners().keySet(); + assertThat(registeredRunners, hasItem(DEFAULT_RUNNER_CLASS.getSimpleName())); + for (String registeredRunner : registeredRunners) { + expectedException.expectMessage(registeredRunner); + } + PipelineOptionsFactory.fromArgs(args).create(); } @@ -927,13 +938,19 @@ public class PipelineOptionsFactoryTest { @Test public void testEmptyArgumentIsIgnored() { - String[] args = new String[] {"", "--diskSizeGb=100", "", "", "--runner=DirectPipelineRunner"}; + String[] args = + new String[] { + "", "--diskSizeGb=100", "", "", "--runner=" + DEFAULT_RUNNER_CLASS.getSimpleName() + }; PipelineOptionsFactory.fromArgs(args).create(); } @Test public void testNullArgumentIsIgnored() { - String[] args = new String[] {"--diskSizeGb=100", null, null, "--runner=DirectPipelineRunner"}; + String[] args = + new String[] { + "--diskSizeGb=100", null, null, "--runner=" + DEFAULT_RUNNER_CLASS.getSimpleName() + }; PipelineOptionsFactory.fromArgs(args).create(); } @@ -985,7 +1002,7 @@ public class PipelineOptionsFactoryTest { String output = new String(baos.toByteArray()); assertThat(output, containsString("com.google.cloud.dataflow.sdk.options.PipelineOptions")); assertThat(output, containsString("--runner")); - assertThat(output, containsString("Default: DirectPipelineRunner")); + assertThat(output, containsString("Default: " + DEFAULT_RUNNER_CLASS.getSimpleName())); assertThat(output, containsString("The pipeline runner that will be used to execute the pipeline.")); } @@ -1000,7 +1017,7 @@ public class PipelineOptionsFactoryTest { String output = new String(baos.toByteArray()); assertThat(output, containsString("com.google.cloud.dataflow.sdk.options.PipelineOptions")); assertThat(output, containsString("--runner")); - assertThat(output, containsString("Default: DirectPipelineRunner")); + assertThat(output, containsString("Default: " + DEFAULT_RUNNER_CLASS.getSimpleName())); assertThat(output, containsString("The pipeline runner that will be used to execute the pipeline.")); } @@ -1015,7 +1032,7 @@ public class PipelineOptionsFactoryTest { String output = new String(baos.toByteArray()); assertThat(output, containsString("com.google.cloud.dataflow.sdk.options.PipelineOptions")); assertThat(output, containsString("--runner")); - assertThat(output, containsString("Default: DirectPipelineRunner")); + assertThat(output, containsString("Default: " + DEFAULT_RUNNER_CLASS.getSimpleName())); assertThat(output, containsString("The pipeline runner that will be used to execute the pipeline.")); } @@ -1096,7 +1113,7 @@ public class PipelineOptionsFactoryTest { String output = new String(baos.toByteArray()); assertThat(output, containsString("com.google.cloud.dataflow.sdk.options.PipelineOptions")); assertThat(output, containsString("--runner")); - assertThat(output, containsString("Default: DirectPipelineRunner")); + assertThat(output, containsString("Default: " + DEFAULT_RUNNER_CLASS.getSimpleName())); assertThat(output, containsString("The pipeline runner that will be used to execute the pipeline.")); }