Package rx.schedulers
Class TestScheduler
- java.lang.Object
-
- rx.Scheduler
-
- rx.schedulers.TestScheduler
-
public class TestScheduler extends Scheduler
TheTestScheduler
is useful for debugging. It allows you to test schedules of events by manually advancing the clock at whatever pace you choose.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
TestScheduler.CompareActionsByTime
(package private) class
TestScheduler.InnerTestScheduler
(package private) static class
TestScheduler.TimedAction
-
Nested classes/interfaces inherited from class rx.Scheduler
Scheduler.Worker
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static long
counter
(package private) java.util.Queue<TestScheduler.TimedAction>
queue
(package private) long
time
-
Constructor Summary
Constructors Constructor Description TestScheduler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advanceTimeBy(long delayTime, java.util.concurrent.TimeUnit unit)
Moves the Scheduler's clock forward by a specified amount of time.void
advanceTimeTo(long delayTime, java.util.concurrent.TimeUnit unit)
Moves the Scheduler's clock to a particular moment in time.Scheduler.Worker
createWorker()
Retrieves or creates a newScheduler.Worker
that represents serial execution of actions.long
now()
Gets the current time, in milliseconds, according to this Scheduler.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 targetTimeInNanos)
-
-
-
Field Detail
-
queue
final java.util.Queue<TestScheduler.TimedAction> queue
-
counter
static long counter
-
time
long time
-
-
Method Detail
-
now
public long now()
Description copied from class:Scheduler
Gets the current time, in milliseconds, according to this Scheduler.
-
advanceTimeBy
public void advanceTimeBy(long delayTime, java.util.concurrent.TimeUnit unit)
Moves the Scheduler's clock forward by a specified amount of time.- Parameters:
delayTime
- the amount of time to move the Scheduler's clock forwardunit
- the units of time thatdelayTime
is expressed in
-
advanceTimeTo
public void advanceTimeTo(long delayTime, java.util.concurrent.TimeUnit unit)
Moves the Scheduler's clock to a particular moment in time.- Parameters:
delayTime
- the point in time to move the Scheduler's clock tounit
- the units of time thatdelayTime
is expressed in
-
triggerActions
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.
-
triggerActions
private void triggerActions(long targetTimeInNanos)
-
createWorker
public Scheduler.Worker createWorker()
Description copied from class:Scheduler
Retrieves or creates a newScheduler.Worker
that represents serial execution of actions.When work is completed it should be unsubscribed using
Subscription.unsubscribe()
.Work on a
Scheduler.Worker
is guaranteed to be sequential.- Specified by:
createWorker
in classScheduler
- Returns:
- a Worker representing a serial queue of actions to be executed
-
-