You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by dh...@apache.org on 2016/12/12 18:28:47 UTC
[1/2] incubator-beam git commit: Closes #1575
Repository: incubator-beam
Updated Branches:
refs/heads/master 2f2617c36 -> 307be5ff9
Closes #1575
Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/307be5ff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/307be5ff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/307be5ff
Branch: refs/heads/master
Commit: 307be5ff98d53a0c1f82066e40e2d2ee70421adb
Parents: 2f2617c 66c29e4
Author: Dan Halperin <dh...@google.com>
Authored: Mon Dec 12 10:28:40 2016 -0800
Committer: Dan Halperin <dh...@google.com>
Committed: Mon Dec 12 10:28:40 2016 -0800
----------------------------------------------------------------------
.../org/apache/beam/sdk/options/ValueProvider.java | 13 ++++++++++---
.../org/apache/beam/sdk/options/ValueProviderTest.java | 12 ++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
[2/2] incubator-beam git commit: [BEAM-551] Fix handling of default
for VP
Posted by dh...@apache.org.
[BEAM-551] Fix handling of default for VP
Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/66c29e4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/66c29e4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/66c29e4d
Branch: refs/heads/master
Commit: 66c29e4d8fd3654899fed6dc0054194f9e6a9b74
Parents: 2f2617c
Author: Sam McVeety <sg...@google.com>
Authored: Sat Dec 10 09:16:57 2016 -0800
Committer: Dan Halperin <dh...@google.com>
Committed: Mon Dec 12 10:28:40 2016 -0800
----------------------------------------------------------------------
.../org/apache/beam/sdk/options/ValueProvider.java | 13 ++++++++++---
.../org/apache/beam/sdk/options/ValueProviderTest.java | 12 ++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/66c29e4d/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java
index 3d36a29..93fcaf8 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java
@@ -17,7 +17,6 @@
*/
package org.apache.beam.sdk.options;
-import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import com.fasterxml.jackson.core.JsonGenerator;
@@ -222,8 +221,16 @@ public interface ValueProvider<T> extends Serializable {
Method method = klass.getMethod(methodName);
PipelineOptions methodOptions = options.as(klass);
InvocationHandler handler = Proxy.getInvocationHandler(methodOptions);
- T value = ((ValueProvider<T>) handler.invoke(methodOptions, method, null)).get();
- return firstNonNull(value, defaultValue);
+ ValueProvider<T> result =
+ (ValueProvider<T>) handler.invoke(methodOptions, method, null);
+ // Two cases: If we have deserialized a new value from JSON, it will
+ // be wrapped in a StaticValueProvider, which we can provide here. If
+ // not, there was no JSON value, and we return the default, whether or
+ // not it is null.
+ if (result instanceof StaticValueProvider) {
+ return result.get();
+ }
+ return defaultValue;
} catch (Throwable e) {
throw new RuntimeException("Unable to load runtime value.", e);
}
http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/66c29e4d/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
index 7ec40be..ea5cc54 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
@@ -149,6 +149,18 @@ public class ValueProviderTest {
assertEquals("quux", provider.get());
}
+ @Test
+ public void testDefaultRuntimeProviderWithoutOverride() throws Exception {
+ TestOptions runtime = PipelineOptionsFactory.as(TestOptions.class);
+ TestOptions options = PipelineOptionsFactory.as(TestOptions.class);
+ runtime.setOptionsId(options.getOptionsId());
+ RuntimeValueProvider.setRuntimeOptions(runtime);
+
+ ValueProvider<String> provider = options.getBar();
+ assertTrue(provider.isAccessible());
+ assertEquals("bar", provider.get());
+ }
+
/** A test interface. */
public interface BadOptionsRuntime extends PipelineOptions {
RuntimeValueProvider<String> getBar();