protected boolean complete(Topology topology, Condition<?> endCondition, long timeout, TimeUnit units) throws Exception { return topology.getTester().complete(getSubmitter(), new JsonObject(), endCondition, timeout, units); }
private void waitUntilComplete(Topology t, TStream<String> s, String[] data) throws Exception { Condition<Long> tc = t.getTester().tupleCount(s, data.length); complete(t, tc); } }
@Test public void testFanout2() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("a", "b", "c"); TStream<String> sf = s.filter(tuple -> "b".equals(tuple)); TStream<String> sm = s.modify(tuple -> tuple.concat("fo2")); Condition<Long> tsmc = t.getTester().tupleCount(sm, 3); Condition<List<String>> tsf = t.getTester().streamContents(sf, "b"); Condition<List<String>> tsm = t.getTester().streamContents(sm, "afo2", "bfo2", "cfo2"); complete(t, t.getTester().and(tsm, tsmc)); assertTrue(tsf.getResult().toString(), tsf.valid()); assertTrue(tsm.getResult().toString(), tsm.valid()); } @Test
@Test public void tesFlattMapWithNullValues() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("mary had a little lamb", "its fleece was white as snow"); TStream<String> w = s.flatMap(tuple-> {List<String> values = Arrays.asList(tuple.split(" ")); values.set(2, null); values.set(4, null); return values;}); assertStream(t, w); Condition<List<String>> contents = t.getTester().streamContents(w, "mary", "had", "little", "its", "fleece", "white", "snow"); complete(t, contents); assertTrue(contents.getResult().toString(), contents.valid()); }
public void completeAndValidate(boolean ordered, String msg, Topology t, TStream<String> s, int secTimeout, String... expected) throws Exception { // if expected.length==0 we must run until the job completes or tmo Condition<Long> tc = t.getTester().tupleCount(s, expected.length == 0 ? Long.MAX_VALUE : expected.length); Condition<List<String>> contents = ordered ? t.getTester().streamContents(s, expected) : t.getTester().contentsUnordered(s, expected); complete(t, tc, secTimeout, TimeUnit.SECONDS); assertTrue(msg + " contents:" + contents.getResult(), contents.valid()); if (expected.length != 0) assertTrue("valid:" + tc.getResult(), tc.valid()); }
@Test public void testDeadtimeTooShort() throws Exception { Topology topology = newTopology("testDeadtimeTooShort"); TStream<Integer> values = topology.of(1,2,3,4,5,6,7,8,9,10); // no deadtime due to < 1ms TStream<Integer> filtered = Filters.deadtime(values, 999, TimeUnit.MICROSECONDS); Condition<Long> count = topology.getTester().tupleCount(filtered, 10); Condition<List<Integer>> contents = topology.getTester().streamContents(filtered, 1,2,3,4,5,6,7,8,9,10 ); complete(topology, count); assertTrue(contents.getResult().toString(), contents.valid()); }
@Test public void testFilter() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("a", "b", "c"); s = s.filter(tuple -> "b".equals(tuple)); assertStream(t, s); Condition<Long> tc = t.getTester().tupleCount(s, 1); Condition<List<String>> contents = t.getTester().streamContents(s, "b"); complete(t, tc); assertTrue(contents.valid()); }
@Test public void tesFlattMapWithNullIterator() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("mary had a little lamb", "NOTUPLES", "its fleece was white as snow"); TStream<String> w = s.flatMap(tuple->tuple.equals("NOTUPLES") ? null : Arrays.asList(tuple.split(" "))); assertStream(t, w); Condition<List<String>> contents = t.getTester().streamContents(w, "mary", "had", "a", "little", "lamb", "its", "fleece", "was", "white", "as", "snow"); complete(t, contents); assertTrue(contents.getResult().toString(), contents.valid()); }
@Test public void testModify() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("a", "b", "c"); TStream<String> i = s.modify(tuple -> tuple.concat("M")); assertStream(t, i); Condition<Long> tc = t.getTester().tupleCount(i, 3); Condition<List<String>> contents = t.getTester().streamContents(i, "aM", "bM", "cM"); complete(t, tc); assertTrue(contents.valid()); }
@Test public void testDeadtimeNoDeadtime() throws Exception { Topology topology = newTopology("testDeadtimeNoDeadtime"); TStream<Integer> values = topology.of(1,2,3,4,5,6,7,8,9,10); // no deadtime TStream<Integer> filtered = Filters.deadtime(values, 0, TimeUnit.MILLISECONDS); Condition<Long> count = topology.getTester().tupleCount(filtered, 10); Condition<List<Integer>> contents = topology.getTester().streamContents(filtered, 1,2,3,4,5,6,7,8,9,10 ); complete(topology, count); assertTrue(contents.getResult().toString(), contents.valid()); }
@Test public void testStringContants() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("a", "b", "c"); assertStream(t, s); Condition<Long> tc = t.getTester().tupleCount(s, 3); Condition<List<String>> contents = t.getTester().streamContents(s, "a", "b", "c"); complete(t, tc); assertTrue(contents.valid()); }
@Test public void testMap() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("32", "423", "-746"); TStream<Integer> i = s.map(Integer::valueOf); assertStream(t, i); Condition<Long> tc = t.getTester().tupleCount(i, 3); Condition<List<Integer>> contents = t.getTester().streamContents(i, 32, 423, -746); complete(t, tc); assertTrue(contents.getResult().toString(), contents.valid()); }
@Test public void tesFlattMap() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("mary had a little lamb", "its fleece was white as snow"); TStream<String> w = s.flatMap(tuple->Arrays.asList(tuple.split(" "))); assertStream(t, w); Condition<List<String>> contents = t.getTester().streamContents(w, "mary", "had", "a", "little", "lamb", "its", "fleece", "was", "white", "as", "snow"); complete(t, contents); assertTrue(contents.getResult().toString(), contents.valid()); }
@Test public void testModifyWithDrops() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("32", "423", "-746"); TStream<Integer> i = s.map(Integer::valueOf); i = i.modify(tuple -> tuple < 0 ? null : tuple + 27); assertStream(t, i); Condition<Long> tc = t.getTester().tupleCount(i, 2); Condition<List<Integer>> contents = t.getTester().streamContents(i, 59, 450); complete(t, tc); assertTrue(contents.getResult().toString(), contents.valid()); }
@Test public void testDeadbandIdentity() throws Exception { Topology topology = newTopology("testDeadband"); TStream<Double> values = topology.of(12.9, 3.4, 12.3, 15.6, 18.4, -3.7, -4.5, 15.0, 16.0, 30.0, 42.0 ); TStream<Double> filtered = Filters.deadband(values, identity(), v -> v >= 10.0 && v <= 30.0); Condition<Long> count = topology.getTester().tupleCount(filtered, 7); Condition<List<Double>> contents = topology.getTester().streamContents(filtered, 12.9, 3.4, 12.3, -3.7, -4.5, 15.0, 42.0 ); complete(topology, count); assertTrue(count.valid()); assertTrue(contents.valid()); } @Test
@Test public void testNoStringContants() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings(); Condition<Long> tc = t.getTester().tupleCount(s, 0); complete(t, tc); assertTrue(tc.valid()); }
@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 testDelete() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/delete"; TStream<String> stream = topology.strings(url); TStream<String> rc = HttpStreams.<String, String>requests( stream, HttpClients::noAuthentication, t -> HttpDelete.METHOD_NAME, t-> t, HttpResponders.inputOn200()); Tester tester = topology.getTester(); Condition<List<String>> endCondition = tester.streamContents(rc, url); tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); assertTrue(endCondition.valid()); }
@Test public void testRuntimeServices() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("A"); Supplier<RuntimeServices> serviceGetter = t.getRuntimeServiceSupplier(); TStream<Boolean> b = s.map(tuple -> serviceGetter.get().getService(ThreadFactory.class) != null && serviceGetter.get().getService(ScheduledExecutorService.class) != null ); Condition<List<Boolean>> tc = t.getTester().streamContents(b, Boolean.TRUE); complete(t, tc); assertTrue(tc.valid()); }