Top Description Inners Fields Constructors Methods
io.reactivex.rxjava3.schedulers

public final Class TestScheduler

extends Scheduler
Class Inheritance
Imports
java.util.Queue, java.util.concurrent.*, java.util.concurrent.atomic.AtomicReference, io.reactivex.rxjava3.annotations.*, io.reactivex.rxjava3.core.Scheduler, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.internal.disposables.EmptyDisposable, io.reactivex.rxjava3.plugins.RxJavaPlugins

A special, non thread-safe scheduler for testing operators that require a scheduler without introducing real concurrency and allows manually advancing a virtual time.

By default, the tasks submitted via the various schedule methods are not wrapped by the RxJavaPlugins#onSchedule(Runnable) hook. To enable this behavior, create a TestScheduler via TestScheduler(boolean) or TestScheduler(long, TimeUnit, boolean).

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv long
counter

The per-scheduler global order counter.

pack-priv final Queue<TestScheduler.TimedRunnable>
queue

The ordered queue for the runnable tasks.

pack-priv volatile long
pack-priv final boolean
useOnScheduleHook

Use the RxJavaPlugins#onSchedule(Runnable) hook when scheduling tasks.

Constructor Summary

AccessConstructor and Description
public
TestScheduler()

Creates a new TestScheduler with initial virtual time of zero.

public
TestScheduler(boolean
if true, the tasks submitted to this TestScheduler is wrapped via the RxJavaPlugins#onSchedule(Runnable) hook
useOnScheduleHook
)

Creates a new TestScheduler with the option to use the RxJavaPlugins#onSchedule(Runnable) hook when scheduling tasks.

public
TestScheduler(long
the point in time to move the Scheduler's clock to
delayTime
,
TimeUnit
the units of time that delayTime is expressed in
unit
)

Creates a new TestScheduler with the specified initial virtual time.

public
TestScheduler(long
the point in time to move the Scheduler's clock to
delayTime
,
TimeUnit
the units of time that delayTime is expressed in
unit
,
boolean
if true, the tasks submitted to this TestScheduler is wrapped via the RxJavaPlugins#onSchedule(Runnable) hook
useOnScheduleHook
)

Creates a new TestScheduler with the specified initial virtual time and with the option to use the RxJavaPlugins#onSchedule(Runnable) hook when scheduling tasks.

Method Summary

Modifier and TypeMethod and Description
public void
advanceTimeBy(long
the amount of time to move the Scheduler's clock forward
delayTime
,
TimeUnit
the units of time that delayTime is expressed in
unit
)

Moves the Scheduler's clock forward by a specified amount of time.

public void
advanceTimeTo(long
the point in time to move the Scheduler's clock to
delayTime
,
TimeUnit
the units of time that delayTime is expressed in
unit
)

Moves the Scheduler's clock to a particular moment in time.

public @NonNull Scheduler.Worker
createWorker()

Implements abstract io.reactivex.rxjava3.core.Scheduler.createWorker.

Retrieves or creates a new Scheduler.Worker that represents sequential execution of actions.
public long
public void
triggerActions()

Triggers any actions that have not yet been triggered and that are scheduled to be triggered at or before this Scheduler's present time.

private void
triggerActions(long targetTimeInNanoseconds)

Inherited from io.reactivex.rxjava3.core.Scheduler:
clockDriftTolerancenowscheduleDirectscheduleDirectschedulePeriodicallyDirectshutdownstartwhen

Field Detail

counterback to summary
pack-priv long counter

The per-scheduler global order counter.

queueback to summary
pack-priv final Queue<TestScheduler.TimedRunnable> queue

The ordered queue for the runnable tasks.

timeback to summary
pack-priv volatile long time
useOnScheduleHookback to summary
pack-priv final boolean useOnScheduleHook

Use the RxJavaPlugins#onSchedule(Runnable) hook when scheduling tasks.

Constructor Detail

TestSchedulerback to summary
public TestScheduler()

Creates a new TestScheduler with initial virtual time of zero.

TestSchedulerback to summary
public TestScheduler(boolean useOnScheduleHook)

Creates a new TestScheduler with the option to use the RxJavaPlugins#onSchedule(Runnable) hook when scheduling tasks.

History: 3.0.10 - experimental

Parameters
useOnScheduleHook:boolean

if true, the tasks submitted to this TestScheduler is wrapped via the RxJavaPlugins#onSchedule(Runnable) hook

Since
3.1.0
TestSchedulerback to summary
public TestScheduler(long delayTime, TimeUnit unit)

Creates a new TestScheduler with the specified initial virtual time.

Parameters
delayTime:long

the point in time to move the Scheduler's clock to

unit:TimeUnit

the units of time that delayTime is expressed in

TestSchedulerback to summary
public TestScheduler(long delayTime, TimeUnit unit, boolean useOnScheduleHook)

Creates a new TestScheduler with the specified initial virtual time and with the option to use the RxJavaPlugins#onSchedule(Runnable) hook when scheduling tasks.

History: 3.0.10 - experimental

Parameters
delayTime:long

the point in time to move the Scheduler's clock to

unit:TimeUnit

the units of time that delayTime is expressed in

useOnScheduleHook:boolean

if true, the tasks submitted to this TestScheduler is wrapped via the RxJavaPlugins#onSchedule(Runnable) hook

Since
3.1.0

Method Detail

advanceTimeByback to summary
public void advanceTimeBy(long delayTime, TimeUnit unit)

Moves the Scheduler's clock forward by a specified amount of time.

Parameters
delayTime:long

the amount of time to move the Scheduler's clock forward

unit:TimeUnit

the units of time that delayTime is expressed in

advanceTimeToback to summary
public void advanceTimeTo(long delayTime, TimeUnit unit)

Moves the Scheduler's clock to a particular moment in time.

Parameters
delayTime:long

the point in time to move the Scheduler's clock to

unit:TimeUnit

the units of time that delayTime is expressed in

createWorkerback to summary
public @NonNull Scheduler.Worker createWorker()

Implements abstract io.reactivex.rxjava3.core.Scheduler.createWorker.

Doc from io.reactivex.rxjava3.core.Scheduler.createWorker.

Retrieves or creates a new Scheduler.Worker that represents sequential execution of actions.

When work is completed, the Worker instance should be released by calling Scheduler.Worker#dispose() to avoid potential resource leaks in the underlying task-execution scheme.

Work on a Scheduler.Worker is guaranteed to be sequential and non-overlapping.

Returns:@NonNull Scheduler.Worker

a Worker representing a serial queue of actions to be executed

Annotations
@NonNull
@Override
nowback to summary
public long now(@NonNull TimeUnit unit)
Annotations
@Override
triggerActionsback to summary
public void triggerActions()

Triggers any actions that have not yet been triggered and that are scheduled to be triggered at or before this Scheduler's present time.

triggerActionsback to summary
private void triggerActions(long targetTimeInNanoseconds)
io.reactivex.rxjava3.schedulers back to summary

pack-priv final Class TestScheduler.TestWorker

extends Worker
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public boolean
isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public long
public @NonNull Disposable
schedule(@NonNull Runnable run, long delayTime, @NonNull TimeUnit unit)

public @NonNull Disposable
Inherited from io.reactivex.rxjava3.core.Scheduler.Worker:
nowschedulescheduleschedulePeriodically

Field Detail

disposedback to summary
pack-priv volatile boolean disposed

Constructor Detail

TestWorkerback to summary
pack-priv TestWorker()

Method Detail

disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Doc from io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
nowback to summary
public long now(@NonNull TimeUnit unit)
Annotations
@Override
scheduleback to summary
public @NonNull Disposable schedule(@NonNull Runnable run, long delayTime, @NonNull TimeUnit unit)
Annotations
@NonNull
@Override
scheduleback to summary
public @NonNull Disposable schedule(@NonNull Runnable run)
Annotations
@NonNull
@Override
io.reactivex.rxjava3.schedulers back to summary

pack-priv final Class TestScheduler.TestWorker.QueueRemove

extends AtomicReference<TestScheduler.TimedRunnable>
implements Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.disposables.Disposable

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicReference.serialVersionUID.

Constructor Detail

QueueRemoveback to summary
pack-priv QueueRemove(TestScheduler.TimedRunnable timedAction)

Method Detail

disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Doc from io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
io.reactivex.rxjava3.schedulers back to summary

pack-priv final Class TestScheduler.TimedRunnable

extends Object
implements Comparable<TestScheduler.TimedRunnable>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

Field Summary

Modifier and TypeField and Description
pack-priv final long
pack-priv final Runnable
pack-priv final TestScheduler.TestWorker
pack-priv final long

Constructor Summary

AccessConstructor and Description
pack-priv
TimedRunnable(TestScheduler.TestWorker scheduler, long time, Runnable run, long count)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(TestScheduler.TimedRunnable
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

countback to summary
pack-priv final long count
runback to summary
pack-priv final Runnable run
schedulerback to summary
pack-priv final TestScheduler.TestWorker scheduler
timeback to summary
pack-priv final long time

Constructor Detail

TimedRunnableback to summary
pack-priv TimedRunnable(TestScheduler.TestWorker scheduler, long time, Runnable run, long count)

Method Detail

compareToback to summary
public int compareTo(TestScheduler.TimedRunnable o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:TestScheduler.TimedRunnable

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override