This is an automated email from the ASF dual-hosted git repository. ericpai pushed a commit to branch improve/iotdb-5410 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 6c4c54e992247da8019f1aa22d1cb51a2b360f2e Author: ericpai <[email protected]> AuthorDate: Thu Jan 12 10:05:22 2023 +0800 Temp save optimizing session IT --- .../apache/iotdb/it/env/cluster/AbstractEnv.java | 20 ++- .../iotdb/it/env/remote/RemoteServerEnv.java | 40 +++++ .../java/org/apache/iotdb/itbase/env/BaseEnv.java | 117 +------------- .../session/it/IoTDBSessionAlignedInsertIT.java | 2 - .../iotdb/session/it/IoTDBSessionComplexIT.java | 2 - .../it/IoTDBSessionDisableMemControlIT.java | 2 - .../iotdb/session/it/IoTDBSessionInsertNullIT.java | 2 - .../session/it/IoTDBSessionSchemaTemplateIT.java | 2 - .../iotdb/session/it/IoTDBSessionSimpleIT.java | 2 - .../session/it/IoTDBSessionSyntaxConventionIT.java | 2 - .../iotdb/session/it/pool/SessionPoolIT.java | 176 ++++++++------------- .../src/test/resources/iotdb-datanode.properties | 24 --- .../src/test/resources/logback-test.xml | 2 + 13 files changed, 134 insertions(+), 259 deletions(-) diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/AbstractEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/AbstractEnv.java index eade9e47d0..c0b36c0049 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/AbstractEnv.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/AbstractEnv.java @@ -30,6 +30,7 @@ import org.apache.iotdb.confignode.rpc.thrift.IConfigNodeRPCService; import org.apache.iotdb.confignode.rpc.thrift.TShowClusterResp; import org.apache.iotdb.isession.ISession; import org.apache.iotdb.isession.SessionConfig; +import org.apache.iotdb.isession.pool.ISessionPool; import org.apache.iotdb.it.env.EnvFactory; import org.apache.iotdb.it.framework.IoTDBTestLogger; import org.apache.iotdb.itbase.env.BaseEnv; @@ -346,7 +347,24 @@ public abstract class AbstractEnv implements BaseEnv { } @Override - public SessionPool getSessionPool(int maxSize) { + public ISession getSessionConnection(List<String> nodeUrls) throws IoTDBConnectionException { + Session session = + new Session( + nodeUrls, + SessionConfig.DEFAULT_USER, + SessionConfig.DEFAULT_PASSWORD, + SessionConfig.DEFAULT_FETCH_SIZE, + null, + SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, + SessionConfig.DEFAULT_MAX_FRAME_SIZE, + SessionConfig.DEFAULT_REDIRECTION_MODE, + SessionConfig.DEFAULT_VERSION); + session.open(); + return session; + } + + @Override + public ISessionPool getSessionPool(int maxSize) { DataNodeWrapper dataNode = this.dataNodeWrapperList.get(rand.nextInt(this.dataNodeWrapperList.size())); return new SessionPool( diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/RemoteServerEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/RemoteServerEnv.java index e1844a5beb..78e88fc9d2 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/RemoteServerEnv.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/RemoteServerEnv.java @@ -26,6 +26,8 @@ import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient; import org.apache.iotdb.commons.cluster.NodeStatus; import org.apache.iotdb.confignode.rpc.thrift.IConfigNodeRPCService; import org.apache.iotdb.isession.ISession; +import org.apache.iotdb.isession.SessionConfig; +import org.apache.iotdb.isession.pool.ISessionPool; import org.apache.iotdb.it.env.EnvFactory; import org.apache.iotdb.it.env.cluster.ConfigNodeWrapper; import org.apache.iotdb.it.env.cluster.DataNodeWrapper; @@ -36,11 +38,13 @@ import org.apache.iotdb.jdbc.Config; import org.apache.iotdb.jdbc.Constant; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.session.Session; +import org.apache.iotdb.session.pool.SessionPool; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.util.Collections; import java.util.List; import static org.apache.iotdb.jdbc.Config.VERSION; @@ -150,6 +154,25 @@ public class RemoteServerEnv implements BaseEnv { return clientManager.borrowClient(new TEndPoint(ip_addr, 10710)); } + @Override + public ISessionPool getSessionPool(int maxSize) { + return new SessionPool( + SessionConfig.DEFAULT_HOST, + SessionConfig.DEFAULT_PORT, + SessionConfig.DEFAULT_USER, + SessionConfig.DEFAULT_PASSWORD, + maxSize, + SessionConfig.DEFAULT_FETCH_SIZE, + 60_000, + false, + null, + SessionConfig.DEFAULT_REDIRECTION_MODE, + SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS, + SessionConfig.DEFAULT_VERSION, + SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, + SessionConfig.DEFAULT_MAX_FRAME_SIZE); + } + @Override public ISession getSessionConnection() throws IoTDBConnectionException { Session session = new Session(ip_addr, Integer.parseInt(port)); @@ -157,6 +180,23 @@ public class RemoteServerEnv implements BaseEnv { return session; } + @Override + public ISession getSessionConnection(List<String> nodeUrls) throws IoTDBConnectionException { + Session session = + new Session( + Collections.singletonList(ip_addr + ":" + port), + SessionConfig.DEFAULT_USER, + SessionConfig.DEFAULT_PASSWORD, + SessionConfig.DEFAULT_FETCH_SIZE, + null, + SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, + SessionConfig.DEFAULT_MAX_FRAME_SIZE, + SessionConfig.DEFAULT_REDIRECTION_MODE, + SessionConfig.DEFAULT_VERSION); + session.open(); + return session; + } + @Override public int getLeaderConfigNodeIndex() { return -1; diff --git a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java index 4132e7b6db..6947ea63c0 100644 --- a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java +++ b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java @@ -22,19 +22,15 @@ import org.apache.iotdb.commons.client.exception.ClientManagerException; import org.apache.iotdb.commons.cluster.NodeStatus; import org.apache.iotdb.confignode.rpc.thrift.IConfigNodeRPCService; import org.apache.iotdb.isession.ISession; -import org.apache.iotdb.isession.SessionConfig; -import org.apache.iotdb.isession.util.Version; +import org.apache.iotdb.isession.pool.ISessionPool; import org.apache.iotdb.it.env.cluster.ConfigNodeWrapper; import org.apache.iotdb.it.env.cluster.DataNodeWrapper; import org.apache.iotdb.jdbc.Constant; import org.apache.iotdb.rpc.IoTDBConnectionException; -import org.apache.iotdb.session.Session; -import org.apache.iotdb.session.pool.SessionPool; import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; -import java.time.ZoneId; import java.util.List; public interface BaseEnv { @@ -80,116 +76,11 @@ public interface BaseEnv { IConfigNodeRPCService.Iface getLeaderConfigNodeConnection() throws ClientManagerException, IOException, InterruptedException; - default ISession getSessionConnection() throws IoTDBConnectionException { - return getSessionConnection( - SessionConfig.DEFAULT_HOST, - SessionConfig.DEFAULT_PORT, - SessionConfig.DEFAULT_USER, - SessionConfig.DEFAULT_PASSWORD, - SessionConfig.DEFAULT_FETCH_SIZE, - null, - SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, - SessionConfig.DEFAULT_MAX_FRAME_SIZE, - SessionConfig.DEFAULT_REDIRECTION_MODE, - SessionConfig.DEFAULT_VERSION); - } - - default ISession getSessionConnection( - String host, - int rpcPort, - String username, - String password, - int fetchSize, - ZoneId zoneId, - int thriftDefaultBufferSize, - int thriftMaxFrameSize, - boolean enableRedirection, - Version version) - throws IoTDBConnectionException { - Session session = - new Session( - host, - rpcPort, - username, - password, - fetchSize, - zoneId, - thriftDefaultBufferSize, - thriftMaxFrameSize, - enableRedirection, - version); - - session.open(); - return session; - } + ISessionPool getSessionPool(int maxSize); - default ISession getSessionConnection(List<String> nodeUrls) throws IoTDBConnectionException { - Session session = - new Session( - nodeUrls, - SessionConfig.DEFAULT_USER, - SessionConfig.DEFAULT_PASSWORD, - SessionConfig.DEFAULT_FETCH_SIZE, - null, - SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, - SessionConfig.DEFAULT_MAX_FRAME_SIZE, - SessionConfig.DEFAULT_REDIRECTION_MODE, - SessionConfig.DEFAULT_VERSION); - session.open(); - return session; - } + ISession getSessionConnection() throws IoTDBConnectionException; - default SessionPool getSessionPool(int maxSize) { - return getSessionPool( - SessionConfig.DEFAULT_HOST, - SessionConfig.DEFAULT_PORT, - SessionConfig.DEFAULT_USER, - SessionConfig.DEFAULT_PASSWORD, - maxSize, - SessionConfig.DEFAULT_FETCH_SIZE, - 60_000, - false, - null, - SessionConfig.DEFAULT_REDIRECTION_MODE, - SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS, - SessionConfig.DEFAULT_VERSION, - SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, - SessionConfig.DEFAULT_MAX_FRAME_SIZE); - } - - default SessionPool getSessionPool( - String host, - int port, - String user, - String password, - int maxSize, - int fetchSize, - long waitToGetSessionTimeoutInMs, - boolean enableCompression, - ZoneId zoneId, - boolean enableRedirection, - int connectionTimeoutInMs, - Version version, - int thriftDefaultBufferSize, - int thriftMaxFrameSize) { - SessionPool pool = - new SessionPool( - host, - port, - user, - password, - maxSize, - fetchSize, - waitToGetSessionTimeoutInMs, - enableCompression, - zoneId, - enableRedirection, - connectionTimeoutInMs, - version, - thriftDefaultBufferSize, - thriftMaxFrameSize); - return pool; - } + ISession getSessionConnection(List<String> nodeUrls) throws IoTDBConnectionException; /** * Get the index of the ConfigNode leader. diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionAlignedInsertIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionAlignedInsertIT.java index 3b18212821..94046d1b22 100644 --- a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionAlignedInsertIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionAlignedInsertIT.java @@ -18,7 +18,6 @@ */ package org.apache.iotdb.session.it; -import org.apache.iotdb.commons.conf.IoTDBConstant; import org.apache.iotdb.isession.ISession; import org.apache.iotdb.isession.SessionDataSet; import org.apache.iotdb.it.env.EnvFactory; @@ -55,7 +54,6 @@ public class IoTDBSessionAlignedInsertIT { @Before public void setUp() throws Exception { - System.setProperty(IoTDBConstant.IOTDB_CONF, "src/test/resources/"); EnvFactory.getEnv().getConfig().getCommonConfig().setMaxDegreeOfIndexNode(3); EnvFactory.getEnv().initClusterEnvironment(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionComplexIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionComplexIT.java index 19e49c7904..e44c40ce99 100644 --- a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionComplexIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionComplexIT.java @@ -18,7 +18,6 @@ */ package org.apache.iotdb.session.it; -import org.apache.iotdb.commons.conf.IoTDBConstant; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.isession.ISession; import org.apache.iotdb.isession.SessionDataSet; @@ -62,7 +61,6 @@ import static org.junit.Assert.fail; public class IoTDBSessionComplexIT { @Before public void setUp() throws Exception { - System.setProperty(IoTDBConstant.IOTDB_CONF, "src/test/resources/"); EnvFactory.getEnv().initClusterEnvironment(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionDisableMemControlIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionDisableMemControlIT.java index 3317a44678..aec033b3dc 100644 --- a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionDisableMemControlIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionDisableMemControlIT.java @@ -18,7 +18,6 @@ */ package org.apache.iotdb.session.it; -import org.apache.iotdb.commons.conf.IoTDBConstant; import org.apache.iotdb.isession.ISession; import org.apache.iotdb.isession.SessionDataSet; import org.apache.iotdb.it.env.EnvFactory; @@ -61,7 +60,6 @@ public class IoTDBSessionDisableMemControlIT { @Before public void setUp() throws Exception { - System.setProperty(IoTDBConstant.IOTDB_CONF, "src/test/resources/"); EnvFactory.getEnv().getConfig().getCommonConfig().setEnableMemControl(false); EnvFactory.getEnv().initClusterEnvironment(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionInsertNullIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionInsertNullIT.java index 67b5e8d486..a77cf3e52c 100644 --- a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionInsertNullIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionInsertNullIT.java @@ -18,7 +18,6 @@ */ package org.apache.iotdb.session.it; -import org.apache.iotdb.commons.conf.IoTDBConstant; import org.apache.iotdb.isession.ISession; import org.apache.iotdb.isession.SessionDataSet; import org.apache.iotdb.it.env.EnvFactory; @@ -57,7 +56,6 @@ public class IoTDBSessionInsertNullIT { @Before public void setUp() throws Exception { - System.setProperty(IoTDBConstant.IOTDB_CONF, "src/test/resources/"); EnvFactory.getEnv().initClusterEnvironment(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSchemaTemplateIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSchemaTemplateIT.java index 8e4988305f..42a33747a0 100644 --- a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSchemaTemplateIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSchemaTemplateIT.java @@ -19,7 +19,6 @@ package org.apache.iotdb.session.it; -import org.apache.iotdb.commons.conf.IoTDBConstant; import org.apache.iotdb.isession.ISession; import org.apache.iotdb.isession.template.Template; import org.apache.iotdb.isession.template.TemplateNode; @@ -57,7 +56,6 @@ public class IoTDBSessionSchemaTemplateIT { @Before public void setUp() throws Exception { - System.setProperty(IoTDBConstant.IOTDB_CONF, "src/test/resources/"); EnvFactory.getEnv().initClusterEnvironment(); session = EnvFactory.getEnv().getSessionConnection(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java index b7b9bd6090..bf9f07ea2e 100644 --- a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java @@ -18,7 +18,6 @@ */ package org.apache.iotdb.session.it; -import org.apache.iotdb.commons.conf.IoTDBConstant; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.conf.OperationType; import org.apache.iotdb.isession.ISession; @@ -76,7 +75,6 @@ public class IoTDBSessionSimpleIT { @Before public void setUp() throws Exception { - System.setProperty(IoTDBConstant.IOTDB_CONF, "src/test/resources/"); EnvFactory.getEnv().initClusterEnvironment(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSyntaxConventionIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSyntaxConventionIT.java index de7605d1c6..1940efc8c6 100644 --- a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSyntaxConventionIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSyntaxConventionIT.java @@ -18,7 +18,6 @@ */ package org.apache.iotdb.session.it; -import org.apache.iotdb.commons.conf.IoTDBConstant; import org.apache.iotdb.isession.ISession; import org.apache.iotdb.isession.SessionDataSet; import org.apache.iotdb.it.env.EnvFactory; @@ -54,7 +53,6 @@ public class IoTDBSessionSyntaxConventionIT { @Before public void setUp() throws Exception { - System.setProperty(IoTDBConstant.IOTDB_CONF, "src/test/resources/"); EnvFactory.getEnv().initClusterEnvironment(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/pool/SessionPoolIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/pool/SessionPoolIT.java index 2e90cfe16b..5e729bf073 100644 --- a/integration-test/src/test/java/org/apache/iotdb/session/it/pool/SessionPoolIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/session/it/pool/SessionPoolIT.java @@ -18,25 +18,37 @@ */ package org.apache.iotdb.session.it.pool; -import org.apache.iotdb.db.utils.EnvironmentUtils; +import org.apache.iotdb.commons.client.exception.ClientManagerException; +import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient; +import org.apache.iotdb.commons.cluster.NodeStatus; +import org.apache.iotdb.confignode.rpc.thrift.TDataNodeInfo; +import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodesResp; import org.apache.iotdb.isession.SessionConfig; +import org.apache.iotdb.isession.pool.ISessionPool; import org.apache.iotdb.isession.pool.SessionDataSetWrapper; import org.apache.iotdb.isession.util.Version; import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.env.cluster.DataNodeWrapper; import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.StatementExecutionException; import org.apache.iotdb.session.pool.SessionPool; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; +import org.apache.thrift.TException; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.time.ZoneId; import java.time.ZoneOffset; import java.util.ArrayList; @@ -53,6 +65,7 @@ import static org.junit.Assert.fail; // this test is not for testing the correctness of Session API. So we just implement one of the API. @RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) public class SessionPoolIT { private static final Logger logger = LoggerFactory.getLogger(SessionPoolIT.class); @@ -60,19 +73,18 @@ public class SessionPoolIT { @Before public void setUp() throws Exception { - EnvFactory.getEnv().initClusterEnvironment(); - EnvironmentUtils.envSetUp(); + // As this IT is only testing SessionPool itself, there's no need to launch a large cluster + EnvFactory.getEnv().initClusterEnvironment(1, 1); } @After public void tearDown() throws Exception { - EnvironmentUtils.cleanEnv(); EnvFactory.getEnv().cleanClusterEnvironment(); } @Test public void insert() { - SessionPool pool = EnvFactory.getEnv().getSessionPool(3); + ISessionPool pool = EnvFactory.getEnv().getSessionPool(3); ExecutorService service = Executors.newFixedThreadPool(10); for (int i = 0; i < 10; i++) { final int no = i; @@ -105,7 +117,7 @@ public class SessionPoolIT { @Test public void incorrectSQL() { - SessionPool pool = EnvFactory.getEnv().getSessionPool(3); + ISessionPool pool = EnvFactory.getEnv().getSessionPool(3); assertEquals(0, pool.currentAvailableSize()); try { pool.insertRecord( @@ -124,7 +136,7 @@ public class SessionPoolIT { @Test public void incorrectExecuteQueryStatement() { - SessionPool pool = EnvFactory.getEnv().getSessionPool(3); + ISessionPool pool = EnvFactory.getEnv().getSessionPool(3); ExecutorService service = Executors.newFixedThreadPool(10); write10Data(pool, true); // now let's query @@ -157,19 +169,19 @@ public class SessionPoolIT { @Test public void executeQueryStatement() { - SessionPool pool = EnvFactory.getEnv().getSessionPool(3); + ISessionPool pool = EnvFactory.getEnv().getSessionPool(3); correctQuery(pool, DEFAULT_QUERY_TIMEOUT); pool.close(); } @Test public void executeQueryStatementWithTimeout() { - SessionPool pool = EnvFactory.getEnv().getSessionPool(3); + ISessionPool pool = EnvFactory.getEnv().getSessionPool(3); correctQuery(pool, 2000); pool.close(); } - private void correctQuery(SessionPool pool, long timeoutInMs) { + private void correctQuery(ISessionPool pool, long timeoutInMs) { ExecutorService service = Executors.newFixedThreadPool(10); write10Data(pool, true); // now let's query @@ -207,7 +219,7 @@ public class SessionPoolIT { @Test public void executeRawDataQuery() { - SessionPool pool = EnvFactory.getEnv().getSessionPool(3); + ISessionPool pool = EnvFactory.getEnv().getSessionPool(3); ExecutorService service = Executors.newFixedThreadPool(10); write10Data(pool, true); List<String> pathList = new ArrayList<>(); @@ -241,30 +253,14 @@ public class SessionPoolIT { } @Test - @Ignore - public void tryIfTheServerIsRestart() { - SessionPool pool = - new SessionPool( - "127.0.0.1", - 6667, - "root", - "root", - 3, - 1, - 6000, - false, - null, - false, - SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS, - SessionConfig.DEFAULT_VERSION, - SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, - SessionConfig.DEFAULT_MAX_FRAME_SIZE); - write10Data(pool, true); + public void tryIfTheServerIsRestart() + throws InterruptedException, TException, ClientManagerException, IOException { + ISessionPool pool = EnvFactory.getEnv().getSessionPool(3); SessionDataSetWrapper wrapper = null; try { wrapper = pool.executeQueryStatement("select * from root.sg1.d1 where time > 1"); - // TODO: replace stopDaemon() and restartDaemon() with new methods in Env. - EnvironmentUtils.stopDaemon(); + EnvFactory.getEnv().getDataNodeWrapper(0).stop(); + EnvFactory.getEnv().getDataNodeWrapper(0).waitingToShutDown(); // user does not know what happens. while (wrapper.hasNext()) { wrapper.next(); @@ -272,25 +268,12 @@ public class SessionPoolIT { } catch (IoTDBConnectionException e) { pool.closeResultSet(wrapper); pool.close(); - EnvironmentUtils.stopDaemon(); - - EnvironmentUtils.reactiveDaemon(); - pool = - new SessionPool( - "127.0.0.1", - 6667, - "root", - "root", - 3, - 1, - 6000, - false, - null, - false, - SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS, - SessionConfig.DEFAULT_VERSION, - SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, - SessionConfig.DEFAULT_MAX_FRAME_SIZE); + EnvFactory.getEnv().getDataNodeWrapper(0).stop(); + EnvFactory.getEnv().getDataNodeWrapper(0).waitingToShutDown(); + Assert.assertTrue(waitDataNodeStatusUnknown(EnvFactory.getEnv().getDataNodeWrapper(0))); + EnvFactory.getEnv().getDataNodeWrapper(0).start(); + TimeUnit.SECONDS.sleep(10); + pool = EnvFactory.getEnv().getSessionPool(3); correctQuery(pool, DEFAULT_QUERY_TIMEOUT); pool.close(); return; @@ -308,24 +291,11 @@ public class SessionPoolIT { } catch (IoTDBConnectionException ec) { pool.closeResultSet(wrapper); pool.close(); - EnvironmentUtils.stopDaemon(); - EnvironmentUtils.reactiveDaemon(); - pool = - new SessionPool( - "127.0.0.1", - 6667, - "root", - "root", - 3, - 1, - 6000, - false, - null, - false, - SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS, - SessionConfig.DEFAULT_VERSION, - SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, - SessionConfig.DEFAULT_MAX_FRAME_SIZE); + EnvFactory.getEnv().getDataNodeWrapper(0).stop(); + EnvFactory.getEnv().getDataNodeWrapper(0).waitingToShutDown(); + Assert.assertTrue(waitDataNodeStatusUnknown(EnvFactory.getEnv().getDataNodeWrapper(0))); + EnvFactory.getEnv().getDataNodeWrapper(0).start(); + pool = EnvFactory.getEnv().getSessionPool(3); correctQuery(pool, DEFAULT_QUERY_TIMEOUT); pool.close(); } catch (StatementExecutionException es) { @@ -383,53 +353,25 @@ public class SessionPoolIT { } @Test - @Ignore - public void restart() { - SessionPool pool = - new SessionPool( - "127.0.0.1", - 6667, - "root", - "root", - 1, - 1, - 1000, - false, - null, - false, - SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS, - SessionConfig.DEFAULT_VERSION, - SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, - SessionConfig.DEFAULT_MAX_FRAME_SIZE); + public void restart() + throws TException, ClientManagerException, IOException, InterruptedException { + ISessionPool pool = EnvFactory.getEnv().getSessionPool(1); write10Data(pool, true); // stop the server. pool.close(); - EnvironmentUtils.stopDaemon(); - pool = - new SessionPool( - "127.0.0.1", - 6667, - "root", - "root", - 1, - 1, - 1000, - false, - null, - false, - SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS, - SessionConfig.DEFAULT_VERSION, - SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY, - SessionConfig.DEFAULT_MAX_FRAME_SIZE); + EnvFactory.getEnv().getDataNodeWrapper(0).stop(); + EnvFactory.getEnv().getDataNodeWrapper(0).waitingToShutDown(); + pool = EnvFactory.getEnv().getSessionPool(1); // all this ten data will fail. write10Data(pool, false); // restart the server - EnvironmentUtils.reactiveDaemon(); + Assert.assertTrue(waitDataNodeStatusUnknown(EnvFactory.getEnv().getDataNodeWrapper(0))); + EnvFactory.getEnv().getDataNodeWrapper(0).start(); write10Data(pool, true); pool.close(); } - private void write10Data(SessionPool pool, boolean failWhenThrowException) { + private void write10Data(ISessionPool pool, boolean failWhenThrowException) { for (int i = 0; i < 10; i++) { try { pool.insertRecord( @@ -449,7 +391,7 @@ public class SessionPoolIT { @Test public void testClose() { - SessionPool pool = EnvFactory.getEnv().getSessionPool(3); + ISessionPool pool = EnvFactory.getEnv().getSessionPool(3); pool.close(); try { pool.insertRecord( @@ -537,4 +479,24 @@ public class SessionPoolIT { pool.close(); } } + + private boolean waitDataNodeStatusUnknown(DataNodeWrapper dataNode) + throws ClientManagerException, IOException, InterruptedException, TException { + try (SyncConfigNodeIServiceClient client = + (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) { + // At least wait 20 seconds + for (int count = 0; count < 30; count++) { + TShowDataNodesResp showDataNodesResp = client.showDataNodes(); + for (TDataNodeInfo dataNodeInfo : showDataNodesResp.getDataNodesInfoList()) { + if (dataNodeInfo.getRpcAddresss().equals(dataNode.getIp()) + && dataNodeInfo.getRpcPort() == dataNode.getPort() + && NodeStatus.Unknown.getStatus().equals(dataNodeInfo.getStatus())) { + return true; + } + } + TimeUnit.SECONDS.sleep(1); + } + } + return false; + } } diff --git a/integration-test/src/test/resources/iotdb-datanode.properties b/integration-test/src/test/resources/iotdb-datanode.properties deleted file mode 100644 index cc01ac1336..0000000000 --- a/integration-test/src/test/resources/iotdb-datanode.properties +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - - -base_dir=target/tmp -dn_data_dirs=target/data -dn_wal_dirs=target/wal -sync_dir=target/sync \ No newline at end of file diff --git a/integration-test/src/test/resources/logback-test.xml b/integration-test/src/test/resources/logback-test.xml index e73d764256..a1cce6aefe 100644 --- a/integration-test/src/test/resources/logback-test.xml +++ b/integration-test/src/test/resources/logback-test.xml @@ -51,6 +51,8 @@ <logger name="org.apache.iotdb.db.service.DataNode" level="WARN"/> <logger name="org.apache.iotdb.db.service.RPCService" level="INFO"/> <logger name="org.apache.iotdb.db.service.MQTTService" level="INFO"/> + <logger name="org.apache.iotdb.db.conf.IoTDBDescriptor" level="WARN"/> + <logger name="org.apache.iotdb.db.conf.TSFileDescriptor" level="WARN"/> <logger name="DETAILED_FAILURE_QUERY_TRACE" level="ERROR"/> <root level="INFO"> <appender-ref ref="stdout"/>
