blob: 80f06b626754dc3ac41f7b4cfbf516a2b755cd58 (
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
37
38
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.utils.test;
import java.util.logging.Logger;
/**
* Unit tests want to fast forward time to avoid waiting for time to pass
*/
public class FakeClock extends SettableClock {
private static final Logger logger = Logger.getLogger(FakeClock.class.getName());
protected long currentTime = 1;
@Override
public long getTimeInMillis() {
return currentTime;
}
@Override
public void adjust(long adjustment) {
synchronized (this) {
logger.fine("Adjusting clock, adding " + adjustment + " ms to it.");
currentTime += adjustment;
notifyAll();
}
}
@Override
public void set(long newTime) {
synchronized (this) {
if (newTime < currentTime) {
// throw new IllegalArgumentException("Clock attempted to be set to go backwards");
}
currentTime = newTime;
}
}
}
|