directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r951738 - /directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpITest.java
Date Sat, 05 Jun 2010 16:22:54 GMT
Author: seelmann
Date: Sat Jun  5 16:22:54 2010
New Revision: 951738

URL: http://svn.apache.org/viewvc?rev=951738&view=rev
Log:
Fixed NTP test:
o offset can be negative
o delay can be zero
o formatting

Modified:
    directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpITest.java

Modified: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpITest.java?rev=951738&r1=951737&r2=951738&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpITest.java
(original)
+++ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpITest.java
Sat Jun  5 16:22:54 2010
@@ -20,6 +20,8 @@
 package org.apache.directory.server.ntp;
 
 
+import static org.junit.Assert.assertTrue;
+
 import java.net.InetAddress;
 import java.util.concurrent.Executors;
 
@@ -32,7 +34,7 @@ import org.apache.mina.util.AvailablePor
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import static org.junit.Assert.assertTrue;
+
 
 /**
  * An test testing the Network Time Protocol (NTP).
@@ -52,18 +54,20 @@ public class NtpITest
     @Before
     public void setUp() throws Exception
     {
-        ntpConfig = new NtpServer( );
+        ntpConfig = new NtpServer();
         port = AvailablePortFinder.getNextAvailable( 10123 );
         TcpTransport tcpTransport = new TcpTransport( port );
         UdpTransport udpTransport = new UdpTransport( port );
         ntpConfig.setTransports( tcpTransport, udpTransport );
-        ntpConfig.getDatagramAcceptor( udpTransport ).getFilterChain().addLast( "executor",
new ExecutorFilter( Executors.newCachedThreadPool() ) );
-        ntpConfig.getSocketAcceptor( tcpTransport ).getFilterChain().addLast( "executor",
new ExecutorFilter( Executors.newCachedThreadPool() ) );
+        ntpConfig.getDatagramAcceptor( udpTransport ).getFilterChain().addLast( "executor",
+            new ExecutorFilter( Executors.newCachedThreadPool() ) );
+        ntpConfig.getSocketAcceptor( tcpTransport ).getFilterChain().addLast( "executor",
+            new ExecutorFilter( Executors.newCachedThreadPool() ) );
         ntpConfig.setEnabled( true );
         ntpConfig.start();
-
     }
 
+
     /**
      * Tests to make sure NTP works when enabled in the server.
      *
@@ -72,21 +76,22 @@ public class NtpITest
     @Test
     public void testNtp() throws Exception
     {
-        long currentTime = System.currentTimeMillis();
-
         InetAddress host = InetAddress.getByName( null );
 
         NTPUDPClient ntp = new NTPUDPClient();
         ntp.setDefaultTimeout( 500000 );
 
+        long currentTime = System.currentTimeMillis();
         TimeInfo timeInfo = ntp.getTime( host, port );
         long returnTime = timeInfo.getReturnTime();
         assertTrue( currentTime - returnTime < 1000 );
 
         timeInfo.computeDetails();
 
-        assertTrue( 0 < timeInfo.getOffset() && timeInfo.getOffset() < 1000
);
-        assertTrue( 0 < timeInfo.getDelay() && timeInfo.getDelay() < 1000 );
+        String offsetMsg = "Expected offset in range (-1000, 1000), but was " + timeInfo.getOffset();
+        assertTrue( offsetMsg, -1000 < timeInfo.getOffset() && timeInfo.getOffset()
< 1000 );
+        String delayMsg = "Expected delay in range [0, 1000), but was " + timeInfo.getOffset();
+        assertTrue( delayMsg, 0 <= timeInfo.getDelay() && timeInfo.getDelay()
< 1000 );
     }
 
 



Mime
View raw message