Java Code Examples for io.reactivex.rxjava3.core.Flowable#subscribe()
The following examples show how to use
io.reactivex.rxjava3.core.Flowable#subscribe() .
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: DataServiceTest.java From java-11-examples with Apache License 2.0 | 6 votes |
@Test public void testDataServiceWithBackPressureIncomplete() throws InterruptedException { DataService dataService = new DataServiceImpl(executor); Flowable<DataItem> dataFlow = dataService.getDataFlowWithBackPressure(new DataQuery("query2-back-pressure-incomplete", 10)); LOG.info("query submitted"); SynchronousDataSubscriber dataSubscriber = new SynchronousDataSubscriber(); dataFlow.subscribe(dataSubscriber); dataSubscriber.request(5); dataSubscriber.await(2, TimeUnit.SECONDS); LOG.info("evaluating test results"); Assert.assertTrue(dataSubscriber.getErrors().size() == 0); Assert.assertTrue(dataSubscriber.getResults().size() == 5); Assert.assertFalse(dataSubscriber.isCompleted()); Assert.assertNotNull(dataSubscriber.getSubscription()); }
Example 2
Source File: JAXRSRxJava3FlowableTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testGetHelloWorldJson() throws Exception { String address = "http://localhost:" + PORT + "/rx3/flowable/textJson"; List<Object> providers = new LinkedList<>(); providers.add(new JacksonJsonProvider()); providers.add(new FlowableRxInvokerProvider()); WebClient wc = WebClient.create(address, providers); Flowable<HelloWorldBean> obs = wc.accept("application/json") .rx(FlowableRxInvoker.class) .get(HelloWorldBean.class); final TestSubscriber<HelloWorldBean> subscriber = new TestSubscriber<>(); obs.subscribe(subscriber); subscriber.await(3, TimeUnit.SECONDS); subscriber.assertResult(new HelloWorldBean("Hello", "World")); }
Example 3
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void completeClearsCacheAndResubscribesStartingWithDefault() { List<String> start = new ArrayList<>(); start.add("initA"); PublishProcessor<String> upstream = PublishProcessor.create(); Flowable<String> replayed = upstream.startWithIterable(start).compose(ReplayingShare.createWithDefault("default")); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); replayed.subscribe(subscriber1); subscriber1.assertValues("default", "initA"); TestSubscriber<String> observer2 = new TestSubscriber<>(); replayed.subscribe(observer2); subscriber1.assertValues("default", "initA"); upstream.onComplete(); subscriber1.assertComplete(); observer2.assertComplete(); start.set(0, "initB"); TestSubscriber<String> observer3 = new TestSubscriber<>(); replayed.subscribe(observer3); observer3.assertValues("default", "initB"); }
Example 4
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void errorClearsCacheAndResubscribes() { List<String> start = new ArrayList<>(); start.add("initA"); PublishProcessor<String> upstream = PublishProcessor.create(); Flowable<String> replayed = upstream.startWithIterable(start).compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); replayed.subscribe(subscriber1); subscriber1.assertValues("initA"); TestSubscriber<String> observer2 = new TestSubscriber<>(); replayed.subscribe(observer2); subscriber1.assertValues("initA"); RuntimeException r = new RuntimeException(); upstream.onError(r); subscriber1.assertError(r); observer2.assertError(r); start.set(0, "initB"); TestSubscriber<String> observer3 = new TestSubscriber<>(); replayed.subscribe(observer3); observer3.assertValues("initB"); }
Example 5
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void completeClearsCacheAndResubscribes() { List<String> start = new ArrayList<>(); start.add("initA"); PublishProcessor<String> upstream = PublishProcessor.create(); Flowable<String> replayed = upstream.startWithIterable(start).compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); replayed.subscribe(subscriber1); subscriber1.assertValues("initA"); TestSubscriber<String> observer2 = new TestSubscriber<>(); replayed.subscribe(observer2); subscriber1.assertValues("initA"); upstream.onComplete(); subscriber1.assertComplete(); observer2.assertComplete(); start.set(0, "initB"); TestSubscriber<String> observer3 = new TestSubscriber<>(); replayed.subscribe(observer3); observer3.assertValues("initB"); }
Example 6
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void streamsDoNotShareInstances() { PublishProcessor<String> subjectA = PublishProcessor.create(); Flowable<String> flowableA = subjectA.compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriberA1 = new TestSubscriber<>(); flowableA.subscribe(subscriberA1); PublishProcessor<String> subjectB = PublishProcessor.create(); Flowable<String> flowableB = subjectB.compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriberB1 = new TestSubscriber<>(); flowableB.subscribe(subscriberB1); subjectA.onNext("Foo"); subscriberA1.assertValues("Foo"); subjectB.onNext("Bar"); subscriberB1.assertValues("Bar"); TestSubscriber<String> subscriberA2 = new TestSubscriber<>(); flowableA.subscribe(subscriberA2); subscriberA2.assertValues("Foo"); TestSubscriber<String> subscriberB2 = new TestSubscriber<>(); flowableB.subscribe(subscriberB2); subscriberB2.assertValues("Bar"); }
Example 7
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void backpressureHonoredWhenCached() { PublishProcessor<String> subject = PublishProcessor.create(); Flowable<String> flowable = subject.compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); flowable.subscribe(subscriber1); subscriber1.assertNoValues(); subject.onNext("Foo"); subscriber1.assertValues("Foo"); TestSubscriber<String> subscriber2 = new TestSubscriber<>(0); flowable.subscribe(subscriber2); subscriber2.assertNoValues(); subject.onNext("Bar"); // Replace the cached value... subscriber2.request(1); // ...and ensure new requests see it. subscriber2.assertValues("Bar"); }
Example 8
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@SuppressWarnings("CheckReturnValue") @Test public void fatalExceptionDuringReplayThrown() { PublishProcessor<String> subject = PublishProcessor.create(); Flowable<String> flowable = subject.compose(ReplayingShare.<String>instance()); flowable.subscribe(); subject.onNext("Foo"); Consumer<String> brokenAction = new Consumer<String>() { @Override public void accept(String s) { throw new OutOfMemoryError("broken!"); } }; try { flowable.subscribe(brokenAction); fail(); } catch (OutOfMemoryError e) { assertEquals("broken!", e.getMessage()); } }
Example 9
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void valueMissedWhenNoSubscribers() { PublishProcessor<String> subject = PublishProcessor.create(); Flowable<String> flowable = subject.compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); flowable.subscribe(subscriber1); subscriber1.assertNoValues(); subscriber1.cancel(); subject.onNext("Foo"); subscriber1.assertNoValues(); TestSubscriber<String> subscriber2 = new TestSubscriber<>(); flowable.subscribe(subscriber2); subscriber2.assertNoValues(); }
Example 10
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void initialValueToNewSubscriberAfterUnsubscribe() { PublishProcessor<String> subject = PublishProcessor.create(); Flowable<String> flowable = subject.compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); flowable.subscribe(subscriber1); subscriber1.assertNoValues(); subject.onNext("Foo"); subscriber1.assertValues("Foo"); subscriber1.cancel(); TestSubscriber<String> subscriber2 = new TestSubscriber<>(); flowable.subscribe(subscriber2); subscriber2.assertValues("Foo"); }
Example 11
Source File: QueryObserverTest.java From objectbox-java with Apache License 2.0 | 6 votes |
@Test public void flowableOneByOne() { publisher.setQueryResult(listResult); Flowable<String> flowable = RxQuery.flowableOneByOne(mockQuery.getQuery()); TestObserver testObserver = new TestObserver(); testObserver.resetLatch(2); //noinspection ResultOfMethodCallIgnored flowable.subscribe(testObserver); testObserver.assertLatchCountedDown(2); assertEquals(2, testObserver.receivedChanges.size()); assertEquals(1, testObserver.receivedChanges.get(0).size()); assertEquals(1, testObserver.receivedChanges.get(1).size()); assertNull(testObserver.error); testObserver.receivedChanges.clear(); publisher.publish(); testObserver.assertNoMoreResults(); }
Example 12
Source File: DataServiceTest.java From java-11-examples with Apache License 2.0 | 6 votes |
@Test public void testDataServiceWithBackPressureComplete() throws InterruptedException { DataService dataService = new DataServiceImpl(executor); Flowable<DataItem> dataFlow = dataService.getDataFlowWithBackPressure(new DataQuery("query1-back-pressure-complete", 10)); LOG.info("query submitted"); SynchronousDataSubscriber dataSubscriber = new SynchronousDataSubscriber(); dataFlow.subscribe(dataSubscriber); dataSubscriber.request(10); dataSubscriber.await(10, TimeUnit.SECONDS); LOG.info("evaluating test results"); Assert.assertTrue(dataSubscriber.getErrors().size() == 0); Assert.assertTrue(dataSubscriber.getResults().size() == 10); Assert.assertTrue(dataSubscriber.isCompleted()); Assert.assertNotNull(dataSubscriber.getSubscription()); }
Example 13
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 5 votes |
@Test public void initialValueToNewSubscriber() { PublishProcessor<String> subject = PublishProcessor.create(); Flowable<String> flowable = subject.compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); flowable.subscribe(subscriber1); subscriber1.assertNoValues(); subject.onNext("Foo"); subscriber1.assertValues("Foo"); TestSubscriber<String> subscriber2 = new TestSubscriber<>(); flowable.subscribe(subscriber2); subscriber2.assertValues("Foo"); }
Example 14
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 5 votes |
@Test public void noInitialValue() { PublishProcessor<String> subject = PublishProcessor.create(); Flowable<String> flowable = subject.compose(ReplayingShare.<String>instance()); TestSubscriber<String> subscriber = new TestSubscriber<>(); flowable.subscribe(subscriber); subscriber.assertNoValues(); }
Example 15
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 5 votes |
@Test public void unsubscribeBeforeSubscribePreventsCacheEmission() { PublishProcessor<String> upstream = PublishProcessor.create(); Flowable<String> replayed = upstream.compose(ReplayingShare.<String>instance()); replayed.subscribe(); upstream.onNext("something to cache"); TestSubscriber<String> testSubscriber = new TestSubscriber<>(); testSubscriber.cancel(); replayed.subscribe(testSubscriber); testSubscriber.assertNoValues(); }
Example 16
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 5 votes |
@Test public void defaultValueOnSubscribe() { PublishProcessor<String> subject = PublishProcessor.create(); Flowable<String> flowable = subject.compose(ReplayingShare.createWithDefault("default")); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); flowable.subscribe(subscriber1); subscriber1.assertValues("default"); subject.onNext("Foo"); subscriber1.assertValues("default", "Foo"); }
Example 17
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 5 votes |
@Test public void defaultValueIsOverriddenByLatestEmissionForNewSubscriber() { PublishProcessor<String> subject = PublishProcessor.create(); Flowable<String> flowable = subject.compose(ReplayingShare.createWithDefault("default")); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); flowable.subscribe(subscriber1); subscriber1.assertValues("default"); subject.onNext("Foo"); subscriber1.assertValues("default", "Foo"); TestSubscriber<String> observer2 = new TestSubscriber<>(); flowable.subscribe(observer2); observer2.assertValues("Foo"); }
Example 18
Source File: ReplayingShareFlowableTest.java From RxReplayingShare with Apache License 2.0 | 5 votes |
@Test public void errorClearsCacheAndResubscribesStartingWithDefault() { List<String> start = new ArrayList<>(); start.add("initA"); PublishProcessor<String> upstream = PublishProcessor.create(); Flowable<String> replayed = upstream.startWithIterable(start).compose(ReplayingShare.createWithDefault("default")); TestSubscriber<String> subscriber1 = new TestSubscriber<>(); replayed.subscribe(subscriber1); subscriber1.assertValues("default", "initA"); TestSubscriber<String> observer2 = new TestSubscriber<>(); replayed.subscribe(observer2); subscriber1.assertValues("default", "initA"); RuntimeException r = new RuntimeException(); upstream.onError(r); subscriber1.assertError(r); observer2.assertError(r); start.set(0, "initB"); TestSubscriber<String> observer3 = new TestSubscriber<>(); replayed.subscribe(observer3); observer3.assertValues("default", "initB"); }
Example 19
Source File: ReactiveIOInvoker.java From cxf with Apache License 2.0 | 5 votes |
protected AsyncResponseImpl handleFlowable(Message inMessage, Flowable<?> f) { final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); if (!isStreamingSubscriberUsed(f, asyncResponse, inMessage)) { Disposable d = f.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse, t)); if (d == null) { throw new IllegalStateException("Subscribe did not return a Disposable"); } } return asyncResponse; }