Fix issue with TransactionProxy throttling test failures 17/15217/2
authorMoiz Raja <moraja@cisco.com>
Thu, 12 Feb 2015 20:52:42 +0000 (12:52 -0800)
committerMoiz Raja <moraja@cisco.com>
Fri, 13 Feb 2015 12:48:10 +0000 (12:48 +0000)
Make the measurement a little bit more precise by using nanoTime
instead of currentTimeMillis

Change-Id: I983ea1d176b65dacdb28e74a50f32623632442cf
Signed-off-by: Moiz Raja <moraja@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java

index 9d8227a..7ce41a4 100644 (file)
@@ -1345,15 +1345,15 @@ public class TransactionProxyTest {
 
         TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
 
-        long start = System.currentTimeMillis();
+        long start = System.nanoTime();
 
         operation.run(transactionProxy);
 
-        long end = System.currentTimeMillis();
+        long end = System.nanoTime();
 
         Assert.assertTrue(String.format("took less time than expected %s was %s",
-                mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds()*1000,
-                (end-start)), (end - start) > mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds()*1000);
+                TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds()),
+                (end-start)), (end - start) > TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds()));
 
     }
 
@@ -1392,15 +1392,15 @@ public class TransactionProxyTest {
 
         TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, READ_WRITE);
 
-        long start = System.currentTimeMillis();
+        long start = System.nanoTime();
 
         operation.run(transactionProxy);
 
-        long end = System.currentTimeMillis();
+        long end = System.nanoTime();
 
         Assert.assertTrue(String.format("took more time than expected %s was %s",
-                mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds()*1000,
-                (end-start)), (end - start) <= mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds()*1000);
+                TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds()),
+                (end-start)), (end - start) <= TimeUnit.SECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInSeconds()));
     }
 
     public void testWriteThrottling(boolean shardFound){