blob: 4d274a33a1f80de3a56ed21e0fd6656a664a8ad5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.test;
import com.yahoo.jdisc.Timer;
import java.time.Duration;
/**
* A {@link Timer} to be used in tests when the advancement of time needs to be controlled.
*
* @author hakonhall
*/
public class TestTimer implements Timer {
private Duration durationSinceEpoch = Duration.ZERO;
public void setMillis(long millisSinceEpoch) {
durationSinceEpoch = Duration.ofMillis(millisSinceEpoch);
}
public void advanceMillis(long millis) { advance(Duration.ofMillis(millis)); }
public void advanceSeconds(long seconds) { advance(Duration.ofSeconds(seconds)); }
public void advanceMinutes(long minutes) { advance(Duration.ofMinutes(minutes)); }
public void advance(Duration duration) {
durationSinceEpoch = durationSinceEpoch.plus(duration);
}
@Override
public long currentTimeMillis() {
return durationSinceEpoch.toMillis();
}
}
|