use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout.
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws InterruptedException {
// From https://github.com/ReactiveX/RxJava/pull/951
final Disposable upstream = mock(Disposable.class);
Observable<String> never = Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> observer) {
observer.onSubscribe(upstream);
}
});
TestScheduler testScheduler = new TestScheduler();
Observable<String> observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
TestObserverEx<String> observer = new TestObserverEx<>();
observableWithTimeout.subscribe(observer);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
observer.assertFailureAndMessage(TimeoutException.class, timeoutMessage(1000, TimeUnit.MILLISECONDS));
verify(upstream, times(1)).dispose();
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableThrottleFirstTest method throttlingWithError.
@Test
public void throttlingWithError() {
Observable<String> source = Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> innerObserver) {
innerObserver.onSubscribe(Disposable.empty());
Exception error = new TestException();
// Should be published since it is first
publishNext(innerObserver, 100, "one");
// Should be skipped since onError will arrive before the timeout expires
publishNext(innerObserver, 200, "two");
// Should be published as soon as the timeout expires.
publishError(innerObserver, 300, error);
}
});
Observable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(400, TimeUnit.MILLISECONDS);
inOrder.verify(observer).onNext("one");
inOrder.verify(observer).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRepeatWhen.
@Test
public void noCancelPreviousRepeatWhen() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> get() throws Exception {
if (times.get() < 4) {
return Observable.error(new TestException());
}
return Observable.just(1);
}
}).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retryWhen(new Function<Observable<Throwable>, ObservableSource<?>>() {
@Override
public ObservableSource<?> apply(Observable<Throwable> e) throws Exception {
return e.takeWhile(new Predicate<Object>() {
@Override
public boolean test(Object v) throws Exception {
return times.getAndIncrement() < 4;
}
});
}
}).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRetry.
@Test
public void noCancelPreviousRetry() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> get() throws Exception {
if (times.getAndIncrement() < 4) {
return Observable.error(new TestException());
}
return Observable.just(1);
}
}).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retry(5).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class JavadocWording method maybeDocRefersToMaybeTypes.
@Test
public void maybeDocRefersToMaybeTypes() throws Exception {
List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Maybe"), "Maybe");
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("onNext", jdx);
if (idx >= 0) {
if (!m.signature.contains("Publisher") && !m.signature.contains("Flowable") && !m.signature.contains("Observable") && !m.signature.contains("ObservableSource")) {
e.append("java.lang.RuntimeException: Maybe doc mentions onNext but no Flowable/Observable in signature\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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("Subscriber", jdx);
if (idx >= 0) {
if (!m.signature.contains("Publisher") && !m.signature.contains("Flowable") && !m.signature.contains("TestSubscriber")) {
e.append("java.lang.RuntimeException: Maybe doc mentions Subscriber but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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(" Subscription", jdx);
if (idx >= 0) {
if (!m.signature.contains("Publisher") && !m.signature.contains("Flowable")) {
e.append("java.lang.RuntimeException: Maybe doc mentions Subscription but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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") && !m.signature.contains("TestObserver")) {
if (idx < 5 || !m.javadoc.substring(idx - 5, idx + 8).equals("MaybeObserver")) {
e.append("java.lang.RuntimeException: Maybe doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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("Publisher", jdx);
if (idx >= 0) {
if (!m.signature.contains("Publisher")) {
if (idx == 0 || !m.javadoc.substring(idx - 1, idx + 9).equals("(Publisher")) {
e.append("java.lang.RuntimeException: Maybe doc mentions Publisher but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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("Flowable", jdx);
if (idx >= 0) {
if (!m.signature.contains("Flowable")) {
Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Flowable");
if (!p.matcher(m.javadoc).find()) {
e.append("java.lang.RuntimeException: Maybe doc mentions Flowable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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("Single", jdx);
if (idx >= 0 && m.javadoc.indexOf("Single#", jdx) != idx) {
int j = m.javadoc.indexOf("#toSingle", jdx);
int k = m.javadoc.indexOf("{@code Single", jdx);
if (!m.signature.contains("Single") && (j + 3 != idx && k + 7 != idx)) {
e.append("java.lang.RuntimeException: Maybe doc mentions Single but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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("SingleSource", jdx);
if (idx >= 0) {
if (!m.signature.contains("SingleSource")) {
e.append("java.lang.RuntimeException: Maybe doc mentions SingleSource but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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")) {
Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Observable");
if (!p.matcher(m.javadoc).find()) {
e.append("java.lang.RuntimeException: Maybe doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.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: Maybe doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
}
jdx = idx + 6;
} else {
break;
}
}
checkAtReturnAndSignatureMatch("Maybe", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
aOrAn(e, m, "Maybe");
missingClosingDD(e, m, "Maybe", "io.reactivex.rxjava3.core");
backpressureMentionedWithoutAnnotation(e, m, "Maybe");
}
}
if (e.length() != 0) {
System.out.println(e);
fail(e.toString());
}
}
Aggregations