Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id ED0E2200CB7 for ; Fri, 30 Jun 2017 23:31:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id EBEBD160C02; Fri, 30 Jun 2017 21:31:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E6088160BE8 for ; Fri, 30 Jun 2017 23:31:05 +0200 (CEST) Received: (qmail 31532 invoked by uid 500); 30 Jun 2017 21:31:04 -0000 Mailing-List: contact commits-help@beam.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@beam.apache.org Delivered-To: mailing list commits@beam.apache.org Received: (qmail 31258 invoked by uid 99); 30 Jun 2017 21:31:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Jun 2017 21:31:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CFAF5E96E9; Fri, 30 Jun 2017 21:31:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kenn@apache.org To: commits@beam.apache.org Date: Fri, 30 Jun 2017 21:31:23 -0000 Message-Id: <8306e627f95f4fef97b1bb28443c9209@git.apache.org> In-Reply-To: <8e3ceb2abb59430881821528fc89b1d5@git.apache.org> References: <8e3ceb2abb59430881821528fc89b1d5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [21/50] beam git commit: Add a Combine Test for Sliding Windows without Context archived-at: Fri, 30 Jun 2017 21:31:07 -0000 Add a Combine Test for Sliding Windows without Context Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/6ade8426 Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/6ade8426 Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/6ade8426 Branch: refs/heads/gearpump-runner Commit: 6ade8426edc2ace1a9bec8f9501d8dad17e91365 Parents: 1e16aa2 Author: Thomas Groh Authored: Wed Jun 28 12:51:31 2017 -0700 Committer: Thomas Groh Committed: Wed Jun 28 12:52:37 2017 -0700 ---------------------------------------------------------------------- .../apache/beam/sdk/transforms/CombineTest.java | 63 ++++++++++++++++++++ 1 file changed, 63 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/beam/blob/6ade8426/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CombineTest.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CombineTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CombineTest.java index e2469ab..b24d82d 100644 --- a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CombineTest.java +++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CombineTest.java @@ -29,11 +29,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -325,6 +327,67 @@ public class CombineTest implements Serializable { @Test @Category(ValidatesRunner.class) + public void testSlidingWindowsCombine() { + PCollection input = + pipeline + .apply( + Create.timestamped( + TimestampedValue.of("a", new Instant(1L)), + TimestampedValue.of("b", new Instant(2L)), + TimestampedValue.of("c", new Instant(3L)))) + .apply( + Window.into( + SlidingWindows.of(Duration.millis(3)).every(Duration.millis(1L)))); + PCollection> combined = + input.apply( + Combine.globally( + new CombineFn, List>() { + @Override + public List createAccumulator() { + return new ArrayList<>(); + } + + @Override + public List addInput(List accumulator, String input) { + accumulator.add(input); + return accumulator; + } + + @Override + public List mergeAccumulators(Iterable> accumulators) { + // Mutate all of the accumulators. Instances should be used in only one + // place, and not + // reused after merging. + List cur = createAccumulator(); + for (List accumulator : accumulators) { + accumulator.addAll(cur); + cur = accumulator; + } + return cur; + } + + @Override + public List extractOutput(List accumulator) { + List result = new ArrayList<>(accumulator); + Collections.sort(result); + return result; + } + }) + .withoutDefaults()); + + PAssert.that(combined) + .containsInAnyOrder( + ImmutableList.of("a"), + ImmutableList.of("a", "b"), + ImmutableList.of("a", "b", "c"), + ImmutableList.of("b", "c"), + ImmutableList.of("c")); + + pipeline.run(); + } + + @Test + @Category(ValidatesRunner.class) public void testSlidingWindowsCombineWithContext() { // [a: 1, 1], [a: 4; b: 1], [b: 13] PCollection> perKeyInput =