You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by su...@apache.org on 2019/06/23 05:13:35 UTC

[incubator-iotdb] branch feature_async_close_tsfile updated: add bwf query test

This is an automated email from the ASF dual-hosted git repository.

suyue pushed a commit to branch feature_async_close_tsfile
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/feature_async_close_tsfile by this push:
     new ce820eb  add bwf query test
     new d1dd579  Merge branch 'feature_async_close_tsfile' of https://github.com/apache/incubator-iotdb into feature_async_close_tsfile
ce820eb is described below

commit ce820ebcb2c377087fa71f79d168f5e07e2d77ab
Author: suyue <23...@qq.com>
AuthorDate: Sun Jun 23 13:13:06 2019 +0800

    add bwf query test
---
 .../iotdb/db/query/reader/ReaderTestHelper.java    | 61 ++++++++++++++
 .../query/reader/sequence/SeqDataReaderTest.java   | 97 +++++++++++++++++++++
 .../reader/sequence/UnsealedSeqReaderTest.java     | 98 ++++++++++++++++++++++
 3 files changed, 256 insertions(+)

diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/ReaderTestHelper.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/ReaderTestHelper.java
new file mode 100644
index 0000000..ac0c254
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/ReaderTestHelper.java
@@ -0,0 +1,61 @@
+/**
+ * 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.query.reader;
+
+import org.apache.iotdb.db.engine.MetadataManagerHelper;
+import org.apache.iotdb.db.engine.filenodeV2.FileNodeProcessorV2;
+import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.write.record.TSRecord;
+import org.apache.iotdb.tsfile.write.record.datapoint.DataPoint;
+import org.junit.After;
+import org.junit.Before;
+
+public abstract class ReaderTestHelper {
+
+  protected String storageGroup = "storage_group1";
+  protected String deviceId = "root.vehicle.d0";
+  protected String measurementId = "s0";
+  protected FileNodeProcessorV2 fileNodeProcessorV2;
+  private String systemDir = "data/info";
+
+  @Before
+  public void setUp() throws Exception {
+    MetadataManagerHelper.initMetadata();
+    EnvironmentUtils.envSetUp();
+    fileNodeProcessorV2 = new FileNodeProcessorV2(systemDir, storageGroup);
+    insertData();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    EnvironmentUtils.cleanEnv();
+    EnvironmentUtils.cleanDir(systemDir);
+  }
+
+  abstract protected void insertData();
+
+  protected void insertOneRecord(long time, int num) {
+    TSRecord record = new TSRecord(time, deviceId);
+    record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(num)));
+    fileNodeProcessorV2.insert(new InsertPlan(record));
+  }
+
+}
\ No newline at end of file
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SeqDataReaderTest.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SeqDataReaderTest.java
new file mode 100644
index 0000000..c8a5b09
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SeqDataReaderTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.query.reader.sequence;
+
+import java.io.IOException;
+import org.apache.iotdb.db.engine.MetadataManagerHelper;
+import org.apache.iotdb.db.engine.filenodeV2.TsFileResourceV2;
+import org.apache.iotdb.db.engine.querycontext.QueryDataSourceV2;
+import org.apache.iotdb.db.query.reader.ReaderTestHelper;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SeqDataReaderTest extends ReaderTestHelper {
+  @Test
+  public void test() throws IOException {}
+
+
+ // @Test
+  public void testSeqReader() throws IOException {
+    QueryDataSourceV2 queryDataSource = fileNodeProcessorV2.query(deviceId, measurementId);
+    Path path = new Path(deviceId, measurementId);
+    SequenceDataReaderV2 readerV2 = new SequenceDataReaderV2(path, queryDataSource.getSeqResources(), null,
+        EnvironmentUtils.TEST_QUERY_CONTEXT);
+    long time = 999;
+    while (readerV2.hasNext()){
+      BatchData batchData = readerV2.nextBatch();
+      while (batchData.hasNext()){
+        time++;
+        Assert.assertEquals(time, batchData.currentTime());
+        batchData.next();
+      }
+    }
+    Assert.assertEquals(3029L, time);
+  }
+
+  //@Test
+  public void testSeqByTimestampReader() throws IOException {
+    QueryDataSourceV2 queryDataSource = fileNodeProcessorV2.query(deviceId, measurementId);
+    Path path = new Path(deviceId, measurementId);
+    SequenceDataReaderByTimestampV2 readerV2 = new SequenceDataReaderByTimestampV2(path, queryDataSource.getSeqResources(), EnvironmentUtils.TEST_QUERY_CONTEXT);
+
+    for (int time = 1000; time <= 3020; time+=10) {
+      int value = (int) readerV2.getValueInTimestamp(time);
+      Assert.assertEquals(time, value);
+    }
+
+    Assert.assertEquals(true, readerV2.hasNext());
+    for (int time = 3050; time <= 3080; time+=10) {
+      Integer value = (Integer) readerV2.getValueInTimestamp(time);
+      Assert.assertEquals(null, value);
+    }
+    Assert.assertEquals(false, readerV2.hasNext());
+  }
+
+
+
+  @Override
+  protected void insertData() {
+    for (int j = 1000; j <= 1009; j++) {
+      insertOneRecord(j, j);
+      fileNodeProcessorV2.asyncForceClose();
+    }
+    for (int j = 1010; j <= 1019; j++) {
+      insertOneRecord(j, j);
+      fileNodeProcessorV2.getWorkSequenceTsFileProcessor().asyncFlush();
+    }
+    fileNodeProcessorV2.asyncForceClose();
+
+    for (int j = 1020; j <= 3019; j++) {
+      insertOneRecord(j, j);
+    }
+    fileNodeProcessorV2.syncCloseFileNode();
+   // fileNodeProcessorV2.getWorkSequenceTsFileProcessor().asyncFlush();
+    for (int j = 3020; j <= 3029; j++) {
+      insertOneRecord(j, j);
+    }
+  }
+}
\ No newline at end of file
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/UnsealedSeqReaderTest.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/UnsealedSeqReaderTest.java
new file mode 100644
index 0000000..0de040e
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/UnsealedSeqReaderTest.java
@@ -0,0 +1,98 @@
+/**
+ * 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.query.reader.sequence;
+
+import java.io.IOException;
+import org.apache.iotdb.db.engine.MetadataManagerHelper;
+import org.apache.iotdb.db.engine.filenodeV2.FileNodeProcessorV2;
+import org.apache.iotdb.db.engine.filenodeV2.TsFileResourceV2;
+import org.apache.iotdb.db.engine.querycontext.QueryDataSourceV2;
+import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
+import org.apache.iotdb.db.query.reader.ReaderTestHelper;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.write.record.TSRecord;
+import org.apache.iotdb.tsfile.write.record.datapoint.DataPoint;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class UnsealedSeqReaderTest extends ReaderTestHelper {
+
+  @Test
+  public void testUnSealedReader() throws IOException {
+    QueryDataSourceV2 queryDataSource = fileNodeProcessorV2.query(deviceId, measurementId);
+    TsFileResourceV2 resourceV2 = queryDataSource.getSeqResources().get(0);
+    Assert.assertEquals(false, resourceV2.isClosed());
+    UnSealedTsFileReaderV2 readerV2 = new UnSealedTsFileReaderV2(resourceV2, null, false);
+    long time = 999;
+    while (readerV2.hasNext()){
+      BatchData batchData = readerV2.nextBatch();
+      while (batchData.hasNext()){
+        time++;
+        Assert.assertEquals(time, batchData.currentTime());
+        batchData.next();
+      }
+    }
+    Assert.assertEquals(3029L, time);
+  }
+
+  @Test
+  public void testUnSealedByTimestampReader() throws IOException {
+    QueryDataSourceV2 queryDataSource = fileNodeProcessorV2.query(deviceId, measurementId);
+    TsFileResourceV2 resourceV2 = queryDataSource.getSeqResources().get(0);
+    Assert.assertEquals(false, resourceV2.isClosed());
+    UnSealedTsFilesReaderByTimestampV2 readerV2 = new UnSealedTsFilesReaderByTimestampV2(resourceV2);
+
+    for (int time = 1000; time <= 3020; time+=10) {
+      int value = (int) readerV2.getValueInTimestamp(time);
+      Assert.assertEquals(time, value);
+    }
+
+    Assert.assertEquals(true, readerV2.hasNext());
+    for (int time = 3050; time <= 3080; time+=10) {
+      Integer value = (Integer) readerV2.getValueInTimestamp(time);
+      Assert.assertEquals(null, value);
+    }
+    Assert.assertEquals(false, readerV2.hasNext());
+  }
+
+
+
+  @Override
+  protected void insertData() {
+    for (int j = 1000; j <= 1009; j++) {
+      insertOneRecord(j, j);
+    }
+    fileNodeProcessorV2.getWorkSequenceTsFileProcessor().asyncFlush();
+    for (int j = 1010; j <= 1019; j++) {
+      insertOneRecord(j, j);
+    }
+    fileNodeProcessorV2.getWorkSequenceTsFileProcessor().asyncFlush();
+    for (int j = 1020; j <= 3019; j++) {
+      insertOneRecord(j, j);
+    }
+    fileNodeProcessorV2.getWorkSequenceTsFileProcessor().asyncFlush();
+    for (int j = 3020; j <= 3029; j++) {
+      insertOneRecord(j, j);
+    }
+  }
+}
\ No newline at end of file