You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/09/03 12:22:56 UTC

[GitHub] [iotdb] qiaojialin commented on a change in pull request #3758: [IOTDB-1562]incorrect exception processing in insertXXX() API

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



##########
File path: session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
##########
@@ -726,6 +725,278 @@ public void testInsertOneDeviceRecordsWithIncorrectOrder()
     session.close();
   }
 
+  @Test
+  public void testInsertIlligalPath() throws IoTDBConnectionException {
+    session = new Session("127.0.0.1", 6667, "root", "root");
+    session.open();
+
+    String deviceId = "root.sg..d1";
+    List<String> deviceIds = Arrays.asList("root.sg..d1", "root.sg.d2");
+    List<Long> timestamps = Arrays.asList(1L, 1L);
+    List<String> measurements = Arrays.asList("s1", "s2", "s3");
+    List<List<String>> allMeasurements = Arrays.asList(measurements, measurements);
+    List<TSDataType> tsDataTypes =
+        Arrays.asList(TSDataType.INT32, TSDataType.FLOAT, TSDataType.TEXT);
+    List<List<TSDataType>> allTsDataTypes = Arrays.asList(tsDataTypes, tsDataTypes);
+    List<TSEncoding> tsEncodings =
+        Arrays.asList(TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN);
+    List<CompressionType> compressionTypes =
+        Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY, CompressionType.SNAPPY);
+    List<Object> values = Arrays.asList(1, 2f, "3");
+    List<List<Object>> allValues = Arrays.asList(values, values);
+    List<String> stringValues = Arrays.asList("1", "2", "3");
+    List<List<String>> allstringValues = Arrays.asList(stringValues, stringValues);
+
+    try {
+      session.insertRecords(deviceIds, timestamps, allMeasurements, allTsDataTypes, allValues);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL, OperationType.INSERT_RECORDS, deviceId)));
+    }
+
+    try {
+      session.insertRecords(deviceIds, Arrays.asList(2L, 2L), allMeasurements, allstringValues);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.INSERT_STRING_RECORDS,
+                      deviceIds.get(0))));
+    }
+
+    try {
+      session.insertRecord(deviceId, 3L, measurements, tsDataTypes, values);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL, OperationType.INSERT_RECORD, deviceId)));
+    }
+
+    try {
+      session.insertRecord(deviceId, 4L, measurements, stringValues);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL, OperationType.INSERT_STRING_RECORD, deviceId)));
+    }
+
+    try {
+      session.insertRecordsOfOneDevice(
+          deviceId, Arrays.asList(5L, 6L), allMeasurements, allTsDataTypes, allValues);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.INSERT_RECORDS_OF_ONE_DEVICE,
+                      deviceId)));
+    }
+
+    try {
+      session.deleteData(deviceId + ".s1", 6L);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL, OperationType.DELETE_DATA, deviceId + ".s1")));
+    }
+
+    try {
+      Tablet tablet =
+          new Tablet(
+              deviceId,
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.INT32),
+                  new MeasurementSchema("s2", TSDataType.FLOAT)),
+              5);
+      long ts = 7L;
+      for (long row = 0; row < 8; row++) {
+        int rowIndex = tablet.rowSize++;
+        tablet.addTimestamp(rowIndex, ts);
+        tablet.addValue("s1", rowIndex, 1);
+        tablet.addValue("s2", rowIndex, 1.0F);
+        if (tablet.rowSize == tablet.getMaxRowNumber()) {
+          session.insertTablet(tablet, true);
+          tablet.reset();
+        }
+        ts++;
+      }
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL, OperationType.INSERT_TABLET, deviceId)));
+    }
+
+    try {
+      Tablet tablet1 =
+          new Tablet(
+              deviceId,
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.INT32),
+                  new MeasurementSchema("s2", TSDataType.FLOAT)),
+              5);
+      Tablet tablet2 =
+          new Tablet(
+              "root.sg.d2",
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.INT32),
+                  new MeasurementSchema("s2", TSDataType.FLOAT)),
+              5);
+      HashMap<String, Tablet> tablets = new HashMap<>();
+      tablets.put(deviceId, tablet1);
+      tablets.put("root.sg.d2", tablet2);
+      long ts = 16L;
+      for (long row = 0; row < 8; row++) {
+        int row1 = tablet1.rowSize++;
+        int row2 = tablet2.rowSize++;
+        tablet1.addTimestamp(row1, ts);
+        tablet2.addTimestamp(row2, ts);
+        tablet1.addValue("s1", row1, 1);
+        tablet1.addValue("s2", row1, 1.0F);
+        tablet2.addValue("s1", row2, 1);
+        tablet2.addValue("s2", row2, 1.0F);
+        if (tablet1.rowSize == tablet1.getMaxRowNumber()) {
+          session.insertTablets(tablets, true);
+          tablet1.reset();
+          tablet2.reset();
+        }
+        ts++;
+      }
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL, OperationType.INSERT_TABLETS, deviceId)));
+    }
+
+    try {
+      session.setStorageGroup("root..sg");
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL, OperationType.SET_STORAGE_GROUP, "root..sg")));
+    }
+
+    try {
+      session.createTimeseries(
+          "root.sg..d1.s1", TSDataType.INT32, TSEncoding.PLAIN, CompressionType.SNAPPY);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.CREATE_TIMESERIES,
+                      "root.sg..d1.s1")));
+    }
+
+    try {
+      session.createAlignedTimeseries(
+          deviceId,
+          measurements,
+          tsDataTypes,
+          tsEncodings,
+          CompressionType.SNAPPY,
+          Arrays.asList("alias1", "alias2", "alias3"));
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      "[%s] Exception occurred: %s failed. %s is not a legal path",

Review comment:
       extract a constant string in this class




-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org