This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch ty/SessionTimeout in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 24ae0e0ad6fdef54c5102837815be97955fe8761 Author: JackieTien97 <[email protected]> AuthorDate: Sat May 11 12:18:40 2024 +0800 fix timeout doesn't take effect while using builder to build session --- .../src/main/java/org/apache/iotdb/session/Session.java | 1 + .../main/java/org/apache/iotdb/session/pool/SessionPool.java | 10 ++++++++++ .../src/test/java/org/apache/iotdb/session/SessionTest.java | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java index 6c0a42e159c..626578c4f83 100644 --- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java +++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java @@ -435,6 +435,7 @@ public class Session implements ISession { this.enableAutoFetch = builder.enableAutoFetch; this.maxRetryCount = builder.maxRetryCount; this.retryIntervalInMs = builder.retryIntervalInMs; + this.queryTimeoutInMs = builder.timeOut; } @Override diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java index c51a6b28692..2811193032c 100644 --- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java +++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java @@ -487,6 +487,7 @@ public class SessionPool implements ISessionPool { this.trustStorePwd = builder.trustStorePwd; this.maxRetryCount = builder.maxRetryCount; this.retryIntervalInMs = builder.retryIntervalInMs; + this.queryTimeoutInMs = builder.queryTimeoutInMs; if (enableAutoFetch) { initThreadPool(); @@ -541,6 +542,7 @@ public class SessionPool implements ISessionPool { .trustStorePwd(trustStorePwd) .maxRetryCount(maxRetryCount) .retryIntervalInMs(retryIntervalInMs) + .timeOut(queryTimeoutInMs) .build(); } else { // Construct redirect-able Session @@ -561,6 +563,7 @@ public class SessionPool implements ISessionPool { .trustStorePwd(trustStorePwd) .maxRetryCount(maxRetryCount) .retryIntervalInMs(retryIntervalInMs) + .timeOut(queryTimeoutInMs) .build(); } session.setEnableQueryRedirection(enableQueryRedirection); @@ -3530,6 +3533,8 @@ public class SessionPool implements ISessionPool { private long retryIntervalInMs = SessionConfig.RETRY_INTERVAL_IN_MS; + private long queryTimeoutInMs = SessionConfig.DEFAULT_QUERY_TIME_OUT; + public Builder useSSL(boolean useSSL) { this.useSSL = useSSL; return this; @@ -3640,6 +3645,11 @@ public class SessionPool implements ISessionPool { return this; } + public Builder queryTimeoutInMs(long queryTimeoutInMs) { + this.queryTimeoutInMs = queryTimeoutInMs; + return this; + } + public SessionPool build() { return new SessionPool(this); } diff --git a/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java index aec44fe3430..4ecd3f436bb 100644 --- a/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java +++ b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java @@ -1200,4 +1200,10 @@ public class SessionTest { assertEquals("nodeUrls shouldn't be empty.", e.getMessage()); } } + + @Test + public void testTimeoutUsingBuilder() { + ISession session1 = new Session.Builder().timeOut(1).build(); + assertEquals(1L, session1.getQueryTimeout()); + } }
