zerolbsony commented on code in PR #16846:
URL: https://github.com/apache/iotdb/pull/16846#discussion_r2580361731


##########
integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBConnectionsIT.java:
##########
@@ -0,0 +1,295 @@
+/*
+ * 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.
+ */
+
+package org.apache.iotdb.session.it;
+
+import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
+import org.apache.iotdb.commons.cluster.NodeStatus;
+import org.apache.iotdb.commons.conf.CommonDescriptor;
+import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
+import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodesResp;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.TableClusterIT;
+import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+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.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.apache.iotdb.db.it.utils.TestUtils.createUser;
+import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT;
+import static org.junit.Assert.fail;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
+public class IoTDBConnectionsIT {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(IoTDBConnectionsIT.class);
+  private static final String SHOW_DATANODES = "show datanodes";
+  private static final int COLUMN_AMOUNT = 6;
+  private static Set<Integer> allDataNodeId = new HashSet<>();
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().getConfig().getCommonConfig();
+    EnvFactory.getEnv().initClusterEnvironment(1, 2);
+    createUser("test", "test123123456");
+    try (Connection connection = EnvFactory.getEnv().getTableConnection();
+        Statement statement = connection.createStatement()) {
+      // Get all data nodes
+      ResultSet result = statement.executeQuery(SHOW_DATANODES);
+      while (result.next()) {
+        allDataNodeId.add(result.getInt(ColumnHeaderConstant.NODE_ID));
+      }
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+
+  @Test
+  public void testStandardGetConnections() {
+    Connection conn = null;
+    try (Connection connection = EnvFactory.getEnv().getTableConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("USE information_schema");
+      ResultSet resultSet = statement.executeQuery("SELECT * FROM 
connections");
+      if (!resultSet.next()) {
+        fail();
+      }
+
+      ResultSetMetaData metaData = resultSet.getMetaData();
+      Assert.assertEquals(COLUMN_AMOUNT, metaData.getColumnCount());
+      while (resultSet.next()) {
+        LOGGER.info(
+            "{}, {}, {}, {}, {}, {}",
+            resultSet.getString(1),
+            resultSet.getString(2),
+            resultSet.getString(3),
+            resultSet.getString(4),
+            resultSet.getTimestamp(5),
+            resultSet.getString(6));
+      }
+
+      conn = connection;
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
+
+    try (Connection connection1 = EnvFactory.getEnv().getTableConnection();
+        Statement statement1 = connection1.createStatement()) {
+      statement1.execute("USE information_schema");
+      ResultSet resultSet1 = statement1.executeQuery("SELECT COUNT(*) FROM 
connections");
+      if (!resultSet1.next()) {
+        fail();
+      }
+
+      while (resultSet1.next()) {
+        Assert.assertEquals(2, resultSet1.getInt(1));
+      }
+
+      conn.close();
+
+      ResultSet resultSet2 = statement1.executeQuery("SELECT COUNT(*) FROM 
connections");

Review Comment:
   > Why execute the same SQL twice? U can merge the following judge into the 
previous one.
   Only just do a comparsion intuitively, like this it's easy to ensure the 
record count previous one, simple to diff difference.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to