protected void prepareTestData() throws java.lang.Exception { long currentTime = TimeUtil.getCurrentLocalTimeMillis(); long oneHour = 3600000; long positive = 8 * oneHour + currentTime; long negative = -5 * oneHour + currentTime; _times = new long[][] { {positive, currentTime}, {currentTime, currentTime}, {negative, currentTime}, }; Calendar cal = GregorianCalendar.getInstance(); cal.set(2002, 9, 19, 5, 5, 29); _testDate = new Timestamp(cal.getTime().getTime()); Logger.debug("Test date (ts)= " + _testDate); Logger.debug("Test date (ms)= " + _testDate.getTime()); _timeServer = UtcTimeServer.getInstance(); TimeUtil.setTimeServer(_timeServer); _event = new GetUtcTimeEvent(); // createSessions(1); // createStateMachines(1); }
private synchronized void checkTimeUpdate(long localTime, long utcTime) throws Exception { // broadcast _props.setProperty("utc", String.valueOf(utcTime)); _props.setProperty("local", String.valueOf(localTime)); TimeUpdateNotification notification = new TimeUpdateNotification(TimeUpdateNotification.UPDATE_UTC_TIME, _props); Notifier.getInstance().broadcast(notification); // wait try { wait(30000L); // 30 seconds } catch (Exception ex) { } // refreshTimeServer(); // checkSuccess(_event, _sessions[0], _sm[0], IErrorCode.NO_ERROR); long offset = utcTime - localTime; Logger.debug("Input UTC Time = " + new Timestamp(utcTime)); Logger.debug("Input Local Time = " + new Timestamp(localTime)); Logger.debug("Expected offset: " + offset); // check local to utc Timestamp ts = TimeUtil.localToUtcTimestamp(_testDate); Logger.debug("Converted local to UTc timestamp: " + ts); assertEquals("LocalToUtc conversion fail", offset, ts.getTime() - _testDate.getTime()); // check utc to local ts = TimeUtil.utcToLocalTimestamp(_testDate); Logger.debug("Converted utc to local timestamp: " + ts); assertEquals("UtcToLocal conversion fail", offset, _testDate.getTime() - ts.getTime()); }
// not used protected void checkActionEffect(BasicEventResponse response, IEvent event, StateMachine sm) { Long utcOffset = (Long) response.getReturnData(); // update the utc offset at client site Logger.debug("Retrieved offset = " + utcOffset); // _timeServer.setUtcOffset(utcOffset); }