Repository: incubator-beam Updated Branches: refs/heads/master 5047cf746 -> 472cf0ec0
Move named DoFn classes into the tests that use them Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/2bc6b1bc Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/2bc6b1bc Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/2bc6b1bc Branch: refs/heads/master Commit: 2bc6b1bc75788ba3412abfc781bd3eb0973c9e46 Parents: 9e6246e Author: Kenneth Knowles <[email protected]> Authored: Thu Oct 20 11:47:16 2016 -0700 Committer: Kenneth Knowles <[email protected]> Committed: Thu Oct 20 11:47:40 2016 -0700 ---------------------------------------------------------------------- .../transforms/reflect/DoFnSignaturesTest.java | 80 ++++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/2bc6b1bc/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/reflect/DoFnSignaturesTest.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/reflect/DoFnSignaturesTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/reflect/DoFnSignaturesTest.java index 0374775..ad58e80 100644 --- a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/reflect/DoFnSignaturesTest.java +++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/reflect/DoFnSignaturesTest.java @@ -313,6 +313,17 @@ public class DoFnSignaturesTest { @Test public void testSimpleTimerIdNamedDoFn() throws Exception { + class DoFnForTestSimpleTimerIdNamedDoFn extends DoFn<KV<String, Integer>, Long> { + @TimerId("foo") + private final TimerSpec bizzle = TimerSpecs.timer(TimeDomain.EVENT_TIME); + + @ProcessElement + public void foo(ProcessContext context) {} + + @OnTimer("foo") + public void onFoo() {} + } + // Test classes at the bottom of the file DoFnSignature sig = DoFnSignatures.INSTANCE.signatureForDoFn(new DoFnForTestSimpleTimerIdNamedDoFn()); @@ -536,17 +547,21 @@ public class DoFnSignaturesTest { @Test public void testDeclAndUsageOfStateInSuperclass() throws Exception { + class DoFnOverridingAbstractStateUse extends DoFnDeclaringStateAndAbstractUse { + + @Override + public void processWithState(ProcessContext c, ValueState<String> state) {} + } + DoFnSignature sig = - DoFnSignatures.INSTANCE.getSignature( - new DoFnOverridingAbstractStateUse().getClass()); + DoFnSignatures.INSTANCE.getSignature(new DoFnOverridingAbstractStateUse().getClass()); assertThat(sig.stateDeclarations().size(), equalTo(1)); assertThat(sig.processElement().extraParameters().size(), equalTo(1)); DoFnSignature.StateDeclaration decl = sig.stateDeclarations().get(DoFnOverridingAbstractStateUse.STATE_ID); - StateParameter stateParam = - (StateParameter) sig.processElement().extraParameters().get(0); + StateParameter stateParam = (StateParameter) sig.processElement().extraParameters().get(0); assertThat( decl.field(), @@ -594,6 +609,15 @@ public class DoFnSignaturesTest { @Test public void testSimpleStateIdNamedDoFn() throws Exception { + class DoFnForTestSimpleStateIdNamedDoFn extends DoFn<KV<String, Integer>, Long> { + @StateId("foo") + private final StateSpec<Object, ValueState<Integer>> bizzle = + StateSpecs.value(VarIntCoder.of()); + + @ProcessElement + public void foo(ProcessContext context) {} + } + // Test classes at the bottom of the file DoFnSignature sig = DoFnSignatures.INSTANCE.signatureForDoFn(new DoFnForTestSimpleStateIdNamedDoFn()); @@ -611,6 +635,16 @@ public class DoFnSignaturesTest { @Test public void testGenericStatefulDoFn() throws Exception { + class DoFnForTestGenericStatefulDoFn<T> extends DoFn<KV<String, T>, Long> { + // Note that in order to have a coder for T it will require initialization in the constructor, + // but that isn't important for this test + @StateId("foo") + private final StateSpec<Object, ValueState<T>> bizzle = null; + + @ProcessElement + public void foo(ProcessContext context) {} + } + // Test classes at the bottom of the file DoFn<KV<String, Integer>, Long> myDoFn = new DoFnForTestGenericStatefulDoFn<Integer>(){}; @@ -627,16 +661,6 @@ public class DoFnSignaturesTest { Matchers.<TypeDescriptor<?>>equalTo(new TypeDescriptor<ValueState<Integer>>() {})); } - - private static class DoFnForTestSimpleStateIdNamedDoFn extends DoFn<KV<String, Integer>, Long> { - @StateId("foo") - private final StateSpec<Object, ValueState<Integer>> bizzle = - StateSpecs.value(VarIntCoder.of()); - - @ProcessElement - public void foo(ProcessContext context) {} - } - private abstract static class DoFnDeclaringState extends DoFn<KV<String, Integer>, Long> { public static final String STATE_ID = "my-state-id"; @@ -664,34 +688,6 @@ public class DoFnSignaturesTest { ProcessContext context, @StateId(STATE_ID) ValueState<String> state); } - private static class DoFnOverridingAbstractStateUse extends - DoFnDeclaringStateAndAbstractUse { - - @Override - public void processWithState(ProcessContext c, ValueState<String> state) {} - } - - private static class DoFnForTestGenericStatefulDoFn<T> extends DoFn<KV<String, T>, Long> { - // Note that in order to have a coder for T it will require initialization in the constructor, - // but that isn't important for this test - @StateId("foo") - private final StateSpec<Object, ValueState<T>> bizzle = null; - - @ProcessElement - public void foo(ProcessContext context) {} - } - - private static class DoFnForTestSimpleTimerIdNamedDoFn extends DoFn<KV<String, Integer>, Long> { - @TimerId("foo") - private final TimerSpec bizzle = TimerSpecs.timer(TimeDomain.EVENT_TIME); - - @ProcessElement - public void foo(ProcessContext context) {} - - @OnTimer("foo") - public void onFoo() {} - } - private abstract static class DoFnDeclaringMyTimerId extends DoFn<KV<String, Integer>, Long> { @TimerId("my-timer-id") private final TimerSpec bizzle = TimerSpecs.timer(TimeDomain.EVENT_TIME);
