blob: 26c14d3f82a3b8aa394c949944227c206fb1dcf3 (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;
import com.yahoo.log.LogLevel;
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 Logger log = Logger.getLogger(FakeTimer.class.getName());
// 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
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(LogLevel.DEBUG, "Time advanced by " + time + " ms. Time increased from " + currentTime + " to " + (currentTime + time));
notifyAll();
}
static {
LogFormatter.initializeLogging();
}
}
|