@Test public void testMultipleSideInputs() { SideInputHandler sideInputHandler = new SideInputHandler( ImmutableList.of(view1, view2), InMemoryStateInternals.<Void>forKey(null)); // two windows that we'll later use for adding elements/retrieving side input IntervalWindow firstWindow = new IntervalWindow(new Instant(0), new Instant(WINDOW_MSECS_1)); // add value for view1 in the first window sideInputHandler.addSideInputValue( view1, valuesInWindow( materializeValuesFor(View.asIterable(), "Hello"), new Instant(0), firstWindow)); assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello")); // view2 should not have any data assertFalse(sideInputHandler.isReady(view2, firstWindow)); // also add some data for view2 sideInputHandler.addSideInputValue( view2, valuesInWindow( materializeValuesFor(View.asIterable(), "Salut"), new Instant(0), firstWindow)); assertTrue(sideInputHandler.isReady(view2, firstWindow)); assertThat(sideInputHandler.get(view2, firstWindow), contains("Salut")); // view1 should not be affected by that assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello")); }
@Test public void testMultipleWindows() { SideInputHandler sideInputHandler = new SideInputHandler(ImmutableList.of(view1), InMemoryStateInternals.<Void>forKey(null)); // two windows that we'll later use for adding elements/retrieving side input IntervalWindow firstWindow = new IntervalWindow(new Instant(0), new Instant(WINDOW_MSECS_1)); IntervalWindow secondWindow = new IntervalWindow(new Instant(1000), new Instant(1000 + WINDOW_MSECS_2)); // add a first value for view1 in the first window sideInputHandler.addSideInputValue( view1, valuesInWindow( materializeValuesFor(View.asIterable(), "Hello"), new Instant(0), firstWindow)); assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello")); // add something for second window of view1 sideInputHandler.addSideInputValue( view1, valuesInWindow( materializeValuesFor(View.asIterable(), "Arrivederci"), new Instant(0), secondWindow)); assertThat(sideInputHandler.get(view1, secondWindow), contains("Arrivederci")); // contents for first window should be unaffected assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello")); }
@Test public void testNewInputReplacesPreviousInput() { // new input should completely replace old input // the creation of the Iterable that has the side input // contents happens upstream. this is also where // accumulation/discarding is decided. SideInputHandler sideInputHandler = new SideInputHandler(ImmutableList.of(view1), InMemoryStateInternals.<Void>forKey(null)); IntervalWindow window = new IntervalWindow(new Instant(0), new Instant(WINDOW_MSECS_1)); // add a first value for view1 sideInputHandler.addSideInputValue( view1, valuesInWindow(materializeValuesFor(View.asIterable(), "Hello"), new Instant(0), window)); assertThat(sideInputHandler.get(view1, window), contains("Hello")); // subsequent values should replace existing values sideInputHandler.addSideInputValue( view1, valuesInWindow( materializeValuesFor(View.asIterable(), "Ciao", "Buongiorno"), new Instant(0), window)); assertThat(sideInputHandler.get(view1, window), contains("Ciao", "Buongiorno")); }