@Test public void scanProcessor() { ReplayProcessor<String> test = ReplayProcessor.create(16, false); Subscription subscription = Operators.emptySubscription(); test.onSubscribe(subscription); assertThat(test.scan(Scannable.Attr.PARENT)).isEqualTo(subscription); assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(16); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); assertThat(test.scan(Scannable.Attr.ERROR)).isNull(); test.onError(new IllegalStateException("boom")); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); }
@SuppressWarnings("unchecked") void testReplayProcessorState(ReplayProcessor<String> rp){ Disposable d1 = rp.subscribe(); rp.subscribe(); ReplayProcessor.ReplayInner<String> s = ((ReplayProcessor.ReplayInner<String>) rp.inners().findFirst().get()); assertThat(d1).isEqualTo(s.actual()); assertThat(s.isEmpty()).isTrue(); assertThat(s.isCancelled()).isFalse(); assertThat(s.isCancelled()).isFalse(); assertThat(rp.getPrefetch()).isEqualTo(Integer.MAX_VALUE); if(rp.getBufferSize() != Integer.MAX_VALUE) { assertThat(rp.getBufferSize()).isEqualTo(1); } FluxSink<String> sink = rp.sink(); sink.next("test"); rp.onComplete(); rp.onComplete(); Exception e = new RuntimeException("test"); try{ rp.onError(e); Assert.fail(); } catch (Exception t){ assertThat(Exceptions.unwrap(t)).isEqualTo(e); } }
@Test public void boundedFusedError() { ReplayProcessor<Integer> rp = ReplayProcessor.create(16, false); for (int i = 0; i < 256; i++) { rp.onNext(i); } rp.onError(new Exception("test")); StepVerifier.create(rp) .expectFusion(Fuseable.ASYNC) .expectNextCount(16) .verifyErrorMessage("test"); }
@Test public void boundedLongError() { ReplayProcessor<Integer> rp = ReplayProcessor.create(16, false); for (int i = 0; i < 256; i++) { rp.onNext(i); } rp.onError(new Exception("test")); StepVerifier.create(rp.hide()) .expectNextCount(16) .verifyErrorMessage("test"); }
@Test public void unboundedFusedError() { ReplayProcessor<Integer> rp = ReplayProcessor.create(16, true); for (int i = 0; i < 256; i++) { rp.onNext(i); } rp.onError(new Exception("test")); StepVerifier.create(rp) .expectFusion(Fuseable.ASYNC) .expectNextCount(256) .verifyErrorMessage("test"); }
@Test public void timedFusedError() throws Exception { VirtualTimeScheduler.getOrSet(); ReplayProcessor<Integer> rp = ReplayProcessor.createTimeout(Duration.ofSeconds(1)); for (int i = 0; i < 5; i++) { rp.onNext(i); } VirtualTimeScheduler.get().advanceTimeBy(Duration.ofSeconds(2)); for (int i = 5; i < 10; i++) { rp.onNext(i); } rp.onError(new Exception("test")); StepVerifier.create(rp) .expectFusion(Fuseable.NONE) .expectNext(5,6,7,8,9) .verifyErrorMessage("test"); }
@Test public void timedError() throws Exception { VirtualTimeScheduler.getOrSet(); ReplayProcessor<Integer> rp = ReplayProcessor.createTimeout(Duration.ofSeconds(1)); for (int i = 0; i < 5; i++) { rp.onNext(i); } VirtualTimeScheduler.get().advanceTimeBy(Duration.ofSeconds(2)); for (int i = 5; i < 10; i++) { rp.onNext(i); } rp.onError(new Exception("test")); StepVerifier.create(rp.hide()) .expectNext(5,6,7,8,9) .verifyErrorMessage("test"); }
@Test public void timedAndBoundFusedError() throws Exception { ReplayProcessor<Integer> rp = ReplayProcessor.createSizeAndTimeout(5, Duration.ofSeconds(1)); for (int i = 0; i < 10; i++) { rp.onNext(i); } VirtualTimeScheduler.get().advanceTimeBy(Duration.ofSeconds(2)); for (int i = 10; i < 20; i++) { rp.onNext(i); } rp.onError(new Exception("test")); StepVerifier.create(rp) .expectFusion(Fuseable.ASYNC) .expectNext(15,16,17,18,19) .verifyErrorMessage("test"); Assert.assertFalse("Has subscribers?", rp.hasDownstreams()); }
@Test public void timedAndBoundError() throws Exception { ReplayProcessor<Integer> rp = ReplayProcessor.createSizeAndTimeout(5, Duration.ofSeconds(1)); for (int i = 0; i < 10; i++) { rp.onNext(i); } VirtualTimeScheduler.get().advanceTimeBy(Duration.ofSeconds(2)); for (int i = 10; i < 20; i++) { rp.onNext(i); } rp.onError(new Exception("test")); StepVerifier.create(rp.hide()) .expectFusion(Fuseable.NONE) .expectNext(15,16,17,18,19) .verifyErrorMessage("test"); Assert.assertFalse("Has subscribers?", rp.hasDownstreams()); }