public Long call(ApacheAccessLog entry) { return 1L; }}).reduceByWindow(new Function2<Long, Long, Long>() { public Long call(Long v1, Long v2) { return v1+v2;
@Test public void testReduceByWindow() { List<List<Integer>> inputData = Arrays.asList( Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)); List<List<Integer>> expected = Arrays.asList( Arrays.asList(6), Arrays.asList(21), Arrays.asList(39), Arrays.asList(24)); JavaDStream<Integer> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1); JavaDStream<Integer> reducedWindowed = stream.reduceByWindow( (x, y) -> x + y, (x, y) -> x - y, new Duration(2000), new Duration(1000)); JavaTestUtils.attachTestOutputStream(reducedWindowed); List<List<Integer>> result = JavaTestUtils.runStreams(ssc, 4, 4); Assert.assertEquals(expected, result); }
@Test public void testReduceByWindow() { List<List<Integer>> inputData = Arrays.asList( Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)); List<List<Integer>> expected = Arrays.asList( Arrays.asList(6), Arrays.asList(21), Arrays.asList(39), Arrays.asList(24)); JavaDStream<Integer> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1); JavaDStream<Integer> reducedWindowed = stream.reduceByWindow( (x, y) -> x + y, (x, y) -> x - y, new Duration(2000), new Duration(1000)); JavaTestUtils.attachTestOutputStream(reducedWindowed); List<List<Integer>> result = JavaTestUtils.runStreams(ssc, 4, 4); Assert.assertEquals(expected, result); }
@SuppressWarnings("unchecked") private void testReduceByWindow(boolean withInverse) { List<List<Integer>> inputData = Arrays.asList( Arrays.asList(1,2,3), Arrays.asList(4,5,6), Arrays.asList(7,8,9)); List<List<Integer>> expected = Arrays.asList( Arrays.asList(6), Arrays.asList(21), Arrays.asList(39), Arrays.asList(24)); JavaDStream<Integer> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1); JavaDStream<Integer> reducedWindowed; if (withInverse) { reducedWindowed = stream.reduceByWindow(new IntegerSum(), new IntegerDifference(), new Duration(2000), new Duration(1000)); } else { reducedWindowed = stream.reduceByWindow(new IntegerSum(), new Duration(2000), new Duration(1000)); } JavaTestUtils.attachTestOutputStream(reducedWindowed); List<List<Integer>> result = JavaTestUtils.runStreams(ssc, 4, 4); Assert.assertEquals(expected, result); }
@SuppressWarnings("unchecked") private void testReduceByWindow(boolean withInverse) { List<List<Integer>> inputData = Arrays.asList( Arrays.asList(1,2,3), Arrays.asList(4,5,6), Arrays.asList(7,8,9)); List<List<Integer>> expected = Arrays.asList( Arrays.asList(6), Arrays.asList(21), Arrays.asList(39), Arrays.asList(24)); JavaDStream<Integer> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1); JavaDStream<Integer> reducedWindowed; if (withInverse) { reducedWindowed = stream.reduceByWindow(new IntegerSum(), new IntegerDifference(), new Duration(2000), new Duration(1000)); } else { reducedWindowed = stream.reduceByWindow(new IntegerSum(), new Duration(2000), new Duration(1000)); } JavaTestUtils.attachTestOutputStream(reducedWindowed); List<List<Integer>> result = JavaTestUtils.runStreams(ssc, 4, 4); Assert.assertEquals(expected, result); }