Java Code Examples for io.reactivex.rxjava3.subjects.PublishSubject#create()
The following examples show how to use
io.reactivex.rxjava3.subjects.PublishSubject#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: MobiusEffectRouterTest.java From mobius with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { cConsumer = new TestConsumer<>(); dAction = new TestAction(); ObservableTransformer<TestEffect, TestEvent> router = RxMobius.<TestEffect, TestEvent>subtypeEffectHandler() .addTransformer(A.class, (Observable<A> as) -> as.map(a -> AEvent.create(a.id()))) .addTransformer(B.class, (Observable<B> bs) -> bs.map(b -> BEvent.create(b.id()))) .addConsumer(C.class, cConsumer) .addAction(D.class, dAction) .addFunction(E.class, e -> AEvent.create(e.id())) .build(); publishSubject = PublishSubject.create(); testSubscriber = TestObserver.create(); publishSubject.compose(router).subscribe(testSubscriber); }
Example 2
Source File: ReplayingShareObservableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@SuppressWarnings("CheckReturnValue") @Test public void fatalExceptionDuringReplayThrown() { PublishSubject<String> subject = PublishSubject.create(); Observable<String> observable = subject.compose(ReplayingShare.<String>instance()); observable.subscribe(); subject.onNext("Foo"); Consumer<String> brokenAction = new Consumer<String>() { @Override public void accept(String s) { throw new OutOfMemoryError("broken!"); } }; try { observable.subscribe(brokenAction); fail(); } catch (OutOfMemoryError e) { assertEquals("broken!", e.getMessage()); } }
Example 3
Source File: OutsideLifecycleExceptionTest.java From RxLifecycle with Apache License 2.0 | 6 votes |
@Test public void eventOutOfLifecycle() { PublishSubject<String> stream = PublishSubject.create(); PublishSubject<String> lifecycle = PublishSubject.create(); TestObserver<String> testObserver = stream .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS)) .test(); // Event is out of lifecycle, but this just results in completing the stream lifecycle.onNext("destroy"); stream.onNext("1"); testObserver.assertNoValues(); testObserver.assertComplete(); }
Example 4
Source File: MobiusEffectRouterTest.java From mobius with Apache License 2.0 | 6 votes |
@Test public void effectHandlersShouldBeImmutable() throws Exception { // redo some test setup for test case specific conditions publishSubject = PublishSubject.create(); testSubscriber = TestObserver.create(); RxMobius.SubtypeEffectHandlerBuilder<TestEffect, TestEvent> builder = RxMobius.<TestEffect, TestEvent>subtypeEffectHandler() .addTransformer(A.class, (Observable<A> as) -> as.map(a -> AEvent.create(a.id()))); ObservableTransformer<TestEffect, TestEvent> router = builder.build(); // this should not lead to the effects router being capable of handling B effects builder.addTransformer(B.class, bs -> bs.map(b -> BEvent.create(b.id()))); publishSubject.compose(router).subscribe(testSubscriber); B effect = B.create(84); publishSubject.onNext(effect); publishSubject.onComplete(); testSubscriber.await(); testSubscriber.assertError(new UnknownEffectException(effect)); }
Example 5
Source File: ReplayingShareObservableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void errorClearsCacheAndResubscribes() { List<String> start = new ArrayList<>(); start.add("initA"); PublishSubject<String> upstream = PublishSubject.create(); Observable<String> replayed = upstream.startWithIterable(start).compose(ReplayingShare.<String>instance()); TestObserver<String> observer1 = new TestObserver<>(); replayed.subscribe(observer1); observer1.assertValues("initA"); TestObserver<String> observer2 = new TestObserver<>(); replayed.subscribe(observer2); observer1.assertValues("initA"); RuntimeException r = new RuntimeException(); upstream.onError(r); observer1.assertError(r); observer2.assertError(r); start.set(0, "initB"); TestObserver<String> observer3 = new TestObserver<>(); replayed.subscribe(observer3); observer3.assertValues("initB"); }
Example 6
Source File: RxEventSourcesTest.java From mobius with Apache License 2.0 | 6 votes |
@Test public void disposePreventsFurtherEvents() throws Exception { PublishSubject<Integer> subject = PublishSubject.create(); EventSource<Integer> source = RxEventSources.fromObservables(subject); RecordingConsumer<Integer> consumer = new RecordingConsumer<>(); Disposable d = source.subscribe(consumer); subject.onNext(1); subject.onNext(2); d.dispose(); subject.onNext(3); consumer.waitForChange(50); consumer.assertValues(1, 2); }
Example 7
Source File: TransformersTest.java From mobius with Apache License 2.0 | 5 votes |
@Test public void effectPerformerInvokesConsumerOnSchedulerAndPassesTheRequestedEffect() throws Exception { PublishSubject<String> upstream = PublishSubject.create(); TestConsumer<String> consumer = new TestConsumer<>(); TestScheduler scheduler = new TestScheduler(); upstream.compose(Transformers.fromConsumer(consumer, scheduler)).subscribe(); upstream.onNext("First Time"); assertThat(consumer.getCurrentValue(), is(equalTo(null))); scheduler.triggerActions(); assertThat(consumer.getCurrentValue(), is("First Time")); }
Example 8
Source File: TransformersTest.java From mobius with Apache License 2.0 | 5 votes |
@Test public void effectPerformerInvokesFunctionWithReceivedEffectAndEmitsReturnedEvents() { PublishSubject<String> upstream = PublishSubject.create(); TestScheduler scheduler = new TestScheduler(); Function<String, Integer> function = String::length; TestObserver<Integer> observer = upstream.compose(Transformers.fromFunction(function, scheduler)).test(); upstream.onNext("Hello"); scheduler.triggerActions(); observer.assertValue(5); }
Example 9
Source File: MobiusEffectRouterTest.java From mobius with Apache License 2.0 | 5 votes |
@Test public void shouldHandleNullRxJavaErrorHandler() throws Exception { // given no RxJava error handler RxJavaPlugins.setErrorHandler(null); // and a router with a broken effect handler publishSubject = PublishSubject.create(); testSubscriber = TestObserver.create(); final RuntimeException expected = new RuntimeException("expected!"); ObservableTransformer<TestEffect, TestEvent> router = RxMobius.<TestEffect, TestEvent>subtypeEffectHandler() .addFunction( A.class, a -> { throw expected; }) .build(); publishSubject.compose(router).subscribe(testSubscriber); // when an event is sent, it doesn't crash (the exception does get printed to stderr) publishSubject.onNext(A.create(1)); // and the right exception is forwarded to the test subscriber testSubscriber.assertError(t -> t == expected); }
Example 10
Source File: ReplayingShareObservableTest.java From RxReplayingShare with Apache License 2.0 | 5 votes |
@Test public void defaultValueIsOverriddenByLatestEmissionForNewSubscriber() { PublishSubject<String> subject = PublishSubject.create(); Observable<String> observable = subject.compose(ReplayingShare.createWithDefault("default")); TestObserver<String> observer1 = new TestObserver<>(); observable.subscribe(observer1); observer1.assertValues("default"); subject.onNext("Foo"); observer1.assertValues("default", "Foo"); TestObserver<String> observer2 = new TestObserver<>(); observable.subscribe(observer2); observer2.assertValues("Foo"); }
Example 11
Source File: ReplayingShareObservableTest.java From RxReplayingShare with Apache License 2.0 | 5 votes |
@Test public void defaultValueOnSubscribe() { PublishSubject<String> subject = PublishSubject.create(); Observable<String> observable = subject.compose(ReplayingShare.createWithDefault("default")); TestObserver<String> observer1 = new TestObserver<>(); observable.subscribe(observer1); observer1.assertValues("default"); subject.onNext("Foo"); observer1.assertValues("default", "Foo"); }
Example 12
Source File: UntilCorrespondingEventTransformerSingleTest.java From RxLifecycle with Apache License 2.0 | 4 votes |
@Before public void setup() { lifecycle = PublishSubject.create(); testScheduler = new TestScheduler(); }
Example 13
Source File: UntilEventTransformerObservableTest.java From RxLifecycle with Apache License 2.0 | 4 votes |
@Before public void setup() { stream = PublishSubject.create(); lifecycle = PublishSubject.create(); }
Example 14
Source File: UntilLifecycleTransformerObservableTest.java From RxLifecycle with Apache License 2.0 | 4 votes |
@Before public void setup() { stream = PublishSubject.create(); lifecycle = PublishSubject.create(); }
Example 15
Source File: UntilCorrespondingEventTransformerMaybeTest.java From RxLifecycle with Apache License 2.0 | 4 votes |
@Before public void setup() { subject = PublishSubject.create(); maybe = subject.firstElement(); lifecycle = PublishSubject.create(); }
Example 16
Source File: UntilCorrespondingEventTransformerFlowableTest.java From RxLifecycle with Apache License 2.0 | 4 votes |
@Before public void setup() { stream = PublishProcessor.create(); lifecycle = PublishSubject.create(); }
Example 17
Source File: UntilEventTransformerCompletableTest.java From RxLifecycle with Apache License 2.0 | 4 votes |
@Before public void setup() { subject = PublishSubject.create(); completable = Completable.fromObservable(subject); lifecycle = PublishSubject.create(); }
Example 18
Source File: UntilCorrespondingEventTransformerObservableTest.java From RxLifecycle with Apache License 2.0 | 4 votes |
@Before public void setup() { stream = PublishSubject.create(); lifecycle = PublishSubject.create(); }
Example 19
Source File: UntilCorrespondingEventTransformerCompletableTest.java From RxLifecycle with Apache License 2.0 | 4 votes |
@Before public void setup() { subject = PublishSubject.create(); completable = Completable.fromObservable(subject); lifecycle = PublishSubject.create(); }
Example 20
Source File: RxJava3Adapter.java From resilience4j with Apache License 2.0 | 3 votes |
/** * Converts the EventPublisher into an Observable. * * @param eventPublisher the event publisher * @param <T> the type of the event * @return the Observable */ public static <T> Observable<T> toObservable(EventPublisher<T> eventPublisher) { PublishSubject<T> publishSubject = PublishSubject.create(); Subject<T> serializedSubject = publishSubject.toSerialized(); eventPublisher.onEvent(serializedSubject::onNext); return serializedSubject; }