beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhalp...@apache.org
Subject [1/3] incubator-beam git commit: Factor common setup in EncodabilityEnforcementFactoryTest
Date Fri, 22 Apr 2016 01:21:29 GMT
Repository: incubator-beam
Updated Branches:
  refs/heads/master 640e2588f -> a5548f915


Factor common setup in EncodabilityEnforcementFactoryTest


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

Branch: refs/heads/master
Commit: 59fd4b3cd51ca5908dc4ca0f5249c4c59399e1cf
Parents: 61988f3
Author: Thomas Groh <tgroh@google.com>
Authored: Thu Apr 21 16:08:20 2016 -0700
Committer: Dan Halperin <dhalperi@google.com>
Committed: Thu Apr 21 18:20:54 2016 -0700

----------------------------------------------------------------------
 .../EncodabilityEnforcementFactoryTest.java     | 43 ++++++++------------
 1 file changed, 17 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/59fd4b3c/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/inprocess/EncodabilityEnforcementFactoryTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/inprocess/EncodabilityEnforcementFactoryTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/inprocess/EncodabilityEnforcementFactoryTest.java
index cade02b..8ed2684 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/inprocess/EncodabilityEnforcementFactoryTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/inprocess/EncodabilityEnforcementFactoryTest.java
@@ -20,6 +20,7 @@ package org.apache.beam.sdk.runners.inprocess;
 import static org.hamcrest.Matchers.isA;
 
 import org.apache.beam.sdk.coders.AtomicCoder;
+import org.apache.beam.sdk.coders.Coder;
 import org.apache.beam.sdk.coders.CoderException;
 import org.apache.beam.sdk.coders.VarIntCoder;
 import org.apache.beam.sdk.runners.inprocess.InProcessPipelineRunner.CommittedBundle;
@@ -54,16 +55,9 @@ public class EncodabilityEnforcementFactoryTest {
 
   @Test
   public void encodeFailsThrows() {
-    TestPipeline p = TestPipeline.create();
-    PCollection<Record> unencodable =
-        p.apply(Create.<Record>of().withCoder(new RecordNoEncodeCoder()));
-    AppliedPTransform<?, ?, ?> consumer =
-        unencodable.apply(Count.<Record>globally()).getProducingTransformInternal();
-
     WindowedValue<Record> record = WindowedValue.valueInGlobalWindow(new Record());
-    CommittedBundle<Record> input =
-        bundleFactory.createRootBundle(unencodable).add(record).commit(Instant.now());
-    ModelEnforcement<Record> enforcement = factory.forBundle(input, consumer);
+
+    ModelEnforcement<Record> enforcement = createEnforcement(new RecordNoEncodeCoder(),
record);
 
     thrown.expect(UserCodeException.class);
     thrown.expectCause(isA(CoderException.class));
@@ -73,16 +67,9 @@ public class EncodabilityEnforcementFactoryTest {
 
   @Test
   public void decodeFailsThrows() {
-    TestPipeline p = TestPipeline.create();
-    PCollection<Record> unencodable =
-        p.apply(Create.of(new Record()).withCoder(new RecordNoDecodeCoder()));
-    AppliedPTransform<?, ?, ?> consumer =
-        unencodable.apply(Count.<Record>globally()).getProducingTransformInternal();
     WindowedValue<Record> record = WindowedValue.valueInGlobalWindow(new Record());
 
-    CommittedBundle<Record> input =
-        bundleFactory.createRootBundle(unencodable).add(record).commit(Instant.now());
-    ModelEnforcement<Record> enforcement = factory.forBundle(input, consumer);
+    ModelEnforcement<Record> enforcement = createEnforcement(new RecordNoDecodeCoder(),
record);
 
     thrown.expect(UserCodeException.class);
     thrown.expectCause(isA(CoderException.class));
@@ -92,12 +79,6 @@ public class EncodabilityEnforcementFactoryTest {
 
   @Test
   public void consistentWithEqualsStructuralValueNotEqualThrows() {
-    TestPipeline p = TestPipeline.create();
-    PCollection<Record> unencodable =
-        p.apply(Create.of(new Record()).withCoder(new RecordStructuralValueCoder()));
-    AppliedPTransform<?, ?, ?> consumer =
-        unencodable.apply(Count.<Record>globally()).getProducingTransformInternal();
-
     WindowedValue<Record> record =
         WindowedValue.<Record>valueInGlobalWindow(
             new Record() {
@@ -107,9 +88,8 @@ public class EncodabilityEnforcementFactoryTest {
               }
             });
 
-    CommittedBundle<Record> input =
-        bundleFactory.createRootBundle(unencodable).add(record).commit(Instant.now());
-    ModelEnforcement<Record> enforcement = factory.forBundle(input, consumer);
+    ModelEnforcement<Record> enforcement =
+        createEnforcement(new RecordStructuralValueCoder(), record);
 
     thrown.expect(UserCodeException.class);
     thrown.expectCause(isA(IllegalArgumentException.class));
@@ -143,6 +123,17 @@ public class EncodabilityEnforcementFactoryTest {
         Collections.<CommittedBundle<?>>emptyList());
   }
 
+  private <T> ModelEnforcement<T> createEnforcement(Coder<T> coder, WindowedValue<T>
record) {
+    TestPipeline p = TestPipeline.create();
+    PCollection<T> unencodable = p.apply(Create.<T>of().withCoder(coder));
+    AppliedPTransform<?, ?, ?> consumer =
+        unencodable.apply(Count.<T>globally()).getProducingTransformInternal();
+    CommittedBundle<T> input =
+        bundleFactory.createRootBundle(unencodable).add(record).commit(Instant.now());
+    ModelEnforcement<T> enforcement = factory.forBundle(input, consumer);
+    return enforcement;
+  }
+
   @Test
   public void structurallyEqualResultsSucceeds() {
     TestPipeline p = TestPipeline.create();


Mime
View raw message