@Override public Coder<IntervalWindow> windowCoder() { return IntervalWindow.getCoder(); }
@Override public Coder<IntervalWindow> windowCoder() { return IntervalWindow.getCoder(); }
@Override public Coder<IntervalWindow> windowCoder() { return IntervalWindow.getCoder(); }
@Override public Coder<IntervalWindow> windowCoder() { return IntervalWindow.getCoder(); }
@Override public Coder<IntervalWindow> windowCoder() { return IntervalWindow.getCoder(); }
@Override public Coder<IntervalWindow> windowCoder() { return IntervalWindow.getCoder(); }
@Override public Coder<IntervalWindow> windowCoder() { return IntervalWindow.getCoder(); }
@Override public void onTimer( String timerId, BoundedWindow window, Instant timestamp, TimeDomain timeDomain) { firedTimers.add( TimerData.of( timerId, StateNamespaces.window(IntervalWindow.getCoder(), (IntervalWindow) window), timestamp, timeDomain)); }
@Test public void singleWindowSucceeds() throws Exception { WindowFn<Object, BoundedWindow> fn = StaticWindows.of(IntervalWindow.getCoder(), first); assertThat(WindowFnTestUtils.assignedWindows(fn, 100L), Matchers.contains(first)); assertThat(WindowFnTestUtils.assignedWindows(fn, -100L), Matchers.contains(first)); }
@Test public void testCompatibility() throws IncompatibleWindowException { StaticWindows staticWindows = StaticWindows.of(IntervalWindow.getCoder(), ImmutableList.of(first, second)); staticWindows.verifyCompatibility( StaticWindows.of(IntervalWindow.getCoder(), ImmutableList.of(first, second))); thrown.expect(IncompatibleWindowException.class); staticWindows.verifyCompatibility( StaticWindows.of(IntervalWindow.getCoder(), ImmutableList.of(first))); } }
@Test public void getReturnsProvidedWindows() { assertThat( WindowSupplier.of(IntervalWindow.getCoder(), ImmutableList.of(window, otherWindow)).get(), Matchers.containsInAnyOrder(otherWindow, window)); }
@Test public void testCoderSerializable() throws Exception { CoderProperties.coderSerializable( ValueInSingleWindow.Coder.of(StringUtf8Coder.of(), IntervalWindow.getCoder())); }
@Test public void getAfterSerialization() { WindowSupplier supplier = WindowSupplier.of(IntervalWindow.getCoder(), ImmutableList.of(window, otherWindow)); assertThat( SerializableUtils.clone(supplier).get(), Matchers.containsInAnyOrder(otherWindow, window)); }
@Test public void getSideInputWindowIdentity() { WindowFn<Object, BoundedWindow> fn = StaticWindows.of(IntervalWindow.getCoder(), ImmutableList.of(first, second)); assertThat(fn.getDefaultWindowMappingFn().getSideInputWindow(first), Matchers.equalTo(first)); assertThat(fn.getDefaultWindowMappingFn().getSideInputWindow(second), Matchers.equalTo(second)); }
@Override public PDone expand(PCollection<String> input) { // Verify that the input has a compatible window type. checkArgument( input.getWindowingStrategy().getWindowFn().windowCoder() == IntervalWindow.getCoder()); ResourceId resource = FileBasedSink.convertToFileResourceIfPossible(filenamePrefix); return input.apply( TextIO.write() .to(new PerWindowFiles(resource)) .withTempDirectory(resource.getCurrentDirectory()) .withWindowedWrites() .withNumShards(3)); } }
@Test public void getSideInputWindowNotPresent() { WindowFn<Object, BoundedWindow> fn = StaticWindows.of(IntervalWindow.getCoder(), ImmutableList.of(second)); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("contains"); fn.getDefaultWindowMappingFn().getSideInputWindow(first); }
@Test public void testComplexCoderSerializable() { CoderProperties.coderSerializable( WindowedValue.getFullCoder( KvCoder.of(ShardedKeyCoder.of(StringUtf8Coder.of()), TableRowInfoCoder.of()), IntervalWindow.getCoder())); }
@Test public void testDecodeEncodeEqual() throws Exception { Instant now = Instant.now(); ValueInSingleWindow<String> value = ValueInSingleWindow.of( "foo", now, new IntervalWindow(now, now.plus(Duration.standardSeconds(10))), PaneInfo.NO_FIRING); CoderProperties.coderDecodeEncodeEqual( ValueInSingleWindow.Coder.of(StringUtf8Coder.of(), IntervalWindow.getCoder()), value); }
@Test public void testCompareByNamespace() { Instant timestamp = new Instant(100); IntervalWindow firstWindow = new IntervalWindow(new Instant(0), timestamp); IntervalWindow secondWindow = new IntervalWindow(timestamp, new Instant(200)); Coder<IntervalWindow> windowCoder = IntervalWindow.getCoder(); StateNamespace firstWindowNs = StateNamespaces.window(windowCoder, firstWindow); StateNamespace secondWindowNs = StateNamespaces.window(windowCoder, secondWindow); TimerData secondEventTime = TimerData.of(firstWindowNs, timestamp, TimeDomain.EVENT_TIME); TimerData thirdEventTime = TimerData.of(secondWindowNs, timestamp, TimeDomain.EVENT_TIME); assertThat(secondEventTime, lessThan(thirdEventTime)); }
@Test public void testTimerDataCoder() throws Exception { CoderProperties.coderDecodeEncodeEqual( TimerDataCoder.of(GlobalWindow.Coder.INSTANCE), TimerData.of( "arbitrary-id", StateNamespaces.global(), new Instant(0), TimeDomain.EVENT_TIME)); Coder<IntervalWindow> windowCoder = IntervalWindow.getCoder(); CoderProperties.coderDecodeEncodeEqual( TimerDataCoder.of(windowCoder), TimerData.of( "another-id", StateNamespaces.window( windowCoder, new IntervalWindow(new Instant(0), new Instant(100))), new Instant(99), TimeDomain.PROCESSING_TIME)); }