Top Description Inners Fields Constructors Methods
io.reactivex.schedulers

public final Class TestScheduler

extends Scheduler
Class Inheritance
Imports
java.util.Queue, java.util.concurrent.*, io.reactivex.Scheduler, io.reactivex.annotations.NonNull, io.reactivex.disposables.*, io.reactivex.internal.disposables.EmptyDisposable, io.reactivex.internal.functions.ObjectHelper

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

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

Constructor Summary

AccessConstructor and Description
public
TestScheduler()

Creates a new TestScheduler with initial virtual time of zero.

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.

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 Scheduler.Worker
createWorker()

Implements abstract io.reactivex.Scheduler.createWorker.

Retrieves or creates a new Scheduler.Worker that represents sequential execution of actions.
public long
now(TimeUnit
the time unit
unit
)

Overrides io.reactivex.Scheduler.now.

Returns the 'current time' of the Scheduler in the specified time unit.
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.Scheduler:
clockDriftTolerancescheduleDirectscheduleDirectschedulePeriodicallyDirectshutdownstartwhen

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

Constructor Detail

TestSchedulerback to summary
public TestScheduler()

Creates a new TestScheduler with initial virtual time of zero.

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

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 Scheduler.Worker createWorker()

Implements abstract io.reactivex.Scheduler.createWorker.

Doc from io.reactivex.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:Scheduler.Worker

a Worker representing a serial queue of actions to be executed

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

Overrides io.reactivex.Scheduler.now.

Doc from io.reactivex.Scheduler.now.

Returns the 'current time' of the Scheduler in the specified time unit.

Parameters
unit:TimeUnit

the time unit

Returns:long

the 'current time'

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.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.disposables.Disposable.dispose.

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

Implements io.reactivex.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public long
now(TimeUnit
the time unit
unit
)

Overrides io.reactivex.Scheduler.Worker.now.

Returns the 'current time' of the Worker in the specified time unit.
public Disposable
schedule(Runnable
the Runnable to schedule
run
,
long
time to "wait" before executing the action; non-positive values indicate an non-delayed schedule
delayTime
,
TimeUnit
the time unit of delayTime
unit
)

Implements abstract io.reactivex.Scheduler.Worker.schedule.

Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.
public Disposable
schedule(Runnable
Runnable to schedule
run
)

Overrides io.reactivex.Scheduler.Worker.schedule.

Schedules a Runnable for execution without any time delay.
Inherited from io.reactivex.Scheduler.Worker:
schedulePeriodically

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.disposables.Disposable.dispose.

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

Dispose the resource, the operation should be idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.disposables.Disposable.isDisposed.

Doc from io.reactivex.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(TimeUnit unit)

Overrides io.reactivex.Scheduler.Worker.now.

Doc from io.reactivex.Scheduler.Worker.now.

Returns the 'current time' of the Worker in the specified time unit.

Parameters
unit:TimeUnit

the time unit

Returns:long

the 'current time'

Annotations
@Override
scheduleback to summary
public Disposable schedule(Runnable run, long delayTime, TimeUnit unit)

Implements abstract io.reactivex.Scheduler.Worker.schedule.

Doc from io.reactivex.Scheduler.Worker.schedule.

Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.

Note to implementors: non-positive delayTime should be regarded as non-delayed schedule, i.e., as if the schedule(Runnable) was called.

Parameters
run:Runnable

the Runnable to schedule

delayTime:long

time to "wait" before executing the action; non-positive values indicate an non-delayed schedule

unit:TimeUnit

the time unit of delayTime

Returns:Disposable

a Disposable to be able to unsubscribe the action (cancel it if not executed)

Annotations
@NonNull
@Override
scheduleback to summary
public Disposable schedule(Runnable run)

Overrides io.reactivex.Scheduler.Worker.schedule.

Doc from io.reactivex.Scheduler.Worker.schedule.

Schedules a Runnable for execution without any time delay.

The default implementation delegates to schedule(Runnable, long, TimeUnit).

Parameters
run:Runnable

Runnable to schedule

Returns:Disposable

a Disposable to be able to unsubscribe the action (cancel it if not executed)

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

pack-priv final Class TestScheduler.TestWorker.QueueRemove

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
pack-priv final TestScheduler.TimedRunnable

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

timedActionback to summary
pack-priv final TestScheduler.TimedRunnable timedAction

Constructor Detail

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

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
io.reactivex.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