@Override public <U> TStream<U> batch(BiFunction<List<T>, K, U> batcher) { batcher = Functions.synchronizedBiFunction(batcher); Window<T, K, List<T>> window = Windows.window( alwaysInsert(), Policies.doNothing(), Policies.evictAll(), Policies.processWhenFullAndEvict(size), getKeyFunction(), () -> new ArrayList<T>(size)); Aggregate<T,U,K> op = new Aggregate<T,U,K>(window, batcher); return feeder().pipe(op); }
@Override public <U> TStream<U> batch(BiFunction<List<T>, K, U> batcher) { batcher = Functions.synchronizedBiFunction(batcher); Window<T, K, List<T>> window = Windows.window( alwaysInsert(), Policies.doNothing(), Policies.evictAll(), Policies.processWhenFullAndEvict(size), getKeyFunction(), () -> new ArrayList<T>(size)); Aggregate<T,U,K> op = new Aggregate<T,U,K>(window, batcher); return feeder().pipe(op); }
@SuppressWarnings("serial") @Test public void countBatchWindowTest(){ List<Integer> numBatches = new LinkedList<>(); Window<Integer, Integer, List<Integer>> window = Windows.window( alwaysInsert(), Policies.doNothing(), Policies.evictAll(), Policies.processWhenFullAndEvict(113), tuple -> 0, () -> new ArrayList<Integer>()); window.registerPartitionProcessor(new BiConsumer<List<Integer>, Integer>() { @Override public void accept(List<Integer> t, Integer u) { numBatches.add(1); } }); for(int i = 0; i < 1000; i++){ window.insert(i); } assertTrue(numBatches.size() == 8); }