/** * Create with the destination set to {@link Functions#discard()}. */ public SettableForwarder() { this.destination = Functions.discard(); }
/** * Returns a constant function that returns zero (0). * This is identical to {@link #zero()} but is more * readable when applied as a key function. * @param <T> tuple type * @return Constant function that returns zero (0). */ public static <T> Function<T,Integer> unpartitioned() { return zero(); }
@Override public TStream<T> peek(Consumer<T> peeker) { peeker = Functions.synchronizedConsumer(peeker); connector.peek(new Peek<T>(peeker)); return this; }
@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
}, 1, TimeUnit.MILLISECONDS); TWindow<Long, Integer> window = times.last(1, TimeUnit.SECONDS, unpartitioned()); assertSame(zero(), window.getKeyFunction()); TStream<Long> diffStream = window.aggregate((tuples, key) -> { assertEquals(Integer.valueOf(0), key);
public EndlessSupplier(Supplier<T> data) { super(Functions.synchronizedSupplier(data)); }
/** * Capture the first and every nth tuple * @param count the nth value interval */ public void setCaptureByCount(int count) { if (count == 1) setCaptureByPredicate(Functions.alwaysTrue()); else setCaptureByPredicate(newByCountPredicate(count)); }
@Override public <U> TStream<U> map(Function<T, U> mapper) { mapper = synchronizedFunction(mapper); return connectPipe(new Map<T, U>(mapper)); }
Functions.unpartitioned(), 1).tag("pressureRelieved");
@Test public void testKeyedWindowSum() throws Exception { Topology t = newTopology(); TStream<Integer> integers = t.collection(Arrays.asList(1,2,3,4,4,3,4,4,3)); TWindow<Integer, Integer> window = integers.last(9, identity()); assertSame(identity(), window.getKeyFunction()); assertSame(t, window.topology()); assertSame(integers, window.feeder()); TStream<Integer> sums = window.aggregate((tuples, key) -> { // All tuples in a partition are equal due to identity assertEquals(1, new HashSet<>(tuples).size()); int sum = 0; for(Integer tuple : tuples) sum+=tuple; return sum; }); Condition<Long> tc = t.getTester().tupleCount(sums, 9); Condition<List<Integer>> contents = t.getTester().streamContents(sums, 1, 2, 3, 4, 8, 6, 12, 16, 9); complete(t, tc); assertTrue(contents.valid()); }
public EndlessSupplier(Supplier<T> data) { super(Functions.synchronizedSupplier(data)); }
@Test public void testAlwaysTrue() { assertTrue(Functions.alwaysTrue().test("hello")); assertTrue(Functions.alwaysTrue().test(42)); assertTrue(Functions.alwaysTrue().test(new Object())); } @Test
@Override public <U> TStream<U> map(Function<T, U> mapper) { mapper = synchronizedFunction(mapper); return connectPipe(new Map<T, U>(mapper)); }
Functions.unpartitioned(), 1).tag("pressureRelieved");
/** * Create with the destination set to {@link Functions#discard()}. */ public SettableForwarder() { this.destination = Functions.discard(); }
@Test public void testDeadbandMaxSuppression() throws Exception { Topology topology = newTopology("testDeadbandMaxSuppression"); 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 ); // 18.4 will be included as it is delayed since the last inband value. values = values.modify(tuple -> {if (tuple == 18.4) try { Thread.sleep(5000); } catch (Exception e) { throw new RuntimeException(e); } return tuple;}); TStream<Double> filtered = Filters.deadband(values, identity(), v -> v >= 10.0 && v <= 30.0, 3, TimeUnit.SECONDS); Condition<Long> count = topology.getTester().tupleCount(filtered, 8); Condition<List<Double>> contents = topology.getTester().streamContents(filtered, 12.9, 3.4, 12.3, 18.4, -3.7, -4.5, 15.0, 42.0 ); complete(topology, count); assertTrue(count.valid()); assertTrue(contents.valid()); }
@Override public <T> TStream<T> poll(Supplier<T> data, long period, TimeUnit unit) { data = Functions.synchronizedSupplier(data); return sourceStream(new SupplierPeriodicSource<>(period, unit, data)); }
/** * Returns a constant function that returns zero (0). * This is identical to {@link #zero()} but is more * readable when applied as a key function. * @param <T> tuple type * @return Constant function that returns zero (0). */ public static <T> Function<T,Integer> unpartitioned() { return zero(); }
@Override public TSink<T> sink(Consumer<T> sinker) { return sink(new Sink<>(Functions.synchronizedConsumer(sinker))); } }