@Test public void testNonPublicInterfaceLogsWarning() throws Exception { PipelineOptionsFactory.as(NonPublicPipelineOptions.class); // Make sure we print the name of the class. expectedLogs.verifyWarn(NonPublicPipelineOptions.class.getName()); expectedLogs.verifyWarn("all non-public interfaces to be in the same package"); }
@Test public void testMissingGetterThrows() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Expected getter for property [object] of type [java.lang.Object] on " + "[org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MissingGetter]."); PipelineOptionsFactory.as(MissingGetter.class); }
@Test public void testSetterAnnotatedWithJsonIgnore() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Expected setter for property [value] to not be marked with @JsonIgnore on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$SetterWithJsonIgnore]"); PipelineOptionsFactory.as(SetterWithJsonIgnore.class); }
@Test public void testUpdateSerializeEmptyUpdate() throws Exception { TestOptions submitOptions = PipelineOptionsFactory.as(TestOptions.class); String serializedOptions = MAPPER.writeValueAsString(submitOptions); String updatedOptions = ValueProviders.updateSerializedOptions(serializedOptions, ImmutableMap.of()); TestOptions runtime = MAPPER.readValue(updatedOptions, PipelineOptions.class).as(TestOptions.class); assertNull(runtime.getString()); } }
@Test public void testDefaultMethodInExtendedClassIgnoresDefaultImplementation() { OptionsWithDefaultMethod extendedOptsWithDefault = PipelineOptionsFactory.as(ExtendedOptionsWithDefault.class); assertThat(extendedOptsWithDefault.getValue(), nullValue()); extendedOptsWithDefault.setValue(Double.NEGATIVE_INFINITY); assertThat(extendedOptsWithDefault.getValue(), equalTo(Double.NEGATIVE_INFINITY)); }
@Test public void testOptionReturnTypeRuntime() { BadOptionsRuntime options = PipelineOptionsFactory.as(BadOptionsRuntime.class); expectedException.expect(RuntimeException.class); expectedException.expectMessage( "Method getBar should not have return type " + "RuntimeValueProvider, use ValueProvider instead."); options.getBar(); }
@Test public void testGettersAnnotatedWithConsistentDefault() throws Exception { GetterWithConsistentDefault options = PipelineOptionsFactory.as(GetterWithDefault.class).as(GetterWithConsistentDefault.class); assertEquals(1, options.getObject()); }
@Test public void testWhenRequiredOptionIsNeverSet() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Missing required value for " + "[public abstract java.lang.String org.apache.beam." + "sdk.options.PipelineOptionsValidatorTest$Required.getObject(), \"Fake Description\"]."); Required required = PipelineOptionsFactory.as(Required.class); PipelineOptionsValidator.validate(Required.class, required); }
@Test public void testDisplayDataExcludesValuesAccessedButNeverSet() { HasDefaults options = PipelineOptionsFactory.as(HasDefaults.class); assertEquals("bar", options.getFoo()); DisplayData data = DisplayData.from(options); assertThat(data, not(hasDisplayItem("foo"))); }
@Test public void testMissingMultipleSettersThrows() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "missing property methods on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MissingMultipleSetters]"); expectedException.expectMessage("setter for property [object] of type [java.lang.Object]"); expectedException.expectMessage("setter for property [otherObject] of type [java.lang.Object]"); PipelineOptionsFactory.as(MissingMultipleSetters.class); }
@Test public void testMultipleSettersAnnotatedWithDefault() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Found setters marked with @Default:"); expectedException.expectMessage( "property [other] should not be marked with @Default on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiSetterWithDefault]"); expectedException.expectMessage( "property [value] should not be marked with @Default on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$SetterWithDefault]"); PipelineOptionsFactory.as(MultiSetterWithDefault.class); }
@Test public void testDefaultInvalidGcpTempLocation() { DataflowPipelineOptions options = PipelineOptionsFactory.as(DataflowPipelineOptions.class); options.setGcpTempLocation("file://temp_location"); thrown.expect(IllegalArgumentException.class); thrown.expectMessage( "Error constructing default value for stagingLocation: gcpTempLocation is not" + " a valid GCS path"); thrown.expectCause(hasMessage(containsString("Expected a valid 'gs://' path"))); options.getStagingLocation(); }
@Test public void testJsonConversionOfIgnoredNotSerializableProperty() throws Exception { IgnoredNotSerializableProperty options = PipelineOptionsFactory.as(IgnoredNotSerializableProperty.class); options.setValue(new NotSerializable("TestString")); IgnoredNotSerializableProperty options2 = serializeDeserialize(IgnoredNotSerializableProperty.class, options); assertNull(options2.getValue()); }
@Test public void testRuntimeOptionsNotCalledInApply() throws Exception { p.enableAbandonedNodeEnforcement(false); RuntimeTestOptions options = PipelineOptionsFactory.as(RuntimeTestOptions.class); p.apply(TextIO.read().from(options.getInput())); }
@Test public void testDefaultToGcpTempLocation() { DataflowPipelineOptions options = PipelineOptionsFactory.as(DataflowPipelineOptions.class); FileSystems.setDefaultPipelineOptions(options); options.setPathValidatorClass(NoopPathValidator.class); options.setTempLocation("gs://temp_location/"); options.setGcpTempLocation("gs://gcp_temp_location/"); assertEquals("gs://gcp_temp_location/staging/", options.getStagingLocation()); }
@Test public void testRuntimeOptionsNotCalledInApply() throws Exception { p.enableAbandonedNodeEnforcement(false); RuntimeTestOptions options = PipelineOptionsFactory.as(RuntimeTestOptions.class); p.apply(Create.of("")).apply(TextIO.write().to(options.getOutput())); }
@Test public void testStagingLocation() { DataflowPipelineOptions options = PipelineOptionsFactory.as(DataflowPipelineOptions.class); options.setPathValidatorClass(NoopPathValidator.class); options.setTempLocation("gs://temp_location"); options.setStagingLocation("gs://staging_location"); assertEquals("gs://temp_location", options.getGcpTempLocation()); assertEquals("gs://staging_location", options.getStagingLocation()); }
@Test public void testGcpTempAndNoTempLocationSucceeds() throws Exception { DataflowPipelineOptions options = PipelineOptionsFactory.as(DataflowPipelineOptions.class); options.setRunner(DataflowRunner.class); options.setGcpCredential(new TestCredential()); options.setProject("foo-project"); options.setGcpTempLocation(VALID_TEMP_BUCKET); options.setGcsUtil(mockGcsUtil); DataflowRunner.fromOptions(options); }
@Test public void testJsonConversionForPartiallySerializedValues() throws Exception { SimpleTypes options = PipelineOptionsFactory.as(SimpleTypes.class); options.setInteger(5); SimpleTypes options2 = serializeDeserialize(SimpleTypes.class, options); options2.setString("TestValue"); SimpleTypes options3 = serializeDeserialize(SimpleTypes.class, options2); assertEquals(5, options3.getInteger()); assertEquals("TestValue", options3.getString()); }
@Test public void testProjectDescription() throws IOException { DataflowPipelineOptions options = PipelineOptionsFactory.as(DataflowPipelineOptions.class); options.setRunner(DataflowRunner.class); options.setProject("some project"); options.setGcpTempLocation(VALID_TEMP_BUCKET); options.setGcsUtil(mockGcsUtil); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Project ID"); thrown.expectMessage("project description"); DataflowRunner.fromOptions(options); }