Use a static variable for CoderCalled in WriteTest

The test is broken when Create serializes the created values at
apply-time rather than at execution-time, as the modification happens
after the Create is applied within the Write PTransform. Moving to a
static variable allows the state of the operation to be captured at any
time without breaking the test, so long as the captured (and executed)
operation uses the same ClassLoader as the test.

----Release Notes----
[]
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=115515376


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/8b5257fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/8b5257fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/8b5257fc

Branch: refs/heads/master
Commit: 8b5257fc64be2697d001bd335302e14591aca044
Parents: 7b28d23
Author: tgroh <[email protected]>
Authored: Wed Feb 24 17:58:23 2016 -0800
Committer: Davor Bonaci <[email protected]>
Committed: Thu Feb 25 23:58:28 2016 -0800

----------------------------------------------------------------------
 sdk/src/main/java/com/google/cloud/dataflow/sdk/io/Write.java  | 2 +-
 .../test/java/com/google/cloud/dataflow/sdk/io/WriteTest.java  | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/8b5257fc/sdk/src/main/java/com/google/cloud/dataflow/sdk/io/Write.java
----------------------------------------------------------------------
diff --git a/sdk/src/main/java/com/google/cloud/dataflow/sdk/io/Write.java 
b/sdk/src/main/java/com/google/cloud/dataflow/sdk/io/Write.java
index 4d130cc..0b78b83 100644
--- a/sdk/src/main/java/com/google/cloud/dataflow/sdk/io/Write.java
+++ b/sdk/src/main/java/com/google/cloud/dataflow/sdk/io/Write.java
@@ -117,7 +117,7 @@ public class Write {
         PCollection<T> input, WriteOperation<T, WriteT> writeOperation) {
       Pipeline p = input.getPipeline();
 
-      // A coder to user for the WriteOperation.
+      // A coder to use for the WriteOperation.
       @SuppressWarnings("unchecked")
       Coder<WriteOperation<T, WriteT>> operationCoder =
           (Coder<WriteOperation<T, WriteT>>) 
SerializableCoder.of(writeOperation.getClass());

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/8b5257fc/sdk/src/test/java/com/google/cloud/dataflow/sdk/io/WriteTest.java
----------------------------------------------------------------------
diff --git a/sdk/src/test/java/com/google/cloud/dataflow/sdk/io/WriteTest.java 
b/sdk/src/test/java/com/google/cloud/dataflow/sdk/io/WriteTest.java
index 2340187..b92f2f1 100644
--- a/sdk/src/test/java/com/google/cloud/dataflow/sdk/io/WriteTest.java
+++ b/sdk/src/test/java/com/google/cloud/dataflow/sdk/io/WriteTest.java
@@ -184,8 +184,12 @@ public class WriteTest {
       FINALIZED
     }
 
+    // Must be static in case the WriteOperation is serialized before the its 
coder is obtained.
+    // If this occurs, the value will be modified but not reflected in the 
WriteOperation that is
+    // executed by the runner, and the finalize method will fail.
+    private static volatile boolean coderCalled = false;
+
     private State state = State.INITIAL;
-    private boolean coderCalled = false;
 
     private final TestSink sink;
     private final UUID id = UUID.randomUUID();

Reply via email to