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 2020/05/01 01:16:34 UTC

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #1135: Update Session.java : fix sort bug

qiaojialin commented on a change in pull request #1135:
URL: https://github.com/apache/incubator-iotdb/pull/1135#discussion_r418373511



##########
File path: session/src/test/java/org/apache/iotdb/session/SessionUT.java
##########
@@ -0,0 +1,81 @@
+package org.apache.iotdb.session;
+
+import org.apache.iotdb.rpc.BatchExecutionException;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class SessionUT {
+
+    public static void main(String[] args) throws BatchExecutionException, IoTDBConnectionException {

Review comment:
       Thanks! We usually use JUnit framework in test, not main thread. You could refer to org.apache.iotdb.tsfile.read.common.BatchDataTest to see how to Assert

##########
File path: session/src/test/java/org/apache/iotdb/session/SessionUT.java
##########
@@ -0,0 +1,81 @@
+package org.apache.iotdb.session;
+
+import org.apache.iotdb.rpc.BatchExecutionException;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class SessionUT {
+
+    public static void main(String[] args) throws BatchExecutionException, IoTDBConnectionException {
+        /*
+        To test sortTablet in Class Session
+        !!!
+        Before testing, change the sortTablet from private method to public method
+        !!!
+         */
+        Session session = new Session("127.0.0.1", 6667, "root", "root");
+        List<MeasurementSchema> schemaList = new ArrayList<>();
+        schemaList.add(new MeasurementSchema("s1",TSDataType.INT64, TSEncoding.RLE));
+        // insert three rows data
+        Tablet tablet = new Tablet("root.sg1.d1", schemaList, 3);
+        long[] timestamps = tablet.timestamps;
+        Object[] values = tablet.values;
+
+        /*
+        inorder data before inserting
+        timestamp   s1
+        2           0
+        0           1
+        1           2
+         */
+        // inorder timestamps
+        timestamps[0] = 2;
+        timestamps[1] = 0;
+        timestamps[2] = 1;
+        // just one column INT64 data
+        long[] sensor = (long[]) values[0];
+        sensor[0] = 0;
+        sensor[1] = 1;
+        sensor[2] = 2;
+        tablet.rowSize = 3;
+        System.out.printf("%s\t%s\n", "timestamp", "s1");
+        for (int i = 0; i < 3; i++) {
+            System.out.println(timestamps[i] + "\t\t\t" + sensor[i]);
+        }
+
+        session.sortTablet(tablet);
+
+        /*
+        After sorting, if the tablet data is sorted according to the timestamps,
+        data in tablet will be
+        timestamp   s1
+        0           1
+        1           0
+        2           2
+
+        If the data equal to above tablet, test pass, otherwise test fialed
+         */
+        long[] resTimestamps = tablet.timestamps;
+        long[] resValues = (long[])tablet.values[0];
+        boolean ifPass = false;

Review comment:
       in junit, the ifPass could be replaced by Assert.assertEqual(exp, actual)




----------------------------------------------------------------
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:
users@infra.apache.org