blob: 9146b2812a94435dc110cc1ad9b1b49a911cace1 (
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
32
33
34
35
36
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;
import java.util.logging.Level;
import com.yahoo.vespa.clustercontroller.core.testutils.LogFormatter;
import java.util.logging.Logger;
/**
* FakeTimer
*
* Used to fake timing for unit test purposes.
*/
public class FakeTimer implements Timer {
private static final Logger log = Logger.getLogger(FakeTimer.class.getName());
static {
LogFormatter.initializeLogging();
}
// Don't start at zero. Clock users may initialize a 'last run' entry with 0, and we want first time to always look like a timeout
private long currentTime = (long) 30 * 365 * 24 * 60 * 60 * 1000;
public synchronized long getCurrentTimeInMillis() {
return currentTime;
}
public synchronized void advanceTime(long time) {
long currentTime = getCurrentTimeInMillis();
this.currentTime += time;
log.log(Level.FINE, () -> "Time advanced by " + time + " ms. Time increased from " + currentTime + " to " + (currentTime + time));
notifyAll();
}
}
|