HTHou commented on a change in pull request #4024: URL: https://github.com/apache/iotdb/pull/4024#discussion_r719010897
########## File path: server/src/test/java/org/apache/iotdb/db/integration/IoTDBSettleIT.java ########## @@ -0,0 +1,103 @@ +/* + * 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.db.integration; + +import org.apache.iotdb.db.engine.StorageEngine; +import org.apache.iotdb.db.exception.StorageEngineException; +import org.apache.iotdb.db.exception.WriteProcessException; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.PartialPath; +import org.apache.iotdb.db.utils.EnvironmentUtils; +import org.apache.iotdb.jdbc.Config; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class IoTDBSettleIT { + private static List<String> sqls = new ArrayList<>(); + private static Connection connection; + + @BeforeClass + public static void setUp() throws Exception { + EnvironmentUtils.closeStatMonitor(); + initCreateSQLStatement(); + EnvironmentUtils.envSetUp(); + executeSql(); + } + + @AfterClass + public static void tearDown() throws Exception { + close(); + EnvironmentUtils.cleanEnv(); + } + + @Test + public void onlineSettleTest() { + PartialPath sg = null; + try { + sg = new PartialPath("root.st1"); + StorageEngine.getInstance().settleAll(sg); + } catch (IllegalPathException | StorageEngineException | WriteProcessException e) { + Assert.fail(e.getMessage()); + } + } + + private static void close() throws SQLException { + if (Objects.nonNull(connection)) { + try { + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private static void initCreateSQLStatement() { + sqls.add("SET STORAGE GROUP TO root.st1"); + sqls.add("CREATE TIMESERIES root.st1.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN"); + for (int i = 1; i <= 10; i++) { + sqls.add("insert into root.st1.wf01.wt01(timestamp,status) values(" + 100 * i + ",false)"); + } + sqls.add("flush"); + sqls.add("delete from root.st1.wf01.wt01.* where time<500"); + } + + private static void executeSql() throws ClassNotFoundException, SQLException { + Class.forName(Config.JDBC_DRIVER_NAME); + connection = + DriverManager.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root"); + Statement statement = connection.createStatement(); + + for (String sql : sqls) { + statement.execute(sql); + } + + statement.close(); Review comment: Use try with resource to close connection and statement automatically. -- 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]
