Java Code Examples for io.reactivex.rxjava3.core.Scheduler#Worker
The following examples show how to use
io.reactivex.rxjava3.core.Scheduler#Worker .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 5 votes |
@Test public void betweenPeriodicSchedulesReportsIdle() { Scheduler.Worker worker = scheduler.createWorker(); CountingRunnable action = new CountingRunnable(); worker.schedulePeriodically(action, 0, 1, SECONDS); delegate.triggerActions(); assertEquals(1, action.count()); delegate.advanceTimeBy(500, MILLISECONDS); assertIdle(1); delegate.advanceTimeBy(1000, MILLISECONDS); assertIdle(2); }
Example 2
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 5 votes |
@Test public void unsubscribingScheduledWorkWhileRunningWorkReportsBusy() { final Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(() -> { worker.dispose(); assertBusy(); }); delegate.triggerActions(); }
Example 3
Source File: ReplayRelayBoundedConcurrencyTest.java From RxRelay with Apache License 2.0 | 4 votes |
@Test public void testReplaySubjectEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); Scheduler.Worker worker = Schedulers.io().createWorker(); try { for (int i = 0; i < 50000; i++) { if (i % 1000 == 0) { System.out.println(i); } final ReplayRelay<Object> rs = ReplayRelay.createWithSize(2); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); // int j = i; worker.schedule(new Runnable() { @Override public void run() { try { start.await(); } catch (Exception e1) { e1.printStackTrace(); } // System.out.println("> " + j); rs.accept(1); } }); final AtomicReference<Object> o = new AtomicReference<Object>(); rs // .doOnSubscribe(v -> System.out.println("!! " + j)) // .doOnNext(e -> System.out.println(">> " + j)) .subscribeOn(s) .observeOn(Schedulers.io()) // .doOnNext(e -> System.out.println(">>> " + j)) .subscribe(new DefaultObserver<Object>() { @Override protected void onStart() { super.onStart(); } @Override public void onComplete() { o.set(-1); finish.countDown(); } @Override public void onError(Throwable e) { o.set(e); finish.countDown(); } @Override public void onNext(Object t) { o.set(t); finish.countDown(); } }); start.countDown(); if (!finish.await(5, TimeUnit.SECONDS)) { System.out.println(o.get()); System.out.println(rs.hasObservers()); Assert.fail("Timeout @ " + i); break; } else { Assert.assertEquals(1, o.get()); } } } finally { worker.dispose(); } }
Example 4
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void scheduledWorkReportsBusy() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(new CountingRunnable()); assertBusy(); }
Example 5
Source File: ReplayRelayConcurrencyTest.java From RxRelay with Apache License 2.0 | 4 votes |
@Test public void testReplayRelayEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); Scheduler.Worker worker = Schedulers.io().createWorker(); try { for (int i = 0; i < 50000; i++) { if (i % 1000 == 0) { System.out.println(i); } final ReplayRelay<Object> rs = ReplayRelay.create(); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); worker.schedule(new Runnable() { @Override public void run() { try { start.await(); } catch (Exception e1) { e1.printStackTrace(); } rs.accept(1); } }); final AtomicReference<Object> o = new AtomicReference<Object>(); rs.subscribeOn(s).observeOn(Schedulers.io()) .subscribe(new DefaultObserver<Object>() { @Override public void onComplete() { o.set(-1); finish.countDown(); } @Override public void onError(Throwable e) { o.set(e); finish.countDown(); } @Override public void onNext(Object t) { o.set(t); finish.countDown(); } }); start.countDown(); if (!finish.await(5, TimeUnit.SECONDS)) { System.out.println(o.get()); System.out.println(rs.hasObservers()); Assert.fail("Timeout @ " + i); break; } else { Assert.assertEquals(1, o.get()); } } } finally { worker.dispose(); } }
Example 6
Source File: BehaviorRelayTest.java From RxRelay with Apache License 2.0 | 4 votes |
@Test @Ignore("OOMs") public void testEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); Scheduler.Worker worker = Schedulers.io().createWorker(); try { for (int i = 0; i < 50000; i++) { if (i % 1000 == 0) { System.out.println(i); } final BehaviorRelay<Object> rs = BehaviorRelay.create(); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); worker.schedule(new Runnable() { @Override public void run() { try { start.await(); } catch (Exception e1) { e1.printStackTrace(); } rs.accept(1); } }); final AtomicReference<Object> o = new AtomicReference<Object>(); rs.subscribeOn(s).observeOn(Schedulers.io()) .subscribe(new DefaultObserver<Object>() { @Override public void onComplete() { o.set(-1); finish.countDown(); } @Override public void onError(Throwable e) { o.set(e); finish.countDown(); } @Override public void onNext(Object t) { o.set(t); finish.countDown(); } }); start.countDown(); if (!finish.await(5, TimeUnit.SECONDS)) { System.out.println(o.get()); System.out.println(rs.hasObservers()); fail("Timeout @ " + i); break; } else { Assert.assertEquals(1, o.get()); } } } finally { worker.dispose(); } }
Example 7
Source File: ReplayRelayBoundedConcurrencyTest.java From RxRelay with Apache License 2.0 | 4 votes |
@Test public void testReplaySubjectEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); Scheduler.Worker worker = Schedulers.io().createWorker(); try { for (int i = 0; i < 50000; i++) { if (i % 1000 == 0) { System.out.println(i); } final ReplayRelay<Object> rs = ReplayRelay.createWithSize(2); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); // int j = i; worker.schedule(new Runnable() { @Override public void run() { try { start.await(); } catch (Exception e1) { e1.printStackTrace(); } // System.out.println("> " + j); rs.accept(1); } }); final AtomicReference<Object> o = new AtomicReference<Object>(); rs // .doOnSubscribe(v -> System.out.println("!! " + j)) // .doOnNext(e -> System.out.println(">> " + j)) .subscribeOn(s) .observeOn(Schedulers.io()) // .doOnNext(e -> System.out.println(">>> " + j)) .subscribe(new DefaultObserver<Object>() { @Override protected void onStart() { super.onStart(); } @Override public void onComplete() { o.set(-1); finish.countDown(); } @Override public void onError(Throwable e) { o.set(e); finish.countDown(); } @Override public void onNext(Object t) { o.set(t); finish.countDown(); } }); start.countDown(); if (!finish.await(5, TimeUnit.SECONDS)) { System.out.println(o.get()); System.out.println(rs.hasObservers()); Assert.fail("Timeout @ " + i); break; } else { Assert.assertEquals(1, o.get()); } } } finally { worker.dispose(); } }
Example 8
Source File: ReplayRelayConcurrencyTest.java From RxRelay with Apache License 2.0 | 4 votes |
@Test public void testReplayRelayEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); Scheduler.Worker worker = Schedulers.io().createWorker(); try { for (int i = 0; i < 50000; i++) { if (i % 1000 == 0) { System.out.println(i); } final ReplayRelay<Object> rs = ReplayRelay.create(); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); worker.schedule(new Runnable() { @Override public void run() { try { start.await(); } catch (Exception e1) { e1.printStackTrace(); } rs.accept(1); } }); final AtomicReference<Object> o = new AtomicReference<Object>(); rs.subscribeOn(s).observeOn(Schedulers.io()) .subscribe(new DefaultObserver<Object>() { @Override public void onComplete() { o.set(-1); finish.countDown(); } @Override public void onError(Throwable e) { o.set(e); finish.countDown(); } @Override public void onNext(Object t) { o.set(t); finish.countDown(); } }); start.countDown(); if (!finish.await(5, TimeUnit.SECONDS)) { System.out.println(o.get()); System.out.println(rs.hasObservers()); Assert.fail("Timeout @ " + i); break; } else { Assert.assertEquals(1, o.get()); } } } finally { worker.dispose(); } }
Example 9
Source File: BehaviorRelayTest.java From RxRelay with Apache License 2.0 | 4 votes |
@Test @Ignore("OOMs") public void testEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); Scheduler.Worker worker = Schedulers.io().createWorker(); try { for (int i = 0; i < 50000; i++) { if (i % 1000 == 0) { System.out.println(i); } final BehaviorRelay<Object> rs = BehaviorRelay.create(); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); worker.schedule(new Runnable() { @Override public void run() { try { start.await(); } catch (Exception e1) { e1.printStackTrace(); } rs.accept(1); } }); final AtomicReference<Object> o = new AtomicReference<Object>(); rs.subscribeOn(s).observeOn(Schedulers.io()) .subscribe(new DefaultObserver<Object>() { @Override public void onComplete() { o.set(-1); finish.countDown(); } @Override public void onError(Throwable e) { o.set(e); finish.countDown(); } @Override public void onNext(Object t) { o.set(t); finish.countDown(); } }); start.countDown(); if (!finish.await(5, TimeUnit.SECONDS)) { System.out.println(o.get()); System.out.println(rs.hasObservers()); fail("Timeout @ " + i); break; } else { Assert.assertEquals(1, o.get()); } } } finally { worker.dispose(); } }
Example 10
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void finishingWorkWithoutRegisteredCallbackDoesNotCrash() { IdlingResourceScheduler scheduler = Rx3Idler.wrap(delegate, "Bob"); Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(new CountingRunnable()); delegate.triggerActions(); }
Example 11
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void scheduleWorkAfterUnsubscribedReportsIdle() { Scheduler.Worker worker = scheduler.createWorker(); worker.dispose(); worker.schedule(new CountingRunnable()); assertIdle(0); }
Example 12
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void unsubscribingScheduledWorksReportsIdle() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(new CountingRunnable()); worker.dispose(); assertIdle(1); }
Example 13
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void runningWorkReportsBusy() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(this::assertBusy); delegate.triggerActions(); }
Example 14
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void schedulePeriodicallyWithNonZeroDelayReportsIdle() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedulePeriodically(new CountingRunnable(), 1, 1, SECONDS); assertIdle(0); }
Example 15
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void schedulePeriodicallyWithZeroDelayReportsBusy() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedulePeriodically(new CountingRunnable(), 0, 1, SECONDS); assertBusy(); }
Example 16
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void scheduleWithNonZeroDelayReportsIdle() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(new CountingRunnable(), 1, SECONDS); assertIdle(0); }
Example 17
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void scheduleWithZeroDelayReportsBusy() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(new CountingRunnable(), 0, SECONDS); assertBusy(); }
Example 18
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 4 votes |
@Test public void scheduledWorkUnsubscribedReportsIdle() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(new CountingRunnable()).dispose(); assertIdle(1); }