Java Code Examples for reactor.test.publisher.TestPublisher#createNoncompliant()
The following examples show how to use
reactor.test.publisher.TestPublisher#createNoncompliant() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FluxBufferWhenTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void openCloseBadOpen() { TestPublisher<Object> badOpen = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE); StepVerifier.create(Flux.never() .bufferWhen(badOpen, o -> Flux.never())) .then(() -> { badOpen.error(new IOException("ioboom")); badOpen.complete(); badOpen.next(1); badOpen.error(new IllegalStateException("boom")); }) .expectErrorMessage("ioboom") .verifyThenAssertThat() .hasNotDroppedElements() .hasDroppedErrorWithMessage("boom"); }
Example 2
Source File: FluxMetricsTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void malformedOnError() { AtomicReference<Throwable> errorDropped = new AtomicReference<>(); Hooks.onErrorDropped(errorDropped::set); Exception dropError = new IllegalStateException("malformedOnError"); TestPublisher<Integer> testPublisher = TestPublisher.createNoncompliant(CLEANUP_ON_TERMINATE); Flux<Integer> source = testPublisher.flux().hide(); new FluxMetrics<>(source, registry) .subscribe(); testPublisher.next(1) .complete() .error(dropError); Counter malformedMeter = registry .find(METER_MALFORMED) .counter(); assertThat(malformedMeter).isNotNull(); assertThat(malformedMeter.count()).isEqualTo(1); assertThat(errorDropped).hasValue(dropError); }
Example 3
Source File: FluxOnBackpressureBufferTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void onBackpressureBufferMaxCallbackSourceEmitsAfterComplete() { TestPublisher<Integer> testPublisher = TestPublisher.createNoncompliant(TestPublisher.Violation.DEFER_CANCELLATION); CopyOnWriteArrayList<Integer> overflown = new CopyOnWriteArrayList<>(); AtomicInteger producedCounter = new AtomicInteger(); StepVerifier.create(testPublisher.flux() .doOnNext(i -> producedCounter.incrementAndGet()) .onBackpressureBuffer(3, overflown::add), StepVerifierOptions.create().initialRequest(0).checkUnderRequesting(false)) .thenRequest(5) .then(() -> testPublisher.next(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)) .expectNext(1, 2, 3, 4, 5) .thenAwait() //at this point the buffer is overrun since the range request was unbounded .thenRequest(100) //requesting more empties the buffer before an overflow error is propagated .expectNext(6, 7, 8) .expectErrorMatches(Exceptions::isOverflow) .verifyThenAssertThat() .hasDroppedExactly(10, 11, 12, 13, 14, 15); //the rest, asserted above, is dropped because the source was cancelled assertThat(overflown).as("passed to overflow handler").containsExactly(9); assertThat(producedCounter).as("bad source produced").hasValue(15); }
Example 4
Source File: FluxWindowWhenTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void startDoneThenError() { TestPublisher<Integer> source = TestPublisher.create(); TestPublisher<Integer> start = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE); final TestPublisher<Integer> end = TestPublisher.create(); StepVerifier.create(source.flux() .windowWhen(start, v -> end) .flatMap(Flux.identityFunction()) ) .then(() -> start.error(new IllegalStateException("boom")) .error(new IllegalStateException("boom2"))) .expectErrorMessage("boom") .verifyThenAssertThat() .hasDroppedErrorWithMessage("boom2"); source.assertNoSubscribers(); //start doesn't cleanup and as such still has a subscriber end.assertNoSubscribers(); }
Example 5
Source File: FluxBufferWhenTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void openCloseBadSource() { TestPublisher<Object> badSource = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE); StepVerifier.create(badSource.flux() .bufferWhen(Flux.never(), a -> Flux.never())) .then(() -> { badSource.error(new IOException("ioboom")); badSource.complete(); badSource.next(1); badSource.error(new IllegalStateException("boom")); }) .expectErrorMessage("ioboom") .verifyThenAssertThat() .hasNotDroppedElements() .hasDroppedErrorWithMessage("boom"); }
Example 6
Source File: FluxOnBackpressureBufferStrategyTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void onBackpressureBufferWithBadSourceEmitsAfterComplete() { TestPublisher<Integer> testPublisher = TestPublisher.createNoncompliant(TestPublisher.Violation.DEFER_CANCELLATION); CopyOnWriteArrayList<Integer> overflown = new CopyOnWriteArrayList<>(); AtomicInteger producedCounter = new AtomicInteger(); StepVerifier.create(testPublisher.flux() .doOnNext(i -> producedCounter.incrementAndGet()) .onBackpressureBuffer(3, overflown::add, BufferOverflowStrategy.ERROR), StepVerifierOptions.create().initialRequest(0).checkUnderRequesting(false)) .thenRequest(5) .then(() -> testPublisher.next(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)) .expectNext(1, 2, 3, 4, 5) .thenAwait() //at this point the buffer is overrun since the range request was unbounded .thenRequest(100) //requesting more empties the buffer before an overflow error is propagated .expectNext(6, 7, 8) .expectErrorMatches(Exceptions::isOverflow) .verifyThenAssertThat() .hasDroppedExactly(10, 11, 12, 13, 14, 15); //the rest, asserted above, is dropped because the source was cancelled assertThat(overflown).as("passed to overflow handler").containsExactly(9); assertThat(producedCounter).as("bad source produced").hasValue(15); }
Example 7
Source File: MonoCollectListTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void protocolErrorsOnError() { TestPublisher<String> testPublisher = TestPublisher.createNoncompliant(CLEANUP_ON_TERMINATE); StepVerifier.create(testPublisher.flux().collectList()) .expectSubscription() .then(() -> testPublisher.emit("foo")) .then(() -> testPublisher.error(new IllegalStateException("boom"))) .assertNext(l -> assertThat(l).containsExactly("foo")) .expectComplete() .verifyThenAssertThat() .hasDroppedErrorOfType(IllegalStateException.class); }
Example 8
Source File: MonoCollectListTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void protocolErrorsOnNext() { TestPublisher<String> testPublisher = TestPublisher.createNoncompliant(CLEANUP_ON_TERMINATE); StepVerifier.create(testPublisher.flux().collectList()) .expectSubscription() .then(() -> testPublisher.emit("foo")) .then(() -> testPublisher.next("bar")) .assertNext(l -> assertThat(l).containsExactly("foo")) .expectComplete() .verifyThenAssertThat() .hasDropped("bar"); }
Example 9
Source File: ReconnectMonoTests.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test public void shouldExpireValueOnRacingDisposeAndNoValueComplete() { Hooks.onErrorDropped(t -> {}); for (int i = 0; i < 10000; i++) { final TestPublisher<String> cold = TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW); final ReconnectMono<String> reconnectMono = cold.mono().as(source -> new ReconnectMono<>(source, onExpire(), onValue())); final MonoProcessor<String> processor = reconnectMono.subscribeWith(MonoProcessor.create()); Assertions.assertThat(expired).isEmpty(); Assertions.assertThat(received).isEmpty(); RaceTestUtils.race(cold::complete, reconnectMono::dispose); Assertions.assertThat(processor.isTerminated()).isTrue(); Throwable error = processor.getError(); if (error instanceof CancellationException) { Assertions.assertThat(error) .isInstanceOf(CancellationException.class) .hasMessage("ReconnectMono has already been disposed"); } else { Assertions.assertThat(error) .isInstanceOf(IllegalStateException.class) .hasMessage("Source completed empty"); } Assertions.assertThat(expired).isEmpty(); expired.clear(); received.clear(); } }
Example 10
Source File: FluxLimitRequestTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void completeSignalDespiteAllProducedNotPropagated() { TestPublisher<Integer> tp = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE); StepVerifier.create(tp.flux().limitRequest(3)) .then(() -> tp.emit(1, 2, 3)) .expectNext(1, 2, 3) .verifyComplete(); }
Example 11
Source File: FluxWindowWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void mainDoneThenError() { TestPublisher<Integer> source = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE); StepVerifier.create(source.flux() .windowWhen(Flux.never(), v -> Mono.just(1)) .flatMap(Flux.identityFunction())) .then(() -> source.complete().error(new IllegalStateException("boom"))) .expectComplete() .verifyThenAssertThat() .hasDroppedErrorWithMessage("boom"); }
Example 12
Source File: ReconnectMonoTests.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test public void shouldThrowOnBlocking() { final TestPublisher<String> publisher = TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW); final ReconnectMono<String> reconnectMono = publisher.mono().as(source -> new ReconnectMono<>(source, onExpire(), onValue())); Assertions.assertThatThrownBy(() -> reconnectMono.block(Duration.ofMillis(100))) .isInstanceOf(IllegalStateException.class) .hasMessage("Timeout on Mono blocking read"); }
Example 13
Source File: StepVerifierTests.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void initialBoundedThenUnboundedRequestDoesntOverflow() { TestPublisher<String> publisher = TestPublisher.createNoncompliant( REQUEST_OVERFLOW); StepVerifier.create(publisher, 2) .thenRequest(Long.MAX_VALUE - 2) .then(() -> publisher.emit("foo", "bar", "baz")) .expectNext("foo", "bar", "baz") .expectComplete() .verify(); }
Example 14
Source File: StepVerifierTests.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void boundedInitialOverflowIsDetected() { TestPublisher<String> publisher = TestPublisher.createNoncompliant( REQUEST_OVERFLOW); assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.create(publisher, 1) .then(() -> publisher.emit("foo", "bar")) .expectNext("foo") .expectComplete() .verify()) .withMessageStartingWith("request overflow (") .withMessageEndingWith("expected production of at most 1;" + " produced: 2; request overflown by signal: onNext(bar))"); }
Example 15
Source File: OnDiscardShouldNotLeakTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Test public void ensureNoLeaksPopulatedQueueAndRacingCancelAndOnComplete() { Assumptions.assumeThat(discardScenario.subscriptionsNumber).isOne(); for (int i = 0; i < 10000; i++) { tracker.reset(); TestPublisher<Tracked> testPublisher = TestPublisher.createNoncompliant( TestPublisher.Violation.DEFER_CANCELLATION, TestPublisher.Violation.REQUEST_OVERFLOW); Publisher<Tracked> source = discardScenario.producePublisherFromSources(testPublisher); if (conditional) { if (source instanceof Flux) { source = ((Flux<Tracked>) source).filter(t -> true); } else { source = ((Mono<Tracked>) source).filter(t -> true); } } Scannable scannable = Scannable.from(source); Integer prefetch = scannable.scan(Scannable.Attr.PREFETCH); Assumptions.assumeThat(prefetch).isNotZero(); AssertSubscriber<Tracked> assertSubscriber = new AssertSubscriber<>(Operators.enableOnDiscard(null, Tracked::safeRelease), 0); if (fused) { assertSubscriber.requestedFusionMode(Fuseable.ANY); } source.subscribe(assertSubscriber); testPublisher.next(tracker.track(1)); testPublisher.next(tracker.track(2)); testPublisher.next(tracker.track(3)); testPublisher.next(tracker.track(4)); RaceTestUtils.race( assertSubscriber::cancel, () -> testPublisher.complete(), scheduler); List<Tracked> values = assertSubscriber.values(); values.forEach(Tracked::release); tracker.assertNoLeaks(); } }
Example 16
Source File: OnDiscardShouldNotLeakTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Test public void ensureNoLeaksPopulatedQueueAndRacingCancelAndOverflowError() { Assumptions.assumeThat(discardScenario.subscriptionsNumber).isOne(); for (int i = 0; i < 10000; i++) { tracker.reset(); TestPublisher<Tracked> testPublisher = TestPublisher.createNoncompliant( TestPublisher.Violation.DEFER_CANCELLATION, TestPublisher.Violation.REQUEST_OVERFLOW); @SuppressWarnings("unchecked") Publisher<Tracked> source = discardScenario.producePublisherFromSources(testPublisher); if (conditional) { if (source instanceof Flux) { source = ((Flux<Tracked>) source).filter(t -> true); } else { source = ((Mono<Tracked>) source).filter(t -> true); } } Scannable scannable = Scannable.from(source); Integer capacity = scannable.scan(Scannable.Attr.CAPACITY); Integer prefetch = Math.min(scannable.scan(Scannable.Attr.PREFETCH), capacity == 0 ? Integer.MAX_VALUE : capacity); Assumptions.assumeThat(prefetch).isNotZero(); Assumptions.assumeThat(prefetch).isNotEqualTo(Integer.MAX_VALUE); AssertSubscriber<Tracked> assertSubscriber = new AssertSubscriber<>(Operators.enableOnDiscard(null, Tracked::safeRelease), 0); if (fused) { assertSubscriber.requestedFusionMode(Fuseable.ANY); } source.subscribe(assertSubscriber); for (int j = 0; j < prefetch - 1; j++) { testPublisher.next(tracker.track(j)); } Tracked lastValue = tracker.track(prefetch - 1); Tracked overflowValue1 = tracker.track(prefetch); Tracked overflowValue2 = tracker.track(prefetch + 1); RaceTestUtils.race(assertSubscriber::cancel, () -> { testPublisher.next(lastValue); testPublisher.next(overflowValue1); testPublisher.next(overflowValue2); }); List<Tracked> values = assertSubscriber.values(); values.forEach(Tracked::release); if (assertSubscriber.isTerminated()) { // has a chance to error with rejected exception assertSubscriber.assertError(); } tracker.assertNoLeaks(); } }
Example 17
Source File: ReconnectMonoTests.java From rsocket-java with Apache License 2.0 | 4 votes |
@Test public void shouldNotifyAllTheSubscribersUnderRacingBetweenSubscribeAndComplete() { Hooks.onErrorDropped(t -> {}); for (int i = 0; i < 10000; i++) { final TestPublisher<String> cold = TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW); final ReconnectMono<String> reconnectMono = cold.mono().as(source -> new ReconnectMono<>(source, onExpire(), onValue())); final MonoProcessor<String> processor = reconnectMono.subscribeWith(MonoProcessor.create()); final MonoProcessor<String> racerProcessor = MonoProcessor.create(); Assertions.assertThat(expired).isEmpty(); Assertions.assertThat(received).isEmpty(); cold.next("value" + i); RaceTestUtils.race(cold::complete, () -> reconnectMono.subscribe(racerProcessor)); Assertions.assertThat(processor.isTerminated()).isTrue(); Assertions.assertThat(processor.peek()).isEqualTo("value" + i); Assertions.assertThat(racerProcessor.peek()).isEqualTo("value" + i); Assertions.assertThat(reconnectMono.resolvingInner.subscribers) .isEqualTo(ResolvingOperator.READY); Assertions.assertThat( reconnectMono.resolvingInner.add( new ResolvingOperator.MonoDeferredResolutionOperator<>( reconnectMono.resolvingInner, processor))) .isEqualTo(ResolvingOperator.READY_STATE); Assertions.assertThat(expired).isEmpty(); Assertions.assertThat(received) .hasSize(1) .containsOnly(Tuples.of("value" + i, reconnectMono)); received.clear(); } }
Example 18
Source File: OnDiscardShouldNotLeakTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Test public void ensureNoLeaksPopulatedQueueAndRacingCancelAndOnError() { Assumptions.assumeThat(discardScenario.subscriptionsNumber).isOne(); for (int i = 0; i < 10000; i++) { tracker.reset(); TestPublisher<Tracked> testPublisher = TestPublisher.createNoncompliant( TestPublisher.Violation.DEFER_CANCELLATION, TestPublisher.Violation.REQUEST_OVERFLOW); @SuppressWarnings("unchecked") Publisher<Tracked> source = discardScenario.producePublisherFromSources(testPublisher); if (conditional) { if (source instanceof Flux) { source = ((Flux<Tracked>) source).filter(t -> true); } else { source = ((Mono<Tracked>) source).filter(t -> true); } } Scannable scannable = Scannable.from(source); Integer prefetch = scannable.scan(Scannable.Attr.PREFETCH); Assumptions.assumeThat(prefetch).isNotZero(); AssertSubscriber<Tracked> assertSubscriber = new AssertSubscriber<>(Operators.enableOnDiscard(null, Tracked::safeRelease), 0); if (fused) { assertSubscriber.requestedFusionMode(Fuseable.ANY); } source.subscribe(assertSubscriber); testPublisher.next(tracker.track(1)); testPublisher.next(tracker.track(2)); testPublisher.next(tracker.track(3)); testPublisher.next(tracker.track(4)); RaceTestUtils.race( assertSubscriber::cancel, () -> testPublisher.error(new RuntimeException("test")), scheduler); List<Tracked> values = assertSubscriber.values(); values.forEach(Tracked::release); if (assertSubscriber.isTerminated()) { // has a chance to error with rejected exception assertSubscriber.assertError(); } tracker.assertNoLeaks(); } }
Example 19
Source File: ReconnectMonoTests.java From rsocket-java with Apache License 2.0 | 4 votes |
@Test public void shouldExpireValueOnRacingDisposeAndErrorWithNoBackoff() { Hooks.onErrorDropped(t -> {}); RuntimeException runtimeException = new RuntimeException("test"); for (int i = 0; i < 10000; i++) { final TestPublisher<String> cold = TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW); final ReconnectMono<String> reconnectMono = cold.mono() .retryWhen(Retry.max(1).filter(t -> t instanceof Exception)) .as(source -> new ReconnectMono<>(source, onExpire(), onValue())); final MonoProcessor<String> processor = reconnectMono.subscribeWith(MonoProcessor.create()); Assertions.assertThat(expired).isEmpty(); Assertions.assertThat(received).isEmpty(); cold.next("value" + i); RaceTestUtils.race(() -> cold.error(runtimeException), reconnectMono::dispose); Assertions.assertThat(processor.isTerminated()).isTrue(); if (processor.isError()) { if (processor.getError() instanceof CancellationException) { Assertions.assertThat(processor.getError()) .isInstanceOf(CancellationException.class) .hasMessage("ReconnectMono has already been disposed"); } else { Assertions.assertThat(processor.getError()) .matches(t -> Exceptions.isRetryExhausted(t)) .hasCause(runtimeException); } Assertions.assertThat(expired).hasSize(1).containsOnly("value" + i); } else { Assertions.assertThat(received) .hasSize(1) .containsOnly(Tuples.of("value" + i, reconnectMono)); Assertions.assertThat(processor.peek()).isEqualTo("value" + i); } expired.clear(); received.clear(); } }
Example 20
Source File: FluxRefCountGraceTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Test public void doesDisconnectAfterRefCountZeroAndSlowResubscribe() throws InterruptedException { AtomicLong subscriptionCount = new AtomicLong(); AtomicReference<SignalType> termination = new AtomicReference<>(); TestPublisher<Integer> publisher = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE); Flux<Integer> source = publisher.flux() .doFinally(termination::set) .doOnSubscribe(s -> subscriptionCount.incrementAndGet()); Flux<Integer> refCounted = source.publish().refCount(2, Duration.ofMillis(500)); Disposable sub1 = refCounted.subscribe(); //initial subscribe doesn't reach the count assertThat(subscriptionCount.get()).isZero(); assertThat(termination.get()).isNull(); Disposable sub2 = refCounted.subscribe(); //second subscribe does reaches the count assertThat(subscriptionCount.get()).isEqualTo(1); assertThat(termination.get()).isNull(); sub1.dispose(); //all subscribers are not disposed so source isn't terminated assertThat(subscriptionCount.get()).isEqualTo(1); assertThat(termination.get()).isNull(); sub2.dispose(); //all subscribers are now disposed, but grace period kicks in assertThat(subscriptionCount.get()).isEqualTo(1); assertThat(termination.get()).isNull(); //we wait for grace period to elapse Thread.sleep(600); assertThat(termination.get()).isEqualTo(SignalType.CANCEL); termination.set(null); //we then resubscribe sub1 = refCounted.subscribe(); sub2 = refCounted.subscribe(); assertThat(subscriptionCount.get()).isEqualTo(2); //since the TestPublisher doesn't cleanup on termination, we can re-evaluate the doFinally publisher.complete(); assertThat(termination.get()).isEqualTo(SignalType.ON_COMPLETE); }