use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideConnectableObservable.
@SuppressWarnings("rawtypes")
@Test
public void overrideConnectableObservable() {
try {
RxJavaPlugins.setOnConnectableObservableAssembly(new Function<ConnectableObservable, ConnectableObservable>() {
@Override
public ConnectableObservable apply(ConnectableObservable co) throws Exception {
return new ConnectableObservable() {
@Override
public void connect(Consumer connection) {
}
@Override
public void reset() {
// nothing to do in this test
}
@SuppressWarnings("unchecked")
@Override
protected void subscribeActual(Observer observer) {
observer.onSubscribe(Disposable.empty());
observer.onNext(10);
observer.onComplete();
}
};
}
});
Observable.just(1).publish().autoConnect().test().assertResult(10);
} finally {
RxJavaPlugins.reset();
}
Observable.just(1).publish().autoConnect().test().assertResult(1);
}
use of io.reactivex.rxjava3.core.Observer 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);
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class TestObserverTest method errorDelegateThrows.
@Test
public void errorDelegateThrows() {
TestObserver<Integer> to = new TestObserver<>(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Integer value) {
}
@Override
public void onError(Throwable e) {
throw new TestException();
}
@Override
public void onComplete() {
throw new TestException();
}
});
to.onSubscribe(Disposable.empty());
try {
to.onError(new IOException());
throw new RuntimeException("Should have thrown!");
} catch (TestException ex) {
to.assertNotComplete().assertError(Throwable.class);
}
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class CompletableSubscribeOn method subscribeActual.
@Override
protected void subscribeActual(final CompletableObserver observer) {
final SubscribeOnObserver parent = new SubscribeOnObserver(observer, source);
observer.onSubscribe(parent);
Disposable f = scheduler.scheduleDirect(parent);
parent.task.replace(f);
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class CompletableMergeArrayDelayError method subscribeActual.
@Override
public void subscribeActual(final CompletableObserver observer) {
final CompositeDisposable set = new CompositeDisposable();
final AtomicInteger wip = new AtomicInteger(sources.length + 1);
final AtomicThrowable errors = new AtomicThrowable();
set.add(new TryTerminateAndReportDisposable(errors));
observer.onSubscribe(set);
for (CompletableSource c : sources) {
if (set.isDisposed()) {
return;
}
if (c == null) {
Throwable ex = new NullPointerException("A completable source is null");
errors.tryAddThrowableOrReport(ex);
wip.decrementAndGet();
continue;
}
c.subscribe(new MergeInnerCompletableObserver(observer, set, errors, wip));
}
if (wip.decrementAndGet() == 0) {
errors.tryTerminateConsumer(observer);
}
}
Aggregations