zhujt20 commented on code in PR #213:
URL: https://github.com/apache/tsfile/pull/213#discussion_r1732850861


##########
java/tsfile/src/test/java/org/apache/tsfile/encrypt/AES128TsFileReadWriteTest.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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.tsfile.encrypt;
+
+import org.apache.tsfile.common.conf.TSFileConfig;
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.exception.write.WriteProcessException;
+import org.apache.tsfile.file.metadata.IDeviceID;
+import org.apache.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.tsfile.read.TsFileReader;
+import org.apache.tsfile.read.TsFileSequenceReader;
+import org.apache.tsfile.read.common.Field;
+import org.apache.tsfile.read.common.Path;
+import org.apache.tsfile.read.common.RowRecord;
+import org.apache.tsfile.read.expression.QueryExpression;
+import org.apache.tsfile.read.query.dataset.QueryDataSet;
+import org.apache.tsfile.utils.TsFileGeneratorForTest;
+import org.apache.tsfile.write.TsFileWriter;
+import org.apache.tsfile.write.record.TSRecord;
+import org.apache.tsfile.write.record.datapoint.DataPoint;
+import org.apache.tsfile.write.record.datapoint.DoubleDataPoint;
+import org.apache.tsfile.write.record.datapoint.FloatDataPoint;
+import org.apache.tsfile.write.record.datapoint.IntDataPoint;
+import org.apache.tsfile.write.record.datapoint.LongDataPoint;
+import org.apache.tsfile.write.schema.MeasurementSchema;
+import org.apache.tsfile.write.schema.Schema;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class AES128TsFileReadWriteTest {
+  private final double delta = 0.0000001;
+  private final String path = 
TsFileGeneratorForTest.getTestTsFilePath("root.sg1", 0, 0, 1);
+  private File f;
+  private final IDeviceID deviceID = 
IDeviceID.Factory.DEFAULT_FACTORY.create("device_1");
+
+  private TSFileConfig conf = TSFileDescriptor.getInstance().getConfig();
+
+  @Before
+  public void prepare() throws IOException {
+    conf.setEncryptFlag("true");
+    conf.setEncryptType("AES128");
+    conf.setEncryptKey("thisisourtestkey");
+  }
+
+  @Before
+  public void setUp() {
+    f = new File(path);
+    if (f.exists()) {
+      assertTrue(f.delete());
+    }
+    if (!f.getParentFile().exists()) {
+      assertTrue(f.getParentFile().mkdirs());
+    }
+  }
+
+  @After
+  public void tearDown() {
+    f = new File(path);
+    if (f.exists()) {
+      assertTrue(f.delete());
+    }
+  }
+
+  @After
+  public void end() {
+    conf.setEncryptKey("abcdefghijklmnop");
+    conf.setEncryptType("UNENCRYPTED");
+    conf.setEncryptFlag("false");
+  }
+
+  @Test
+  public void intTest() throws IOException, WriteProcessException {
+    List<TSEncoding> encodings =
+        Arrays.asList(
+            TSEncoding.PLAIN,
+            TSEncoding.RLE,
+            TSEncoding.TS_2DIFF,
+            TSEncoding.REGULAR,
+            TSEncoding.GORILLA,
+            TSEncoding.ZIGZAG);
+    for (TSEncoding encoding : encodings) {
+      intTest(encoding);
+    }
+  }
+
+  private void intTest(TSEncoding encoding) throws IOException, 
WriteProcessException {
+    writeDataByTSRecord(TSDataType.INT32, (i) -> new IntDataPoint("sensor_1", 
(int) i), encoding);
+    readData((i, field, delta) -> assertEquals(i, field.getIntV()));
+  }
+
+  @Test
+  public void longTest() throws IOException, WriteProcessException {
+    List<TSEncoding> encodings =
+        Arrays.asList(
+            TSEncoding.PLAIN,
+            TSEncoding.RLE,
+            TSEncoding.TS_2DIFF,
+            TSEncoding.REGULAR,
+            TSEncoding.GORILLA);
+    for (TSEncoding encoding : encodings) {
+      longTest(encoding);
+    }
+  }
+
+  public void longTest(TSEncoding encoding) throws IOException, 
WriteProcessException {
+    writeDataByTSRecord(TSDataType.INT64, (i) -> new LongDataPoint("sensor_1", 
i), encoding);
+    readData((i, field, delta) -> assertEquals(i, field.getLongV()));
+  }
+
+  @Test
+  public void floatTest() throws IOException, WriteProcessException {
+    List<TSEncoding> encodings =
+        Arrays.asList(
+            TSEncoding.PLAIN,
+            TSEncoding.RLE,
+            TSEncoding.TS_2DIFF,
+            TSEncoding.GORILLA_V1,
+            TSEncoding.GORILLA);
+    for (TSEncoding encoding : encodings) {
+      floatTest(encoding);
+    }
+  }
+
+  public void floatTest(TSEncoding encoding) throws IOException, 
WriteProcessException {
+    writeDataByTSRecord(
+        TSDataType.FLOAT, (i) -> new FloatDataPoint("sensor_1", (float) i), 
encoding);
+    readData((i, field, delta) -> assertEquals(i, field.getFloatV(), delta));
+  }
+
+  @Test
+  public void doubleTest() throws IOException, WriteProcessException {
+    List<TSEncoding> encodings =
+        Arrays.asList(
+            TSEncoding.PLAIN,
+            TSEncoding.RLE,
+            TSEncoding.TS_2DIFF,
+            TSEncoding.GORILLA_V1,
+            TSEncoding.GORILLA);
+    for (TSEncoding encoding : encodings) {
+      doubleTest(encoding);
+    }
+  }
+
+  public void doubleTest(TSEncoding encoding) throws IOException, 
WriteProcessException {
+    writeDataByTSRecord(
+        TSDataType.DOUBLE, (i) -> new DoubleDataPoint("sensor_1", (double) i), 
encoding);
+    readData((i, field, delta) -> assertEquals(i, field.getDoubleV(), delta));
+  }
+
+  // If no dataPoint in "device_1.sensor_2", it will throws a nomeasurement
+  // exception,
+  // cause no schema in tsfilemetadata anymore.
+  @Test
+  public void readEmptyMeasurementTest() throws IOException, 
WriteProcessException {
+    try (TsFileWriter tsFileWriter = new TsFileWriter(f, new Schema(), conf)) {
+      // add measurements into file schema
+      tsFileWriter.registerTimeseries(
+          new Path(deviceID), new MeasurementSchema("sensor_1", 
TSDataType.FLOAT, TSEncoding.RLE));
+      tsFileWriter.registerTimeseries(
+          new Path(deviceID),
+          new MeasurementSchema("sensor_2", TSDataType.INT32, 
TSEncoding.TS_2DIFF));
+      // construct TSRecord
+      TSRecord tsRecord = new TSRecord(1, deviceID);
+      DataPoint dPoint1 = new FloatDataPoint("sensor_1", 1.2f);
+      tsRecord.addTuple(dPoint1);
+      // write a TSRecord to TsFile
+      tsFileWriter.write(tsRecord);
+    }
+
+    // read example : no filter
+    TsFileSequenceReader reader = new TsFileSequenceReader(path);
+    TsFileReader readTsFile = new TsFileReader(reader);
+    ArrayList<Path> paths = new ArrayList<>();
+    paths.add(new Path(deviceID, "sensor_2", true));
+    QueryExpression queryExpression = QueryExpression.create(paths, null);
+    try {
+      QueryDataSet queryDataSet = readTsFile.query(queryExpression);
+    } catch (IOException e) {
+      // Assert.fail();

Review Comment:
   It's the same with TsfileReadWriteTest



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