@@ -53,6 +53,40 @@ public FakeScheduledExecutorService() {
5353 DateTimeUtils .setCurrentMillisFixed (currentTime .getMillis ());
5454 }
5555
56+ @ Override
57+ public ScheduledFuture <?> schedule (Runnable command , long delay , TimeUnit unit ) {
58+ return schedulePendingCallable (
59+ new PendingCallable <>(
60+ new Duration (unit .toMillis (delay )), command , PendingCallableType .NORMAL ));
61+ }
62+
63+ @ Override
64+ public <V > ScheduledFuture <V > schedule (Callable <V > callable , long delay , TimeUnit unit ) {
65+ return schedulePendingCallable (
66+ new PendingCallable <>(
67+ new Duration (unit .toMillis (delay )), callable , PendingCallableType .NORMAL ));
68+ }
69+
70+ @ Override
71+ public ScheduledFuture <?> scheduleAtFixedRate (
72+ Runnable command , long initialDelay , long period , TimeUnit unit ) {
73+ return schedulePendingCallable (
74+ new PendingCallable <>(
75+ new Duration (unit .toMillis (initialDelay )), command , PendingCallableType .FIXED_RATE ));
76+ }
77+
78+ @ Override
79+ public ScheduledFuture <?> scheduleWithFixedDelay (
80+ Runnable command , long initialDelay , long delay , TimeUnit unit ) {
81+ return schedulePendingCallable (
82+ new PendingCallable <>(
83+ new Duration (unit .toMillis (initialDelay )), command , PendingCallableType .FIXED_DELAY ));
84+ }
85+
86+ public void tick (long time , TimeUnit unit ) {
87+ advanceTime (Duration .millis (unit .toMillis (time )));
88+ }
89+
5690 /**
5791 * This will advance the reference time of the executor and execute (in the same thread) any
5892 * outstanding callable which execution time has passed.
@@ -134,36 +168,6 @@ public void execute(Runnable command) {
134168 delegate .execute (command );
135169 }
136170
137- @ Override
138- public ScheduledFuture <?> schedule (Runnable command , long delay , TimeUnit unit ) {
139- return schedulePendingCallable (
140- new PendingCallable <>(
141- new Duration (unit .toMillis (delay )), command , PendingCallableType .NORMAL ));
142- }
143-
144- @ Override
145- public <V > ScheduledFuture <V > schedule (Callable <V > callable , long delay , TimeUnit unit ) {
146- return schedulePendingCallable (
147- new PendingCallable <>(
148- new Duration (unit .toMillis (delay )), callable , PendingCallableType .NORMAL ));
149- }
150-
151- @ Override
152- public ScheduledFuture <?> scheduleAtFixedRate (
153- Runnable command , long initialDelay , long period , TimeUnit unit ) {
154- return schedulePendingCallable (
155- new PendingCallable <>(
156- new Duration (unit .toMillis (initialDelay )), command , PendingCallableType .FIXED_RATE ));
157- }
158-
159- @ Override
160- public ScheduledFuture <?> scheduleWithFixedDelay (
161- Runnable command , long initialDelay , long delay , TimeUnit unit ) {
162- return schedulePendingCallable (
163- new PendingCallable <>(
164- new Duration (unit .toMillis (initialDelay )), command , PendingCallableType .FIXED_DELAY ));
165- }
166-
167171 <V > ScheduledFuture <V > schedulePendingCallable (PendingCallable <V > callable ) {
168172 if (shutdown .get ()) {
169173 throw new IllegalStateException ("This executor has been shutdown" );
0 commit comments