appProps.setProperty(
"com.sun.sgs.impl.service.watchdog.timesync.interval",
"1000");
addNodes(appProps, 1);
WatchdogServerImpl watchdogServer = watchdogService.getServer();
WatchdogService remoteWatchdogService =
additionalNodes[0].getWatchdogService();
// watchdog server and service should initially be sync'd
long serverTime = watchdogServer.currentAppTimeMillis();
long serviceTime = remoteWatchdogService.currentAppTimeMillis();
assertTrue(checkInRange(serverTime,
serviceTime,
Constants.MAX_CLOCK_GRANULARITY));
// force watchdog service out of sync
Field serviceTimeOffset = getField(WatchdogServiceImpl.class,
"timeOffset");
serviceTimeOffset.set(remoteWatchdogService, 0);
serverTime = watchdogServer.currentAppTimeMillis();
serviceTime = remoteWatchdogService.currentAppTimeMillis();
assertFalse(checkInRange(serverTime,
serviceTime,
Constants.MAX_CLOCK_GRANULARITY));
// wait for time sync interval and verify service syncs back with server
Thread.sleep(1000 + Constants.MAX_CLOCK_GRANULARITY);
serverTime = watchdogServer.currentAppTimeMillis();
serviceTime = remoteWatchdogService.currentAppTimeMillis();
assertTrue(checkInRange(serverTime,
serviceTime,
Constants.MAX_CLOCK_GRANULARITY));
}