qiaojialin commented on a change in pull request #2468:
URL: https://github.com/apache/iotdb/pull/2468#discussion_r577344418



##########
File path: server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
##########
@@ -558,4 +558,19 @@ public void testGetMeasurementMNodeCount() throws 
MetadataException {
       fail(e1.getMessage());
     }
   }
+
+  @Test
+  public void testCreateTimeseries() throws MetadataException {
+    MTree root = new MTree();
+    String sgPath = "root.sg1";
+    root.setStorageGroup(new PartialPath(sgPath));
+
+    root.createTimeseries(new PartialPath("root.sg1.a.b.c"), TSDataType.INT32, 
TSEncoding.RLE,
+        TSFileDescriptor.getInstance().getConfig().getCompressor(), 
Collections.emptyMap(), null);
+
+    root.createTimeseries(new PartialPath("root.sg1.a.b"), TSDataType.INT32, 
TSEncoding.RLE,
+        TSFileDescriptor.getInstance().getConfig().getCompressor(), 
Collections.emptyMap(), null);
+
+    assertTrue(root.isPathExist(new PartialPath("root.sg1.a.b")));

Review comment:
       This is always true no matter you create root.sg1.a.b or not.
   
   You can count timeseries to check whether timeseries is 2.

##########
File path: 
server/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateTimeseriesIT.java
##########
@@ -0,0 +1,137 @@
+/*
+ * 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 java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.jdbc.IoTDBSQLException;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Notice that, all test begins with "IoTDB" is integration test. All test 
which will start the
+ * IoTDB server should be defined as integration test.
+ */
+public class IoTDBCreateTimeseriesIT {
+  private Statement statement;
+
+  @Before
+  public void setUp() throws Exception {
+    EnvironmentUtils.envSetUp();
+
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    Connection connection = DriverManager.
+        getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    statement = connection.createStatement();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    EnvironmentUtils.cleanEnv();
+  }
+
+  /**
+   * Test creating a time series that is a prefix path of an existing time 
series
+   */
+  @Test
+  public void testCreateTimeseries1() throws Exception {
+    String timeSeries1 = "root.sg1.aa.bb";
+    String timeSeries2 = "root.sg1.aa.bb.cc";
+
+    statement.execute(
+        String.format("create timeseries %s with datatype=INT64, 
encoding=PLAIN, compression=SNAPPY", timeSeries1));
+    statement.execute(
+        String.format("create timeseries %s with datatype=INT64, 
encoding=PLAIN, compression=SNAPPY", timeSeries2));

Review comment:
       I suggest creating timeseries 2 then 1. You could change this test or 
add a new test.

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
##########
@@ -100,4 +104,34 @@ public static PartialPath 
getStorageGroupPathByLevel(PartialPath path, int level
     System.arraycopy(nodeNames, 0, storageGroupNodes, 0, level + 1);
     return new PartialPath(storageGroupNodes);
   }
+
+  public static List<String> getMultiFullPaths(MNode node) {
+    if (node == null) {
+      return Collections.emptyList();
+    }
+
+    List<MNode> lastNodeList = new ArrayList<>();
+    collectLastNode(node, lastNodeList);
+
+    List<String> result = new ArrayList<>();
+    for (MNode mNode : lastNodeList) {
+      result.add(mNode.getFullPath());
+    }
+
+    return result;
+  }
+
+  public static void collectLastNode(MNode node, List<MNode> lastNodeList) {

Review comment:
       @TestOnly

##########
File path: 
server/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateTimeseriesIT.java
##########
@@ -0,0 +1,137 @@
+/*
+ * 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 java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.jdbc.IoTDBSQLException;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Notice that, all test begins with "IoTDB" is integration test. All test 
which will start the
+ * IoTDB server should be defined as integration test.
+ */
+public class IoTDBCreateTimeseriesIT {
+  private Statement statement;
+
+  @Before
+  public void setUp() throws Exception {
+    EnvironmentUtils.envSetUp();
+
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    Connection connection = DriverManager.
+        getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    statement = connection.createStatement();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    EnvironmentUtils.cleanEnv();
+  }
+
+  /**
+   * Test creating a time series that is a prefix path of an existing time 
series
+   */
+  @Test
+  public void testCreateTimeseries1() throws Exception {
+    String timeSeries1 = "root.sg1.aa.bb";
+    String timeSeries2 = "root.sg1.aa.bb.cc";
+
+    statement.execute(
+        String.format("create timeseries %s with datatype=INT64, 
encoding=PLAIN, compression=SNAPPY", timeSeries1));
+    statement.execute(
+        String.format("create timeseries %s with datatype=INT64, 
encoding=PLAIN, compression=SNAPPY", timeSeries2));
+
+    EnvironmentUtils.stopDaemon();
+    setUp();
+
+    boolean hasResult = statement.execute("show timeseries");
+    Assert.assertTrue(hasResult);
+
+    List<String> resultList = new ArrayList<>();
+    try (ResultSet resultSet = statement.getResultSet()) {
+      while (resultSet.next()) {
+        String timeseries = resultSet.getString("timeseries");
+        resultList.add(timeseries);
+      }
+    }
+    Assert.assertEquals(2, resultList.size());
+
+    if (resultList.get(0).split("\\.").length < 
resultList.get(1).split("\\.").length) {
+      Assert.assertEquals(timeSeries1, resultList.get(0));
+      Assert.assertEquals(timeSeries2, resultList.get(1));
+    } else {
+      Assert.assertEquals(timeSeries2, resultList.get(0));
+      Assert.assertEquals(timeSeries1, resultList.get(1));
+    }
+
+  }
+
+  /**
+   * Test if creating a time series will cause the storage group with same 
name to disappear
+   */
+  @Test
+  public void testCreateTimeseries2() throws Exception {
+    String timeSeries = "root.sg1.a.b.c";
+
+    statement.execute(String.format("SET storage group TO %s", timeSeries));
+    try {
+      statement.execute(
+          String.format("create timeseries %s with datatype=INT64, 
encoding=PLAIN, compression=SNAPPY", timeSeries));
+    } catch (IoTDBSQLException ignored) {
+    }
+
+    EnvironmentUtils.stopDaemon();
+    setUp();
+
+    statement.execute("show timeseries");
+    Set<String> resultList = new HashSet<>();
+    try (ResultSet resultSet = statement.getResultSet()) {
+      while (resultSet.next()) {
+        String str = resultSet.getString("timeseries");
+        resultList.add(str);
+      }
+    }
+    Assert.assertFalse(resultList.contains(timeSeries));

Review comment:
       This is ok, another way is to assert the PathAlreadyExistException in 
the catch clause.

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
##########
@@ -100,4 +104,34 @@ public static PartialPath 
getStorageGroupPathByLevel(PartialPath path, int level
     System.arraycopy(nodeNames, 0, storageGroupNodes, 0, level + 1);
     return new PartialPath(storageGroupNodes);
   }
+
+  public static List<String> getMultiFullPaths(MNode node) {

Review comment:
       add an annotation @TestOnly




----------------------------------------------------------------
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.

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


Reply via email to