use of io.reactivex.Scheduler.Worker in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerSchedulePeriodicallyReschedulesItself.
@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyReschedulesItself() {
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
worker.schedulePeriodically(counter, 1, 1, MINUTES);
runUiThreadTasks();
assertEquals(0, counter.get());
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(1, counter.get());
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(2, counter.get());
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(3, counter.get());
}
use of io.reactivex.Scheduler.Worker in project RxJava by ReactiveX.
the class FlowableReplayTest method testIssue2191_SchedulerUnsubscribe.
/**
* Specifically test interaction with a Scheduler with subscribeOn.
*
* @throws Exception functional interfaces declare throws Exception
*/
@SuppressWarnings("unchecked")
@Test
public void testIssue2191_SchedulerUnsubscribe() throws Exception {
// setup mocks
Consumer<Integer> sourceNext = mock(Consumer.class);
Action sourceCompleted = mock(Action.class);
Action sourceUnsubscribed = mock(Action.class);
final Scheduler mockScheduler = mock(Scheduler.class);
final Disposable mockSubscription = mock(Disposable.class);
Worker spiedWorker = workerSpy(mockSubscription);
Subscriber<Integer> mockObserverBeforeConnect = TestHelper.mockSubscriber();
Subscriber<Integer> mockObserverAfterConnect = TestHelper.mockSubscriber();
when(mockScheduler.createWorker()).thenReturn(spiedWorker);
// Flowable under test
ConnectableFlowable<Integer> replay = Flowable.just(1, 2, 3).doOnNext(sourceNext).doOnCancel(sourceUnsubscribed).doOnComplete(sourceCompleted).subscribeOn(mockScheduler).replay();
replay.subscribe(mockObserverBeforeConnect);
replay.subscribe(mockObserverBeforeConnect);
replay.connect();
replay.subscribe(mockObserverAfterConnect);
replay.subscribe(mockObserverAfterConnect);
verify(mockObserverBeforeConnect, times(2)).onSubscribe((Subscription) any());
verify(mockObserverAfterConnect, times(2)).onSubscribe((Subscription) any());
// verify interactions
verify(sourceNext, times(1)).accept(1);
verify(sourceNext, times(1)).accept(2);
verify(sourceNext, times(1)).accept(3);
verify(sourceCompleted, times(1)).run();
verify(mockScheduler, times(1)).createWorker();
verify(spiedWorker, times(1)).schedule((Runnable) notNull());
verifyObserverMock(mockObserverBeforeConnect, 2, 6);
verifyObserverMock(mockObserverAfterConnect, 2, 6);
// FIXME not supported
// verify(spiedWorker, times(1)).isUnsubscribed();
// FIXME publish calls cancel too
verify(spiedWorker, times(1)).dispose();
verify(sourceUnsubscribed, never()).run();
verifyNoMoreInteractions(sourceNext);
verifyNoMoreInteractions(sourceCompleted);
verifyNoMoreInteractions(sourceUnsubscribed);
verifyNoMoreInteractions(spiedWorker);
verifyNoMoreInteractions(mockSubscription);
verifyNoMoreInteractions(mockScheduler);
verifyNoMoreInteractions(mockObserverBeforeConnect);
verifyNoMoreInteractions(mockObserverAfterConnect);
}
use of io.reactivex.Scheduler.Worker in project RxJava by ReactiveX.
the class FlowableSubscribeOnTest method deferredRequestRace.
@Test
public void deferredRequestRace() {
for (int i = 0; i < 500; i++) {
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L);
Worker w = Schedulers.computation().createWorker();
final SubscribeOnSubscriber<Integer> so = new SubscribeOnSubscriber<Integer>(ts, w, Flowable.<Integer>never(), true);
ts.onSubscribe(so);
final BooleanSubscription bs = new BooleanSubscription();
try {
Runnable r1 = new Runnable() {
@Override
public void run() {
so.onSubscribe(bs);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
so.request(1);
}
};
TestHelper.race(r1, r2);
} finally {
w.dispose();
}
}
}
use of io.reactivex.Scheduler.Worker in project RxJava by ReactiveX.
the class ImmediateThinSchedulerTest method schedule.
@Test
public void schedule() {
final int[] count = { 0 };
Worker w = ImmediateThinScheduler.INSTANCE.createWorker();
assertFalse(w.isDisposed());
w.schedule(new Runnable() {
@Override
public void run() {
count[0]++;
}
});
assertEquals(1, count[0]);
}
use of io.reactivex.Scheduler.Worker in project RxJava by ReactiveX.
the class TrampolineSchedulerInternalTest method reentrantScheduleDispose.
@Test
public void reentrantScheduleDispose() {
final Worker w = Schedulers.trampoline().createWorker();
try {
final int[] calls = { 0, 0 };
w.schedule(new Runnable() {
@Override
public void run() {
calls[0]++;
w.schedule(new Runnable() {
@Override
public void run() {
calls[1]++;
}
}).dispose();
}
});
assertEquals(1, calls[0]);
assertEquals(0, calls[1]);
} finally {
w.dispose();
}
}
Aggregations