use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class SingleFromPublisherTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Single.fromPublisher(new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
BooleanSubscription s2 = new BooleanSubscription();
s.onSubscribe(s2);
assertTrue(s2.isCancelled());
s.onNext(1);
s.onComplete();
s.onNext(2);
s.onError(new TestException());
s.onComplete();
}
}).test().assertResult(1);
TestHelper.assertError(errors, 0, IllegalStateException.class, "Subscription already set!");
TestHelper.assertUndeliverable(errors, 1, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class AbstractSchedulerTests method subscribeOnNestedConcurrency.
@Test
public final void subscribeOnNestedConcurrency() throws InterruptedException {
final Scheduler scheduler = getScheduler();
Flowable<String> f = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten").flatMap(new Function<String, Flowable<String>>() {
@Override
public Flowable<String> apply(final String v) {
return Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onNext("value_after_map-" + v);
subscriber.onComplete();
}
}).subscribeOn(scheduler);
}
});
ConcurrentObserverValidator<String> observer = new ConcurrentObserverValidator<>();
f.subscribe(observer);
if (!observer.completed.await(3000, TimeUnit.MILLISECONDS)) {
fail("timed out");
}
if (observer.error.get() != null) {
observer.error.get().printStackTrace();
fail("Error: " + observer.error.get().getMessage());
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class TestSchedulerTest method nestedSchedule.
@Test
public final void nestedSchedule() {
final TestScheduler scheduler = new TestScheduler();
final Scheduler.Worker inner = scheduler.createWorker();
try {
final Runnable calledOp = mock(Runnable.class);
Flowable<Object> poller;
poller = Flowable.unsafeCreate(new Publisher<Object>() {
@Override
public void subscribe(final Subscriber<? super Object> aSubscriber) {
final BooleanSubscription bs = new BooleanSubscription();
aSubscriber.onSubscribe(bs);
inner.schedule(new Runnable() {
@Override
public void run() {
if (!bs.isCancelled()) {
calledOp.run();
inner.schedule(this, 5, TimeUnit.SECONDS);
}
}
});
}
});
InOrder inOrder = Mockito.inOrder(calledOp);
Disposable sub;
sub = poller.subscribe();
scheduler.advanceTimeTo(6, TimeUnit.SECONDS);
inOrder.verify(calledOp, times(2)).run();
sub.dispose();
scheduler.advanceTimeTo(11, TimeUnit.SECONDS);
inOrder.verify(calledOp, never()).run();
sub = poller.subscribe();
scheduler.advanceTimeTo(12, TimeUnit.SECONDS);
inOrder.verify(calledOp, times(1)).run();
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class RxJavaPluginsTest method clearIsPassthrough.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void clearIsPassthrough() {
try {
RxJavaPlugins.reset();
assertNull(RxJavaPlugins.onAssembly((Observable) null));
assertNull(RxJavaPlugins.onAssembly((ConnectableObservable) null));
assertNull(RxJavaPlugins.onAssembly((Flowable) null));
assertNull(RxJavaPlugins.onAssembly((ConnectableFlowable) null));
Observable oos = new Observable() {
@Override
public void subscribeActual(Observer t) {
}
};
Flowable fos = new Flowable() {
@Override
public void subscribeActual(Subscriber t) {
}
};
assertSame(oos, RxJavaPlugins.onAssembly(oos));
assertSame(fos, RxJavaPlugins.onAssembly(fos));
assertNull(RxJavaPlugins.onAssembly((Single) null));
Single sos = new Single() {
@Override
public void subscribeActual(SingleObserver t) {
}
};
assertSame(sos, RxJavaPlugins.onAssembly(sos));
assertNull(RxJavaPlugins.onAssembly((Completable) null));
Completable cos = new Completable() {
@Override
public void subscribeActual(CompletableObserver t) {
}
};
assertSame(cos, RxJavaPlugins.onAssembly(cos));
assertNull(RxJavaPlugins.onAssembly((Maybe) null));
Maybe myb = new Maybe() {
@Override
public void subscribeActual(MaybeObserver t) {
}
};
assertSame(myb, RxJavaPlugins.onAssembly(myb));
Runnable action = Functions.EMPTY_RUNNABLE;
assertSame(action, RxJavaPlugins.onSchedule(action));
class AllSubscriber implements Subscriber, Observer, SingleObserver, CompletableObserver, MaybeObserver {
@Override
public void onSuccess(Object value) {
}
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSubscribe(Subscription s) {
}
@Override
public void onNext(Object t) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
}
AllSubscriber all = new AllSubscriber();
Subscriber[] allArray = { all };
assertNull(RxJavaPlugins.onSubscribe(Observable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Observable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Flowable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Flowable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Single.just(1), null));
assertSame(all, RxJavaPlugins.onSubscribe(Single.just(1), all));
assertNull(RxJavaPlugins.onSubscribe(Completable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Completable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Maybe.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Maybe.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Flowable.never().parallel(), null));
assertSame(allArray, RxJavaPlugins.onSubscribe(Flowable.never().parallel(), allArray));
final Scheduler s = ImmediateThinScheduler.INSTANCE;
Supplier<Scheduler> c = new Supplier<Scheduler>() {
@Override
public Scheduler get() throws Exception {
return s;
}
};
assertSame(s, RxJavaPlugins.onComputationScheduler(s));
assertSame(s, RxJavaPlugins.onIoScheduler(s));
assertSame(s, RxJavaPlugins.onNewThreadScheduler(s));
assertSame(s, RxJavaPlugins.onSingleScheduler(s));
assertSame(s, RxJavaPlugins.initComputationScheduler(c));
assertSame(s, RxJavaPlugins.initIoScheduler(c));
assertSame(s, RxJavaPlugins.initNewThreadScheduler(c));
assertSame(s, RxJavaPlugins.initSingleScheduler(c));
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class ObservableConcatMapSchedulerTest method issue2890NoStackoverflow.
@Test
public void issue2890NoStackoverflow() throws InterruptedException, TimeoutException {
final ExecutorService executor = Executors.newFixedThreadPool(2);
final Scheduler sch = Schedulers.from(executor);
Function<Integer, Observable<Integer>> func = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t) {
Observable<Integer> flowable = Observable.just(t).subscribeOn(sch);
Subject<Integer> processor = UnicastSubject.create();
flowable.subscribe(processor);
return processor;
}
};
int n = 5000;
final AtomicInteger counter = new AtomicInteger();
Observable.range(1, n).concatMap(func, 2, ImmediateThinScheduler.INSTANCE).subscribe(new DefaultObserver<Integer>() {
@Override
public void onNext(Integer t) {
// Consume after sleep for 1 ms
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// ignored
}
if (counter.getAndIncrement() % 100 == 0) {
System.out.print("testIssue2890NoStackoverflow -> ");
System.out.println(counter.get());
}
;
}
@Override
public void onComplete() {
executor.shutdown();
}
@Override
public void onError(Throwable e) {
executor.shutdown();
}
});
long awaitTerminationTimeout = 100_000;
if (!executor.awaitTermination(awaitTerminationTimeout, TimeUnit.MILLISECONDS)) {
throw new TimeoutException("Completed " + counter.get() + "/" + n + " before timed out after " + awaitTerminationTimeout + " milliseconds.");
}
assertEquals(n, counter.get());
}
Aggregations