use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class JavadocWording method observableDocRefersToObservableTypes.
@Test
public void observableDocRefersToObservableTypes() throws Exception {
List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Observable"), "Observable");
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: Observable doc mentions onSuccess\r\n at io.reactivex.rxjava3.core.").append("Observable.method(Observable.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("Flowable") && !m.signature.contains("Publisher")) {
e.append("java.lang.RuntimeException: Observable doc mentions Subscription but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Observable.method(Observable.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")) {
if (idx < 6 || !m.javadoc.substring(idx - 6, idx + 8).equals("@link Flowable")) {
e.append("java.lang.RuntimeException: Observable doc mentions Flowable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Observable.method(Observable.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")) {
e.append("java.lang.RuntimeException: Observable doc mentions Publisher but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Observable.method(Observable.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")) {
e.append("java.lang.RuntimeException: Observable doc mentions Subscriber but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Observable.method(Observable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
}
jdx = idx + 6;
} else {
break;
}
}
checkAtReturnAndSignatureMatch("Observable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "ConnectableObservable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
aOrAn(e, m, "Observable");
missingClosingDD(e, m, "Observable", "io.reactivex.rxjava3.core");
backpressureMentionedWithoutAnnotation(e, m, "Observable");
}
}
if (e.length() != 0) {
System.out.println(e);
fail(e.toString());
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class XFlatMapTest method maybeNotificationEmpty.
@Test
public void maybeNotificationEmpty() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestObserver<Integer> to = Maybe.<Integer>empty().subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Maybe<Integer>>() {
@Override
public Maybe<Integer> apply(Integer v) throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}, new Function<Throwable, Maybe<Integer>>() {
@Override
public Maybe<Integer> apply(Throwable v) throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}, new Supplier<Maybe<Integer>>() {
@Override
public Maybe<Integer> get() throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(to);
to.dispose();
Thread.sleep(SLEEP_AFTER_CANCEL);
to.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class XFlatMapTest method maybeNotificationSuccess.
@Test
public void maybeNotificationSuccess() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestObserver<Integer> to = Maybe.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Maybe<Integer>>() {
@Override
public Maybe<Integer> apply(Integer v) throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}, new Function<Throwable, Maybe<Integer>>() {
@Override
public Maybe<Integer> apply(Throwable v) throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}, new Supplier<Maybe<Integer>>() {
@Override
public Maybe<Integer> get() throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(to);
to.dispose();
Thread.sleep(SLEEP_AFTER_CANCEL);
to.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class XFlatMapTest method maybeNotificationError.
@Test
public void maybeNotificationError() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestObserver<Integer> to = Maybe.<Integer>error(new TestException()).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Maybe<Integer>>() {
@Override
public Maybe<Integer> apply(Integer v) throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}, new Function<Throwable, Maybe<Integer>>() {
@Override
public Maybe<Integer> apply(Throwable v) throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}, new Supplier<Maybe<Integer>>() {
@Override
public Maybe<Integer> get() throws Exception {
sleep();
return Maybe.<Integer>error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(to);
to.dispose();
Thread.sleep(SLEEP_AFTER_CANCEL);
to.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class MaybeTest method onTerminateDetach.
@Test
public void onTerminateDetach() throws Exception {
System.gc();
Thread.sleep(150);
long before = usedMemoryNow();
Maybe<Object> source = Flowable.just((Object) new Object[10000000]).singleElement();
long middle = usedMemoryNow();
MaybeObserver<Object> observer = new MaybeObserver<Object>() {
@SuppressWarnings("unused")
Disposable u;
@Override
public void onSubscribe(Disposable d) {
this.u = d;
}
@Override
public void onSuccess(Object value) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
};
source.onTerminateDetach().subscribe(observer);
source = null;
System.gc();
Thread.sleep(250);
long after = usedMemoryNow();
String log = String.format("%.2f MB -> %.2f MB -> %.2f MB%n", before / 1024.0 / 1024.0, middle / 1024.0 / 1024.0, after / 1024.0 / 1024.0);
System.out.printf(log);
if (before * 1.3 < after) {
fail("There seems to be a memory leak: " + log);
}
// hold onto the reference to prevent premature GC
assertNotNull(observer);
}
Aggregations