public class VirtualTimeScheduler extends Object implements reactor.core.scheduler.TimedScheduler
Scheduler
that uses a virtual clock, allowing to manipulate time
(eg. in tests). Can replace the default reactor schedulers by using
the getOrSet(boolean)
/ set(VirtualTimeScheduler)
methods.Modifier | Constructor and Description |
---|---|
protected |
VirtualTimeScheduler() |
protected |
VirtualTimeScheduler(boolean allScheduler)
Deprecated.
will be removed in 3.1.0 in favor of an argumentless ctor (enable on all by default)
|
Modifier and Type | Method and Description |
---|---|
void |
advanceTime()
Triggers any tasks that have not yet been executed and that are scheduled to be
executed at or before this
VirtualTimeScheduler 's present time. |
void |
advanceTimeBy(java.time.Duration delayTime)
Moves the
VirtualTimeScheduler 's clock forward by a specified amount of time. |
void |
advanceTimeTo(java.time.Instant instant)
Moves the
VirtualTimeScheduler 's clock to a particular moment in time. |
static VirtualTimeScheduler |
create()
Deprecated.
behavior will change to be that of
createForAll() in 3.1.0 |
static VirtualTimeScheduler |
createForAll()
Deprecated.
will be removed in 3.1.0, AT WHICH POINT the `create()` method will influence ALL schedulers
|
reactor.test.scheduler.VirtualTimeScheduler.VirtualTimeWorker |
createWorker() |
void |
dispose() |
static VirtualTimeScheduler |
enable(boolean allSchedulers)
Deprecated.
use
getOrSet(boolean) alias instead, will be removed in 3.1.0 |
static VirtualTimeScheduler |
enable(VirtualTimeScheduler scheduler)
Deprecated.
use
getOrSet(VirtualTimeScheduler) instead, will be removed in 3.1.0 |
static VirtualTimeScheduler |
get()
The current
VirtualTimeScheduler assigned in Schedulers |
static VirtualTimeScheduler |
getOrSet()
Assign a single newly created
VirtualTimeScheduler to all Schedulers.Factory
factories. |
static VirtualTimeScheduler |
getOrSet(boolean allSchedulers)
Deprecated.
will be removed in 3.1.0, use
getOrSet() to obtain a newly created VTS and assign it to all factories |
static VirtualTimeScheduler |
getOrSet(VirtualTimeScheduler scheduler)
Assign an externally created
VirtualTimeScheduler to the relevant
Schedulers.Factory factories, depending on how it was created (see
createForAll() and create() ). |
boolean |
isDisposed() |
boolean |
isEnabledOnAllSchedulers()
Deprecated.
will always be true from 3.1.0 onwards
|
static boolean |
isFactoryEnabled()
Return true if there is a
VirtualTimeScheduler currently used by the
Schedulers factory (ie it has been enabled ),
false otherwise (ie it has been reset ). |
long |
now(TimeUnit unit) |
static void |
reset()
Re-assign the default Reactor Core
Schedulers factories. |
reactor.core.Disposable |
schedule(Runnable task) |
reactor.core.Disposable |
schedule(Runnable task,
long delay,
TimeUnit unit) |
reactor.core.Disposable |
schedulePeriodically(Runnable task,
long initialDelay,
long period,
TimeUnit unit) |
static VirtualTimeScheduler |
set(VirtualTimeScheduler scheduler)
Assign an externally created
VirtualTimeScheduler to the relevant
Schedulers.Factory factories, depending on how it was created (see
createForAll() and create() ). |
void |
shutdown() |
@Deprecated protected VirtualTimeScheduler(boolean allScheduler)
protected VirtualTimeScheduler()
@Deprecated public static VirtualTimeScheduler create()
createForAll()
in 3.1.0VirtualTimeScheduler
without enabling it. Call
getOrSet(VirtualTimeScheduler)
to enable it on timed-only
Schedulers.Factory
factories.VirtualTimeScheduler
intended for timed-only
Schedulers
factories.@Deprecated public static VirtualTimeScheduler createForAll()
VirtualTimeScheduler
without enabling it. Call
getOrSet(VirtualTimeScheduler)
to enable it on all Schedulers.Factory
factories.VirtualTimeScheduler
intended for all Schedulers
factories.@Deprecated public static VirtualTimeScheduler enable(boolean allSchedulers)
getOrSet(boolean)
alias instead, will be removed in 3.1.0VirtualTimeScheduler
to all or timed-only
Schedulers.Factory
factories. While the method is thread safe, its usually
advised to execute such wide-impact BEFORE all tested code runs (setup etc).
The created scheduler is returned.allSchedulers
- true if all Schedulers.Factory
factories@Deprecated public static VirtualTimeScheduler enable(VirtualTimeScheduler scheduler)
getOrSet(VirtualTimeScheduler)
instead, will be removed in 3.1.0VirtualTimeScheduler
to the relevant
Schedulers.Factory
factories, depending on how it was created (see
createForAll()
and create()
). Note that the returned scheduler
should always be captured and used going forward, as the provided scheduler can be
superseded by a matching scheduler that has already been enabled.
While the method is thread safe, it's usually advised to execute such wide-impact BEFORE all tested code runs (setup etc). The actual enabled Scheduler is returned.
scheduler
- the VirtualTimeScheduler
to use in factories.@Deprecated public static VirtualTimeScheduler getOrSet(boolean allSchedulers)
getOrSet()
to obtain a newly created VTS and assign it to all factoriesVirtualTimeScheduler
to all or timed-only
Schedulers.Factory
factories. While the method is thread safe, its usually
advised to execute such wide-impact BEFORE all tested code runs (setup etc).
The created scheduler is returned.allSchedulers
- true if all Schedulers.Factory
factoriespublic static VirtualTimeScheduler getOrSet()
VirtualTimeScheduler
to all Schedulers.Factory
factories. While the method is thread safe, its usually advised to execute such
wide-impact BEFORE all tested code runs (setup etc). The created scheduler is returned.public static VirtualTimeScheduler getOrSet(VirtualTimeScheduler scheduler)
VirtualTimeScheduler
to the relevant
Schedulers.Factory
factories, depending on how it was created (see
createForAll()
and create()
). Note that the returned scheduler
should always be captured and used going forward, as the provided scheduler can be
superseded by a matching scheduler that has already been enabled.
While the method is thread safe, it's usually advised to execute such wide-impact BEFORE all tested code runs (setup etc). The actual enabled Scheduler is returned.
scheduler
- the VirtualTimeScheduler
to use in factories.public static VirtualTimeScheduler set(VirtualTimeScheduler scheduler)
VirtualTimeScheduler
to the relevant
Schedulers.Factory
factories, depending on how it was created (see
createForAll()
and create()
). Contrary to
getOrSet(VirtualTimeScheduler)
, the provided scheduler is always used, even
if a matching scheduler is currently enabled.
While the method is thread safe, it's usually advised to execute such wide-impact BEFORE all tested code runs (setup etc).
scheduler
- the VirtualTimeScheduler
to use in factories.public static VirtualTimeScheduler get()
VirtualTimeScheduler
assigned in Schedulers
VirtualTimeScheduler
assigned in Schedulers
IllegalStateException
- if no VirtualTimeScheduler
has been foundpublic static boolean isFactoryEnabled()
VirtualTimeScheduler
currently used by the
Schedulers
factory (ie it has been enabled
),
false otherwise (ie it has been reset
).public static void reset()
Schedulers
factories.
While the method is thread safe, its usually advised to execute such wide-impact
AFTER all tested code has been run (teardown etc).public void advanceTime()
VirtualTimeScheduler
's present time.public void advanceTimeBy(java.time.Duration delayTime)
VirtualTimeScheduler
's clock forward by a specified amount of time.delayTime
- the amount of time to move the VirtualTimeScheduler
's clock forwardpublic void advanceTimeTo(java.time.Instant instant)
VirtualTimeScheduler
's clock to a particular moment in time.instant
- the point in time to move the VirtualTimeScheduler
's
clock topublic reactor.test.scheduler.VirtualTimeScheduler.VirtualTimeWorker createWorker()
createWorker
in interface reactor.core.scheduler.Scheduler
createWorker
in interface reactor.core.scheduler.TimedScheduler
@Deprecated public boolean isEnabledOnAllSchedulers()
Schedulers.Factory
public long now(TimeUnit unit)
now
in interface reactor.core.scheduler.Scheduler
public reactor.core.Disposable schedule(Runnable task)
schedule
in interface reactor.core.scheduler.Scheduler
public reactor.core.Disposable schedule(Runnable task, long delay, TimeUnit unit)
schedule
in interface reactor.core.scheduler.Scheduler
public boolean isDisposed()
isDisposed
in interface reactor.core.Disposable
public void dispose()
dispose
in interface reactor.core.Cancellation
dispose
in interface reactor.core.Disposable
dispose
in interface reactor.core.scheduler.Scheduler
public void shutdown()
shutdown
in interface reactor.core.scheduler.Scheduler