SntpClient { public static Timing requestTimeHA(final int timeoutMillis, final String... hosts) throws IOException, InterruptedException, TimeoutException { return requestTimeHA(timeoutMillis, DEFAULT_SOCKET_TIMEOUT_MILLIS, hosts); } private  SntpClient(); static Timing requestTimeHA(final int timeoutMillis, final String... hosts); static Timing requestTimeHA(final int timeoutMillis,
          final int ntpResponseTimeoutMillis, final String... hosts); static Timing requestTimeHA(final int timeoutMillis,
          final int ntpResponseTimeoutMillis, final int port, final String... hosts); static Timing requestTimeHA(final int timeoutMillis,
          final int ntpResponseTimeoutMillis, final int port, final InetAddress... hosts); static synchronized Timing requestTime(final String host, final int timeoutMillis); @SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE") // false positive static Timing requestTime(final String host, final int port, final int timeoutMillis); @SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE") // false positive static Timing requestTime(final String host, final int port, final long deadlineNanos); @SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE") // false positive static synchronized Timing requestTime(final InetAddress address, final int port, final long deadlineNanos);  }
@Test public void test() throws IOException, InterruptedException, TimeoutException { Timing requestTime = SntpClient.requestTimeHA(60000, "time.apple.com"); long currentTimeMachine = System.currentTimeMillis(); long currentTimeNtp = requestTime.getTime(); LOG.debug("Current time machine = {} ", Instant.ofEpochMilli(currentTimeMachine)); LOG.debug("Current time ntp = {} ", Instant.ofEpochMilli(currentTimeNtp)); Assert.assertTrue(Math.abs(currentTimeNtp - currentTimeMachine) < 10000); }
@Test public void test2h() throws IOException, InterruptedException, TimeoutException { try (Closeable runUdpServer = runUdpServer(true)) { Timing timing = SntpClient.requestTimeHA(60000, 5, 50123, "localhost"); long currentTimeMachine = System.currentTimeMillis(); long currentTimeNtp = timing.getTime(); LOG.debug("Current Timing = {} ", timing); LOG.debug("Current time machine = {} ", Instant.ofEpochMilli(currentTimeMachine)); LOG.debug("Current time ntp = {} ", Instant.ofEpochMilli(currentTimeNtp)); Assert.assertTrue(Math.abs(currentTimeNtp - currentTimeMachine) < 10000); } }