You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2022/04/26 07:30:02 UTC

[iotdb] branch master updated: Use logical clock to fix clientManager test (#5671)

This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 7d5630159c Use logical clock to fix clientManager test (#5671)
7d5630159c is described below

commit 7d5630159c63a912354ea7bc24816edbd3f9f01a
Author: Potato <TX...@gmail.com>
AuthorDate: Tue Apr 26 15:29:57 2022 +0800

    Use logical clock to fix clientManager test (#5671)
---
 .../org/apache/iotdb/commons/client/ClientFactoryProperty.java   | 4 +++-
 .../java/org/apache/iotdb/commons/client/ClientPoolProperty.java | 3 ++-
 .../test/java/org/apache/iotdb/commons/ClientManagerTest.java    | 9 ++++++---
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientFactoryProperty.java b/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientFactoryProperty.java
index bd8ab891fd..f1801628e4 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientFactoryProperty.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientFactoryProperty.java
@@ -23,6 +23,8 @@ import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.protocol.TCompactProtocol;
 import org.apache.thrift.protocol.TProtocolFactory;
 
+import java.util.concurrent.TimeUnit;
+
 public class ClientFactoryProperty {
 
   private final TProtocolFactory protocolFactory;
@@ -87,7 +89,7 @@ public class ClientFactoryProperty {
     private DefaultProperty() {}
 
     public static final boolean RPC_THRIFT_COMPRESSED_ENABLED = false;
-    public static final int CONNECTION_TIMEOUT_MS = 20_000;
+    public static final int CONNECTION_TIMEOUT_MS = (int) TimeUnit.SECONDS.toMillis(20);;
     public static final int SELECTOR_NUM_OF_ASYNC_CLIENT_MANAGER = 1;
   }
 }
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientPoolProperty.java b/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientPoolProperty.java
index 7c21b5ad5d..c764692564 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientPoolProperty.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientPoolProperty.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.commons.client;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
 
 import java.time.Duration;
+import java.util.concurrent.TimeUnit;
 
 public class ClientPoolProperty<V> {
 
@@ -76,7 +77,7 @@ public class ClientPoolProperty<V> {
 
     private DefaultProperty() {}
 
-    public static final long WAIT_CLIENT_TIMEOUT_MS = 10_000;
+    public static final long WAIT_CLIENT_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
     public static final int MAX_TOTAL_CLIENT_FOR_EACH_NODE = 100;
     public static final int MAX_IDLE_CLIENT_FOR_EACH_NODE = 100;
   }
diff --git a/node-commons/src/test/java/org/apache/iotdb/commons/ClientManagerTest.java b/node-commons/src/test/java/org/apache/iotdb/commons/ClientManagerTest.java
index 497eb910ec..54eeb70625 100644
--- a/node-commons/src/test/java/org/apache/iotdb/commons/ClientManagerTest.java
+++ b/node-commons/src/test/java/org/apache/iotdb/commons/ClientManagerTest.java
@@ -236,7 +236,10 @@ public class ClientManagerTest {
     Assert.assertEquals(0, syncClusterManager.getPool().getNumIdle(endPoint));
 
     // get another sync client, should throw error and return null
+    long start = System.nanoTime();
     SyncDataNodeInternalServiceClient syncClient2 = syncClusterManager.borrowClient(endPoint);
+    long end = System.nanoTime();
+    Assert.assertTrue(end - start >= DefaultProperty.WAIT_CLIENT_TIMEOUT_MS * 1_000_000);
     Assert.assertNull(syncClient2);
 
     // return one sync client
@@ -300,10 +303,10 @@ public class ClientManagerTest {
     Assert.assertEquals(0, syncClusterManager.getPool().getNumIdle(endPoint));
 
     // get another sync client, should wait waitClientTimeoutMS ms, throw error and return null
-    long start = System.currentTimeMillis();
+    long start = System.nanoTime();
     SyncDataNodeInternalServiceClient syncClient2 = syncClusterManager.borrowClient(endPoint);
-    long end = System.currentTimeMillis();
-    Assert.assertTrue(end - start >= waitClientTimeoutMS);
+    long end = System.nanoTime();
+    Assert.assertTrue(end - start >= waitClientTimeoutMS * 1_000_000);
     Assert.assertNull(syncClient2);
 
     // return one sync client