@Override @SneakyThrows public long getPhysicalTime() { return getTimestamp().ntpValue(); }
@Override @SneakyThrows public long getPhysicalTime() { return getTimestamp().ntpValue(); }
@Test(successPercentage = 99, dataProvider = "delays") public void secondsPassed(int delay) throws UnknownHostException, InterruptedException, TimeoutException { TimeStamp ts1 = provider.getTimestamp(); Thread.sleep(delay); TimeStamp ts2 = provider.getTimestamp(); long seconds = delay / 1000; // Verify that seconds passed were calculated properly // since the last time NTP timestamp was fetched. Measuring fractions // is pointless as there's a gap between sleeping and requesting the timestamp. assertEquals("Delay=" + delay + " time_diff=" + (ts2.getTime() - ts1.getTime()), seconds, (ts2.getTime() - ts1.getTime()) / 1000); }
@SneakyThrows @Test(timeOut = 5000) public void unavailableTimeServer() { NTPServerTimeProvider timeProvider = new NTPServerTimeProvider(new String[]{"255.255.255.255"}); timeProvider.startAsync().awaitRunning(); try { timeProvider.getTimestamp(); assertEquals("Should throw TimeoutException", true, false); } catch (TimeoutException e) { return; } timeProvider.stopAsync().awaitTerminated(); }