@Test public void testUnpartitioned() { String s = "hello"; assertEquals(Integer.valueOf(0), unpartitioned().apply(s)); Integer i = 42; assertEquals(Integer.valueOf(0), unpartitioned().apply(i)); Object o = new Object(); assertEquals(Integer.valueOf(0), unpartitioned().apply(o)); } @Test
Functions.unpartitioned(), 1).tag("pressureRelieved");
Functions.unpartitioned(), 1).tag("pressureRelieved");
final int COUNT = 100; Window<Integer, Integer, ? extends List<Integer>> window = Windows.lastNProcessOnInsert(10, unpartitioned());
ses.scheduleAtFixedRate(() -> {partition.process();}, 0, 1000, TimeUnit.MILLISECONDS); }}, unpartitioned(), () -> new InsertionTimeList<Long>());
}, 1, TimeUnit.MILLISECONDS); TWindow<Long, Integer> window = times.last(1, TimeUnit.SECONDS, unpartitioned()); assertSame(zero(), window.getKeyFunction()); TStream<Long> diffStream = window.aggregate((tuples, key) -> {
@Test public void testWindowSum() throws Exception { Topology t = newTopology(); TStream<Integer> integers = t.collection(Arrays.asList(1,2,3,4)); TWindow<Integer, Integer> window = integers.last(4, unpartitioned()); assertSame(unpartitioned(), window.getKeyFunction()); TStream<Integer> sums = window.aggregate((tuples, key) -> { assertEquals(Integer.valueOf(0), key); int sum = 0; for(Integer tuple : tuples) sum+=tuple; return sum; }); Condition<Long> tc = t.getTester().tupleCount(sums, 4); Condition<List<Integer>> contents = t.getTester().streamContents(sums, 1, 3, 6, 10); complete(t, tc); assertTrue(contents.valid()); }
@Test public void testAggregateNStream() throws Exception { // Aggregations.aggregate are ignorant of Stream/Window but // to be safe verify a full Stream/Window based use case works UnivariateAggregate[] stats = STAT_RESULTS.keySet().toArray(new UnivariateAggregate[0]); Topology topology = newTopology("testAggregateNStream"); // (1, 4, 102, 0) TStream<Integer> sourceData = sourceData(topology); TWindow<Integer, Integer> window = sourceData.last(2, Functions.unpartitioned()); TStream<ResultMap> aggregate = window.aggregate( (list,partition) -> { return Aggregations.aggregateN(list, stats); }); Condition<Long> count = topology.getTester().atLeastTupleCount(aggregate, 4); Condition<List<ResultMap>> contents = topology.getTester().streamContents(aggregate); complete(topology, count); assertTrue(count.valid()); List<ResultMap> tuples = contents.getResult(); assertEquals(4, tuples.size()); for (int i = 0; i < tuples.size(); i++) { assertResult(i, stats, STAT_RESULTS, tuples.get(i)); } }
TStream<TimeAndId> pr = PlumbingStreams.pressureReliever(raw, Functions.unpartitioned(), 1);
.map(i -> new SensorReadings(i, i+1000)); TWindow<SensorReadings, Integer> window = sourceData.last(2, Functions.unpartitioned());
@Test public void testPressureRelieverNoDrop() throws Exception { Topology topology = newTopology(); // Same pipeline config as testPressureRelieverDrop but the reliever queue is // big enough to avoid drops String[] tuples = {"A", "B", "C", "D", "E", "F", "G", "H"}; TStream<String> raw = topology.strings(tuples); TStream<String> pr = PlumbingStreams.pressureReliever(raw, Functions.unpartitioned(), 100); TStream<String> pr2 = PlumbingStreams.blockingOneShotDelay(pr, 1, TimeUnit.SECONDS); Condition<Long> tcCount = topology.getTester().tupleCount(pr2, tuples.length); Condition<List<String>> contents = topology.getTester().streamContents(pr2, tuples); complete(topology, tcCount); assertTrue(tcCount.valid()); assertTrue(contents.valid()); }
@Test public void testPressureRelieverDrop() throws Exception { Topology topology = newTopology(); // Verify the pressureReliever drops and retains the most recent when // backpressure exists. // // Here, all the tuples hit the reliever at once, the downstream processing (oneShotDelay) // causes a backup causing the reliever's queue to become full and drop tuples. // The first tuple should be processed, then the last (most recent) N (N==queue depth). String[] tuples = {"A", "B", "C", "D", "E", "F", "G", "H"}; String[] expTuples = {"A", "F", "G", "H"}; // with queue depth of 3 TStream<String> raw = topology.strings(tuples); TStream<String> pr = PlumbingStreams.pressureReliever(raw, Functions.unpartitioned(), 3); TStream<String> pr2 = PlumbingStreams.blockingOneShotDelay(pr, 1, TimeUnit.SECONDS); Condition<Long> tcCount = topology.getTester().tupleCount(pr2, expTuples.length); Condition<List<String>> contents = topology.getTester().streamContents(pr2, expTuples); complete(topology, tcCount); assertTrue(tcCount.valid()); assertTrue(contents.valid()); }