Search in sources :

Example 6 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.

the class JavadocWording method flowableDocRefersToFlowableTypes.

@Test
public void flowableDocRefersToFlowableTypes() throws Exception {
    List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Flowable"), "Flowable");
    assertFalse(list.isEmpty());
    StringBuilder e = new StringBuilder();
    for (RxMethod m : list) {
        int jdx;
        if (m.javadoc != null) {
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("onSuccess", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Maybe") && !m.signature.contains("MaybeSource") && !m.signature.contains("Single") && !m.signature.contains("SingleSource")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions onSuccess\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Observer", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("ObservableSource") && !m.signature.contains("Observable")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" SingleObserver", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("SingleSource") && !m.signature.contains("Single")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions SingleObserver but not using Single\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" MaybeObserver", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("MaybeSource") && !m.signature.contains("Maybe")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions MaybeObserver but not using Maybe\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Disposable", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Observable") && !m.signature.contains("ObservableSource") && !m.signature.contains("Single") && !m.signature.contains("SingleSource") && !m.signature.contains("Completable") && !m.signature.contains("CompletableSource") && !m.signature.contains("Maybe") && !m.signature.contains("MaybeSource") && !m.signature.contains("Disposable") && !m.signature.contains("void subscribe")) {
                        CharSequence subSequence = m.javadoc.subSequence(idx - 6, idx + 11);
                        if (idx < 6 || !subSequence.equals("{@link Disposable")) {
                            e.append("java.lang.RuntimeException: Flowable doc mentions Disposable but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Observable", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Observable")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("ObservableSource", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("ObservableSource")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            checkAtReturnAndSignatureMatch("Flowable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "ConnectableFlowable", "ParallelFlowable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
            aOrAn(e, m, "Flowable");
            missingClosingDD(e, m, "Flowable", "io.reactivex.rxjava3.core");
            backpressureMentionedWithoutAnnotation(e, m, "Flowable");
        }
    }
    if (e.length() != 0) {
        System.out.println(e);
        fail(e.toString());
    }
}
Also used : RxMethod(io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod) Test(org.junit.Test)

Example 7 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.

the class JavadocWording method parallelFlowableDocRefersToCorrectTypes.

@Test
public void parallelFlowableDocRefersToCorrectTypes() throws Exception {
    List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("ParallelFlowable", "io.reactivex.rxjava3.parallel"), "ParallelFlowable");
    assertFalse(list.isEmpty());
    StringBuilder e = new StringBuilder();
    for (RxMethod m : list) {
        int jdx;
        if (m.javadoc != null) {
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("onSuccess", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Maybe") && !m.signature.contains("MaybeSource") && !m.signature.contains("Single") && !m.signature.contains("SingleSource")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions onSuccess\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Observer", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("ObservableSource") && !m.signature.contains("Observable")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" SingleObserver", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("SingleSource") && !m.signature.contains("Single")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions SingleObserver but not using Single\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" MaybeObserver", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("MaybeSource") && !m.signature.contains("Maybe")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions MaybeObserver but not using Maybe\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Disposable", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Observable") && !m.signature.contains("ObservableSource") && !m.signature.contains("Single") && !m.signature.contains("SingleSource") && !m.signature.contains("Completable") && !m.signature.contains("CompletableSource") && !m.signature.contains("Maybe") && !m.signature.contains("MaybeSource") && !m.signature.contains("Disposable")) {
                        CharSequence subSequence = m.javadoc.subSequence(idx - 6, idx + 11);
                        if (idx < 6 || !subSequence.equals("{@link Disposable")) {
                            e.append("java.lang.RuntimeException: Flowable doc mentions Disposable but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Observable", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Observable")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("ObservableSource", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("ObservableSource")) {
                        e.append("java.lang.RuntimeException: Flowable doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Flowable.method(Flowable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            checkAtReturnAndSignatureMatch("ParallelFlowable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "ConnectableFlowable", "ParallelFlowable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
            aOrAn(e, m, "ParallelFlowable");
            missingClosingDD(e, m, "ParallelFlowable", "io.reactivex.rxjava3.parallel");
            backpressureMentionedWithoutAnnotation(e, m, "ParallelFlowable");
        }
    }
    if (e.length() != 0) {
        System.out.println(e);
        fail(e.toString());
    }
}
Also used : RxMethod(io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod) Test(org.junit.Test)

Example 8 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.

the class FlowableTests method publishLast.

@Test
public void publishLast() throws InterruptedException {
    final AtomicInteger count = new AtomicInteger();
    ConnectableFlowable<String> connectable = Flowable.<String>unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(final Subscriber<? super String> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            count.incrementAndGet();
            new Thread(new Runnable() {

                @Override
                public void run() {
                    subscriber.onNext("first");
                    subscriber.onNext("last");
                    subscriber.onComplete();
                }
            }).start();
        }
    }).takeLast(1).publish();
    // subscribe once
    final CountDownLatch latch = new CountDownLatch(1);
    connectable.subscribe(new Consumer<String>() {

        @Override
        public void accept(String value) {
            assertEquals("last", value);
            latch.countDown();
        }
    });
    // subscribe twice
    connectable.subscribe();
    Disposable subscription = connectable.connect();
    assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
    assertEquals(1, count.get());
    subscription.dispose();
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 9 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.

the class FlowableTests method replay.

@Test
public void replay() throws InterruptedException {
    final AtomicInteger counter = new AtomicInteger();
    ConnectableFlowable<String> f = Flowable.<String>unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(final Subscriber<? super String> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            new Thread(new Runnable() {

                @Override
                public void run() {
                    counter.incrementAndGet();
                    subscriber.onNext("one");
                    subscriber.onComplete();
                }
            }).start();
        }
    }).replay();
    // we connect immediately and it will emit the value
    Disposable connection = f.connect();
    try {
        // we then expect the following 2 subscriptions to get that same value
        final CountDownLatch latch = new CountDownLatch(2);
        // subscribe once
        f.subscribe(new Consumer<String>() {

            @Override
            public void accept(String v) {
                assertEquals("one", v);
                latch.countDown();
            }
        });
        // subscribe again
        f.subscribe(new Consumer<String>() {

            @Override
            public void accept(String v) {
                assertEquals("one", v);
                latch.countDown();
            }
        });
        if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
            fail("subscriptions did not receive values");
        }
        assertEquals(1, counter.get());
    } finally {
        connection.dispose();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 10 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.

the class FlowableReplayTest method disposeNoNeedForResetTimeBound.

@Test
public void disposeNoNeedForResetTimeBound() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.replay(10, TimeUnit.MINUTES);
    TestSubscriber<Integer> ts = cf.test();
    Disposable d = cf.connect();
    pp.onNext(1);
    d.dispose();
    ts = cf.test();
    ts.assertEmpty();
    cf.connect();
    ts.assertEmpty();
    pp.onNext(2);
    ts.assertValuesOnly(2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Aggregations

Disposable (io.reactivex.rxjava3.disposables.Disposable)25 Test (org.junit.Test)14 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)4 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)3 TestException (io.reactivex.rxjava3.exceptions.TestException)2 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)2 ScalarSubscription (io.reactivex.rxjava3.internal.subscriptions.ScalarSubscription)2 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)2 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)2 Observable (io.reactivex.rxjava3.core.Observable)1 Observer (io.reactivex.rxjava3.core.Observer)1 HasUpstreamPublisher (io.reactivex.rxjava3.internal.fuseable.HasUpstreamPublisher)1 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)1 ConnectConsumer (io.reactivex.rxjava3.internal.util.ConnectConsumer)1 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)1 ParallelFlowable (io.reactivex.rxjava3.parallel.ParallelFlowable)1 IOException (java.io.IOException)1