Java Code Examples for reactor.test.publisher.TestPublisher#mono()
The following examples show how to use
reactor.test.publisher.TestPublisher#mono() .
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: MonoCacheTimeTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void coordinatorReachableThroughCacheInnerSubscriptionsOnly() throws InterruptedException { TestPublisher<Integer> source = TestPublisher.create(); MonoCacheTime<Integer> cached = new MonoCacheTime<>(source.mono(), Duration.ofMillis(100), //short cache TTL should trigger state change if source is not never Schedulers.parallel()); Disposable d1 = cached.subscribe(); cached.subscribe(); WeakReference<Signal<Integer>> refCoordinator = new WeakReference<>(cached.state); assertThat(refCoordinator.get()).isInstanceOf(MonoCacheTime.CoordinatorSubscriber.class); Thread.sleep(150); source = null; cached = null; System.gc(); assertThat(refCoordinator.get()).isInstanceOf(MonoCacheTime.CoordinatorSubscriber.class); }
Example 2
Source File: MonoCacheTimeTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void coordinatorCacheInnerDisposedOrNoReferenceNoLeak() throws InterruptedException { TestPublisher<Integer> source = TestPublisher.create(); MonoCacheTime<Integer> cached = new MonoCacheTime<>(source.mono(), Duration.ofMillis(100), //short cache TTL should trigger state change if source is not never Schedulers.parallel()); Disposable d1 = cached.subscribe(); cached.subscribe(); WeakReference<Signal<Integer>> refCoordinator = new WeakReference<>(cached.state); assertThat(refCoordinator.get()).isInstanceOf(MonoCacheTime.CoordinatorSubscriber.class); Thread.sleep(150); source = null; cached = null; d1.dispose(); System.gc(); assertThat(refCoordinator.get()).isNull(); }
Example 3
Source File: MonoCacheTimeTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void coordinatorNoReferenceNoLeak() throws InterruptedException { TestPublisher<Integer> source = TestPublisher.create(); MonoCacheTime<Integer> cached = new MonoCacheTime<>(source.mono(), Duration.ofMillis(100), //short cache TTL should trigger state change if source is not never Schedulers.parallel()); cached.subscribe(); cached.subscribe(); WeakReference<Signal<Integer>> refCoordinator = new WeakReference<>(cached.state); assertThat(refCoordinator.get()).isInstanceOf(MonoCacheTime.CoordinatorSubscriber.class); Thread.sleep(150); source = null; cached = null; System.gc(); assertThat(refCoordinator.get()).isNull(); }
Example 4
Source File: MonoCacheTimeTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void sourceCachedNoCoordinatorLeak() { TestPublisher<Integer> source = TestPublisher.create(); MonoCacheTime<Integer> cached = new MonoCacheTime<>(source.mono(), Duration.ofSeconds(2), Schedulers.parallel()); cached.subscribe(); WeakReference<Signal<Integer>> refCoordinator = new WeakReference<>(cached.state); assertThat(refCoordinator.get()).isInstanceOf(MonoCacheTime.CoordinatorSubscriber.class); source.emit(100); System.gc(); assertThat(refCoordinator.get()).isNull(); }
Example 5
Source File: MonoDematerializeTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void sourceWithSignalButNeverCompletes() { //the noncompliant TestPublisher should result in Mono.fromDirect, preventing it from sending an onComplete TestPublisher<String> testPublisher = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE); Mono<String> neverEndingSource = testPublisher.mono(); StepVerifier.create(neverEndingSource.materialize().dematerialize()) .expectSubscription() .then(() -> testPublisher.next("foo")) .expectNext("foo") .verifyComplete(); testPublisher.assertWasCancelled(); }
Example 6
Source File: ReconnectMonoTests.java From rsocket-java with Apache License 2.0 | 4 votes |
@Test public void shouldBeScannable() { final TestPublisher<String> publisher = TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW); final Mono<String> parent = publisher.mono(); final ReconnectMono<String> reconnectMono = parent.as(source -> new ReconnectMono<>(source, onExpire(), onValue())); final Scannable scannableOfReconnect = Scannable.from(reconnectMono); Assertions.assertThat( (List) scannableOfReconnect.parents().map(s -> s.getClass()).collect(Collectors.toList())) .hasSize(1) .containsExactly(publisher.mono().getClass()); Assertions.assertThat(scannableOfReconnect.scanUnsafe(Scannable.Attr.TERMINATED)) .isEqualTo(false); Assertions.assertThat(scannableOfReconnect.scanUnsafe(Scannable.Attr.ERROR)).isNull(); final MonoProcessor<String> processor = reconnectMono.subscribeWith(MonoProcessor.create()); final Scannable scannableOfMonoProcessor = Scannable.from(processor); Assertions.assertThat( (List) scannableOfMonoProcessor .parents() .map(s -> s.getClass()) .collect(Collectors.toList())) .hasSize(4) .containsExactly( ResolvingOperator.MonoDeferredResolutionOperator.class, ReconnectMono.ResolvingInner.class, ReconnectMono.class, publisher.mono().getClass()); reconnectMono.dispose(); Assertions.assertThat(scannableOfReconnect.scanUnsafe(Scannable.Attr.TERMINATED)) .isEqualTo(true); Assertions.assertThat(scannableOfReconnect.scanUnsafe(Scannable.Attr.ERROR)) .isInstanceOf(CancellationException.class); }