@Test public void testSlewClockEventuallyCatchesUpWithWallClock() throws Throwable { final AtomicLong slewStart = new AtomicLong(); final AtomicLong offset = new AtomicLong(0); final List<Throwable> errors = Collections.synchronizedList(new ArrayList<Throwable>()); this.timeProvider = new SlewClock.TimeProvider() { public long currentTimeMillis() { return System.currentTimeMillis() - offset.get(); } }; SlewClock.realignWithTimeProvider(); final AtomicBoolean stopped = new AtomicBoolean(false); final AtomicInteger catchingUp = new AtomicInteger(); SlewClockVerifierThread[] threads = new SlewClockVerifierThread[THREADS]; for(int i =0; i < THREADS; i++) { threads[i] = new SlewClockVerifierThread(stopped, catchingUp, errors, slewStart, i == 0); } for (Thread thread : threads) { thread.start(); } Thread.sleep(TimeUnit.SECONDS.toMillis(DURATION)); System.out.println("Going back in time by " + BACK_IN_TIME); slewStart.set(System.currentTimeMillis()); offset.set(BACK_IN_TIME); Thread.sleep(SLOWRUN ? BACK_IN_TIME * 3 : BACK_IN_TIME * 2); stopped.set(true); for (SlewClockVerifierThread thread : threads) { thread.join(); } if(!errors.isEmpty()) { System.err.println("We have " + errors.size() + " error(s) here!"); throw errors.get(0); } assertThat(catchingUp.get(), is(THREADS)); }
@Deprecated static void realignWithTimeProvider() { CURRENT.set(getCurrentTime()); }
SlewClock { @Deprecated static void realignWithTimeProvider() { CURRENT.set(getCurrentTime()); } }
SlewClock { @Deprecated static void realignWithTimeProvider() { CURRENT.set(getCurrentTime()); } private  SlewClock(); }
SlewClock { @Deprecated static void realignWithTimeProvider() { CURRENT.set(getCurrentTime()); } private  SlewClock();  }
SlewClock { @Deprecated static void realignWithTimeProvider() { CURRENT.set(getCurrentTime()); } private  SlewClock();   }