void checkConstructionFailure(int size, int offset) { try { FixedWindows.of(Duration.standardSeconds(size)).withOffset(Duration.standardSeconds(offset)); fail("should have failed"); } catch (IllegalArgumentException e) { assertThat( e.toString(), containsString("FixedWindows WindowingStrategies must have 0 <= offset < size")); } }
fixedWindows = fixedWindows.withOffset(durationParameter(parameters, 2));
@Test public void testFixedOffsetWindow() throws Exception { Map<IntervalWindow, Set<String>> expected = new HashMap<>(); expected.put(new IntervalWindow(new Instant(-5), new Instant(5)), set(1, 2)); expected.put(new IntervalWindow(new Instant(5), new Instant(15)), set(5, 9, 10, 11)); expected.put(new IntervalWindow(new Instant(95), new Instant(105)), set(100)); assertEquals( expected, runWindowFn( FixedWindows.of(new Duration(10)).withOffset(new Duration(5)), Arrays.asList(1L, 2L, 5L, 9L, 10L, 11L, 100L))); }
@Test public void testTimeUnit() throws Exception { Map<IntervalWindow, Set<String>> expected = new HashMap<>(); expected.put(new IntervalWindow(new Instant(-5000), new Instant(5000)), set(1, 2, 1000)); expected.put(new IntervalWindow(new Instant(5000), new Instant(15000)), set(5000, 5001, 10000)); assertEquals( expected, runWindowFn( FixedWindows.of(Duration.standardSeconds(10)).withOffset(Duration.standardSeconds(5)), Arrays.asList(1L, 2L, 1000L, 5000L, 5001L, 10000L))); }
FixedWindowsPayload.parseFrom(windowFnSpec.getSpec().getPayload()); return FixedWindows.of(Duration.millis(Durations.toMillis(fixedParams.getSize()))) .withOffset(Duration.millis(Timestamps.toMillis(fixedParams.getOffset()))); } else if (s.equals(getUrn(SlidingWindowsPayload.Enum.PROPERTIES))) { SlidingWindowsPayload slidingParams =
@Test public void testDisplayData() { Duration offset = Duration.standardSeconds(1234); Duration size = Duration.standardSeconds(2345); FixedWindows fixedWindows = FixedWindows.of(size).withOffset(offset); DisplayData displayData = DisplayData.from(fixedWindows); assertThat(displayData, hasDisplayItem("size", size)); assertThat(displayData, hasDisplayItem("offset", offset)); } }
@Parameters(name = "{index}: {0}") public static Iterable<ToProtoAndBackSpec> data() { return ImmutableList.of( toProtoAndBackSpec(WindowingStrategy.globalDefault()), toProtoAndBackSpec( WindowingStrategy.of( FixedWindows.of(Duration.millis(11)).withOffset(Duration.millis(3)))), toProtoAndBackSpec( WindowingStrategy.of( SlidingWindows.of(Duration.millis(37)) .every(Duration.millis(3)) .withOffset(Duration.millis(2)))), toProtoAndBackSpec(WindowingStrategy.of(Sessions.withGapDuration(Duration.millis(389)))), toProtoAndBackSpec( WindowingStrategy.of(REPRESENTATIVE_WINDOW_FN) .withClosingBehavior(ClosingBehavior.FIRE_ALWAYS) .withMode(AccumulationMode.ACCUMULATING_FIRED_PANES) .withTrigger(REPRESENTATIVE_TRIGGER) .withAllowedLateness(Duration.millis(71)) .withTimestampCombiner(TimestampCombiner.EARLIEST)), toProtoAndBackSpec( WindowingStrategy.of(REPRESENTATIVE_WINDOW_FN) .withClosingBehavior(ClosingBehavior.FIRE_IF_NON_EMPTY) .withMode(AccumulationMode.DISCARDING_FIRED_PANES) .withTrigger(REPRESENTATIVE_TRIGGER) .withAllowedLateness(Duration.millis(93)) .withTimestampCombiner(TimestampCombiner.LATEST))); }