|
27 | 27 | import org.reactivestreams.*;
|
28 | 28 |
|
29 | 29 | import io.reactivex.rxjava3.core.*;
|
| 30 | +import io.reactivex.rxjava3.core.Scheduler.Worker; |
30 | 31 | import io.reactivex.rxjava3.disposables.Disposable;
|
31 | 32 | import io.reactivex.rxjava3.functions.*;
|
32 | 33 | import io.reactivex.rxjava3.internal.disposables.SequentialDisposable;
|
@@ -771,4 +772,51 @@ public void schedulePeriodicallyDirectNullRunnable() {
|
771 | 772 | assertEquals("run is null", npe.getMessage());
|
772 | 773 | }
|
773 | 774 | }
|
| 775 | + |
| 776 | + void schedulePrint(Function<Runnable, Disposable> onSchedule) { |
| 777 | + CountDownLatch waitForBody = new CountDownLatch(1); |
| 778 | + CountDownLatch waitForPrint = new CountDownLatch(1); |
| 779 | + |
| 780 | + try { |
| 781 | + Disposable d = onSchedule.apply(() -> { |
| 782 | + waitForBody.countDown(); |
| 783 | + try { |
| 784 | + waitForPrint.await(); |
| 785 | + } catch (InterruptedException ex) { |
| 786 | + ex.printStackTrace(); |
| 787 | + } |
| 788 | + }); |
| 789 | + |
| 790 | + waitForBody.await(); |
| 791 | + |
| 792 | + assertNotEquals("", d.toString()); |
| 793 | + } catch (Throwable ex) { |
| 794 | + throw new AssertionError(ex); |
| 795 | + } finally { |
| 796 | + waitForPrint.countDown(); |
| 797 | + } |
| 798 | + } |
| 799 | + |
| 800 | + @Test |
| 801 | + public void scheduleDirectPrint() { |
| 802 | + if (getScheduler() instanceof TrampolineScheduler) { |
| 803 | + // no concurrency with Trampoline |
| 804 | + return; |
| 805 | + } |
| 806 | + schedulePrint(r -> getScheduler().scheduleDirect(r)); |
| 807 | + } |
| 808 | + |
| 809 | + @Test |
| 810 | + public void schedulePrint() { |
| 811 | + if (getScheduler() instanceof TrampolineScheduler) { |
| 812 | + // no concurrency with Trampoline |
| 813 | + return; |
| 814 | + } |
| 815 | + Worker worker = getScheduler().createWorker(); |
| 816 | + try { |
| 817 | + schedulePrint(worker::schedule); |
| 818 | + } finally { |
| 819 | + worker.dispose(); |
| 820 | + } |
| 821 | + } |
774 | 822 | }
|
0 commit comments