Methods Summary |
---|
protected void | closeConnections()closes all the connections
try
{
server1.stop();
Thread.sleep(1000);
} catch (Exception e)
{
}
|
public static void | main(java.lang.String[] args)main for running the test. // default test port
junit.textui.TestRunner.run(TimeTCPClientTest.class);
|
protected void | openConnections()open connections needed for the tests for the test.
try {
server1 = new TimeTestSimpleServer(_port);
server1.connect();
} catch (IOException ioe)
{
// try again on another port
_port = 4000;
server1 = new TimeTestSimpleServer(_port);
server1.connect();
}
server1.start();
|
public void | testCompareTimes()tests the times retrieved via the Time protocol implementation.
openConnections();
long time, time2;
long clientTime, clientTime2;
try
{
TimeTCPClient client = new TimeTCPClient();
try
{
// We want to timeout if a response takes longer than 60 seconds
client.setDefaultTimeout(60000);
client.connect(InetAddress.getLocalHost(), _port);
clientTime = client.getDate().getTime();
time = System.currentTimeMillis();
} finally
{
client.disconnect();
}
try
{
// We want to timeout if a response takes longer than 60 seconds
client.setDefaultTimeout(60000);
client.connect(InetAddress.getLocalHost(), _port);
clientTime2 = (client.getTime() - TimeTCPClient.SECONDS_1900_TO_1970)*1000L;
time2 = System.currentTimeMillis();
} finally
{
client.disconnect();
}
} finally
{
closeConnections();
}
// current time shouldn't differ from time reported via network by 5 seconds
assertTrue(Math.abs(time - clientTime) < 5000);
assertTrue(Math.abs(time2 - clientTime2) < 5000);
|
public void | testInitial()tests the constant basetime used by TimeClient against tha
computed from Calendar class.
TimeZone utcZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(utcZone);
calendar.set(1900, Calendar.JANUARY, 1, 0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
long baseTime = calendar.getTime().getTime() / 1000L;
assertTrue(baseTime == -TimeTCPClient.SECONDS_1900_TO_1970);
|