Java Code Examples for io.reactivex.processors.UnicastProcessor#create()

The following examples show how to use io.reactivex.processors.UnicastProcessor#create() . 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: UniCacheTest.java    From smallrye-mutiny with Apache License 2.0 6 votes vote down vote up
@Test
public void assertCachingTheValueEmittedByAProcessor() {
    UnicastProcessor<Integer> processor = UnicastProcessor.create();
    Uni<Integer> cached = Uni.createFrom().publisher(processor).cache();

    UniAssertSubscriber<Integer> sub1 = new UniAssertSubscriber<>();
    UniAssertSubscriber<Integer> sub2 = new UniAssertSubscriber<>();

    cached.subscribe().withSubscriber(sub1);
    cached.subscribe().withSubscriber(sub2);

    sub1.assertNotCompleted();
    sub2.assertNotCompleted();

    processor.onNext(23);
    processor.onNext(42);
    processor.onComplete();

    sub1.assertCompletedSuccessfully().assertItem(23);
    sub2.assertCompletedSuccessfully().assertItem(23);
}
 
Example 2
Source File: UniCacheTest.java    From smallrye-mutiny with Apache License 2.0 6 votes vote down vote up
@Test
public void assertCancellingImmediately() {
    UnicastProcessor<Integer> processor = UnicastProcessor.create();
    Uni<Integer> cached = Uni.createFrom().publisher(processor).cache();

    UniAssertSubscriber<Integer> sub1 = new UniAssertSubscriber<>(true);
    UniAssertSubscriber<Integer> sub2 = new UniAssertSubscriber<>(true);

    cached.subscribe().withSubscriber(sub1);
    cached.subscribe().withSubscriber(sub2);

    sub1.assertNoResult().assertNoFailure();
    sub2.assertNoResult().assertNoFailure();

    processor.onNext(23);
    processor.onNext(42);
    processor.onComplete();

    sub1.assertNoResult().assertNoFailure();
    sub2.assertNoResult().assertNoFailure();
}