Repository: incubator-beam Updated Branches: refs/heads/master c81376bc7 -> 4e14ac2c2
Restore ReshuffleTriggerTest to SDK Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/619746b6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/619746b6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/619746b6 Branch: refs/heads/master Commit: 619746b6cdbd46bc108f8b0d0214a9e8f266b6b1 Parents: c81376b Author: Kenneth Knowles <k...@google.com> Authored: Mon Oct 17 12:44:29 2016 -0700 Committer: Kenneth Knowles <k...@google.com> Committed: Tue Oct 18 09:38:41 2016 -0700 ---------------------------------------------------------------------- .../beam/sdk/util/ReshuffleTriggerTest.java | 67 ++++++++++++++++++++ 1 file changed, 67 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/619746b6/sdks/java/core/src/test/java/org/apache/beam/sdk/util/ReshuffleTriggerTest.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/ReshuffleTriggerTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/ReshuffleTriggerTest.java new file mode 100644 index 0000000..83077f4 --- /dev/null +++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/ReshuffleTriggerTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.apache.beam.sdk.transforms.windowing.BoundedWindow; +import org.apache.beam.sdk.transforms.windowing.FixedWindows; +import org.apache.beam.sdk.transforms.windowing.IntervalWindow; +import org.apache.beam.sdk.transforms.windowing.Trigger; +import org.joda.time.Duration; +import org.joda.time.Instant; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for {@link ReshuffleTrigger}. + */ +@RunWith(JUnit4.class) +public class ReshuffleTriggerTest { + + /** Public so that other tests can instantiate {@link ReshuffleTrigger}. */ + public static <W extends BoundedWindow> ReshuffleTrigger<W> forTest() { + return new ReshuffleTrigger<>(); + } + + @Test + public void testShouldFire() throws Exception { + TriggerTester<Integer, IntervalWindow> tester = TriggerTester.forTrigger( + new ReshuffleTrigger<IntervalWindow>(), FixedWindows.of(Duration.millis(100))); + IntervalWindow arbitraryWindow = new IntervalWindow(new Instant(300), new Instant(400)); + assertTrue(tester.shouldFire(arbitraryWindow)); + } + + @Test + public void testOnTimer() throws Exception { + TriggerTester<Integer, IntervalWindow> tester = TriggerTester.forTrigger( + new ReshuffleTrigger<IntervalWindow>(), FixedWindows.of(Duration.millis(100))); + IntervalWindow arbitraryWindow = new IntervalWindow(new Instant(100), new Instant(200)); + tester.fireIfShouldFire(arbitraryWindow); + assertFalse(tester.isMarkedFinished(arbitraryWindow)); + } + + @Test + public void testToString() { + Trigger trigger = new ReshuffleTrigger<>(); + assertEquals("ReshuffleTrigger()", trigger.toString()); + } +}