@Test public void asyncFusion() { AssertSubscriber<Object> ts = AssertSubscriber.create(); UnicastProcessor<Integer> up = UnicastProcessor.create(new ConcurrentLinkedQueue<>()); up.filter(v -> (v & 1) == 0).subscribe(ts); for (int i = 1; i < 11; i++) { up.onNext(i); } up.onComplete(); ts.assertValues(2, 4, 6, 8, 10).assertNoError().assertComplete(); }
@Test public void asyncFusionBackpressured2() { AssertSubscriber<Object> ts = AssertSubscriber.create(1); UnicastProcessor<Integer> up = UnicastProcessor.create(new ConcurrentLinkedQueue<>()); Flux.just(1).hide().flatMap(w -> up.filter(v -> (v & 1) == 0), false, 1, 1).subscribe(ts); up.onNext(1); up.onNext(2); ts.assertValues(2).assertNoError().assertNotComplete(); up.onComplete(); ts.assertValues(2).assertNoError().assertComplete(); }
@Test public void subsequentSumAsync() { AssertSubscriber<Integer> ts = AssertSubscriber.create(); UnicastProcessor<Integer> up = UnicastProcessor.create(QueueSupplier.<Integer>get(16).get()); up.publish(o -> zip((Object[] a) -> (Integer) a[0] + (Integer) a[1], o, o.skip(1))) .subscribe(ts); up.onNext(1); up.onNext(2); up.onNext(3); up.onNext(4); up.onNext(5); up.onComplete(); ts.assertValues(1 + 2, 2 + 3, 3 + 4, 4 + 5).assertNoError().assertComplete(); }