@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 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 boundedLong() { ReplayProcessor<Integer> rp = ReplayProcessor.create(16, false); for (int i = 0; i < 256; i++) { rp.onNext(i); } rp.onComplete(); StepVerifier.create(rp.hide()) .expectNextCount(16) .verifyComplete(); }
@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()); }
@Test public void timed() 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.onComplete(); StepVerifier.create(rp.hide()) .expectFusion(Fuseable.NONE) .expectNext(5,6,7,8,9) .verifyComplete(); }
@Test public void timedAndBound() 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.onComplete(); StepVerifier.create(rp.hide()) .expectFusion(Fuseable.NONE) .expectNext(15,16,17,18,19) .verifyComplete(); Assert.assertFalse("Has subscribers?", rp.hasDownstreams()); }
@Test public void timedAfter() throws Exception { ReplayProcessor<Integer> rp = ReplayProcessor.createTimeout(Duration.ofSeconds(1)); StepVerifier.create(rp.hide()) .expectFusion(Fuseable.NONE) .then(() -> { 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.onComplete(); }) .expectNext(0,1,2,3,4,5,6,7,8,9) .verifyComplete(); }
@Test public void timedAndBoundAfter() throws Exception { ReplayProcessor<Integer> rp = ReplayProcessor.createSizeAndTimeout(5, Duration.ofSeconds(1)); StepVerifier.create(rp.hide()) .expectFusion(Fuseable.NONE) .then(() -> { 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.onComplete(); }) .expectNextCount(20) .verifyComplete(); Assert.assertFalse("Has subscribers?", rp.hasDownstreams()); }