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

jackietien pushed a commit to branch CacheImprove
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/CacheImprove by this push:
     new 557ff3fd477 fix UT
557ff3fd477 is described below

commit 557ff3fd477d519a5bcffa486eb381e40382a3a7
Author: JackieTien97 <[email protected]>
AuthorDate: Thu Nov 2 22:04:33 2023 +0800

    fix UT
---
 .../execution/operator/process/SortOperator.java   |  4 +-
 .../execution/operator/SortOperatorTest.java       | 47 +++++++++++++---------
 .../execution/operator/TopKOperatorTest.java       |  4 ++
 .../apache/iotdb/db/utils/sort/SortUtilTest.java   |  9 +++++
 4 files changed, 43 insertions(+), 21 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/SortOperator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/SortOperator.java
index be2baaa78ed..78bf446aae0 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/SortOperator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/SortOperator.java
@@ -72,7 +72,7 @@ public class SortOperator implements ProcessOperator {
 
   private static final Logger logger = 
LoggerFactory.getLogger(SortOperator.class);
 
-  private static final int DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES =
+  private final int maxReturnSize =
       TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
 
   public SortOperator(
@@ -337,7 +337,7 @@ public class SortOperator implements ProcessOperator {
 
   @Override
   public long calculateMaxReturnSize() {
-    return DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES;
+    return maxReturnSize;
   }
 
   @Override
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/SortOperatorTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/SortOperatorTest.java
index 8f30c5b5dc9..b7785248513 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/SortOperatorTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/SortOperatorTest.java
@@ -81,9 +81,12 @@ public class SortOperatorTest {
 
   private int dataNodeId;
 
+  private int maxTsBlockSizeInBytes;
+
   @Before
   public void setUp() throws MetadataException, IOException, 
WriteProcessException {
     dataNodeId = IoTDBDescriptor.getInstance().getConfig().getDataNodeId();
+    maxTsBlockSizeInBytes = 
TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
     IoTDBDescriptor.getInstance().getConfig().setDataNodeId(0);
     TSFileDescriptor.getInstance().getConfig().setMaxTsBlockSizeInBytes(200);
     SeriesReaderTestUtil.setUp(
@@ -94,6 +97,7 @@ public class SortOperatorTest {
   public void tearDown() throws IOException {
     SeriesReaderTestUtil.tearDown(seqResources, unSeqResources);
     IoTDBDescriptor.getInstance().getConfig().setDataNodeId(dataNodeId);
+    
TSFileDescriptor.getInstance().getConfig().setMaxTsBlockSizeInBytes(maxTsBlockSizeInBytes);
   }
 
   // 
------------------------------------------------------------------------------------------------
@@ -228,26 +232,31 @@ public class SortOperatorTest {
   // with data spilling
   @Test
   public void sortOperatorSpillingTest() throws Exception {
-    IoTDBDescriptor.getInstance().getConfig().setSortBufferSize(5000);
-    SortOperator root = (SortOperator) genSortOperator(Ordering.ASC, true);
-    int lastValue = -1;
-    int count = 0;
-    while (root.isBlocked().isDone() && root.hasNext()) {
-      TsBlock tsBlock = root.next();
-      if (tsBlock == null) continue;
-      for (int i = 0; i < tsBlock.getPositionCount(); i++) {
-        long time = tsBlock.getTimeByIndex(i);
-        int v1 = tsBlock.getColumn(0).getInt(i);
-        int v2 = tsBlock.getColumn(1).getInt(i);
-        assertTrue(lastValue == -1 || lastValue < v1);
-        assertEquals(getValue(time), v1);
-        assertEquals(v1, v2);
-        lastValue = v1;
-        count++;
+    long sortBufferSize = 
IoTDBDescriptor.getInstance().getConfig().getSortBufferSize();
+    try {
+      IoTDBDescriptor.getInstance().getConfig().setSortBufferSize(5000);
+      SortOperator root = (SortOperator) genSortOperator(Ordering.ASC, true);
+      int lastValue = -1;
+      int count = 0;
+      while (root.isBlocked().isDone() && root.hasNext()) {
+        TsBlock tsBlock = root.next();
+        if (tsBlock == null) continue;
+        for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+          long time = tsBlock.getTimeByIndex(i);
+          int v1 = tsBlock.getColumn(0).getInt(i);
+          int v2 = tsBlock.getColumn(1).getInt(i);
+          assertTrue(lastValue == -1 || lastValue < v1);
+          assertEquals(getValue(time), v1);
+          assertEquals(v1, v2);
+          lastValue = v1;
+          count++;
+        }
       }
+      root.close();
+      assertEquals(500, count);
+    } finally {
+      
IoTDBDescriptor.getInstance().getConfig().setSortBufferSize(sortBufferSize);
     }
-    root.close();
-    assertEquals(count, 500);
   }
 
   // no data spilling
@@ -271,6 +280,6 @@ public class SortOperatorTest {
       }
     }
     root.close();
-    assertEquals(count, 500);
+    assertEquals(500, count);
   }
 }
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/TopKOperatorTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/TopKOperatorTest.java
index 2aff973b154..166e7f2ea40 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/TopKOperatorTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/TopKOperatorTest.java
@@ -104,11 +104,14 @@ public class TopKOperatorTest {
 
   private int dataNodeId;
 
+  private int maxTsBlockLineNumber;
+
   private final int limitValue = 100;
 
   @Before
   public void setUp() throws MetadataException, IOException, 
WriteProcessException {
     dataNodeId = IoTDBDescriptor.getInstance().getConfig().getDataNodeId();
+    maxTsBlockLineNumber = 
TSFileDescriptor.getInstance().getConfig().getMaxTsBlockLineNumber();
     IoTDBDescriptor.getInstance().getConfig().setDataNodeId(0);
     TSFileDescriptor.getInstance().getConfig().setMaxTsBlockLineNumber(3);
     SeriesReaderTestUtil.setUp(
@@ -119,6 +122,7 @@ public class TopKOperatorTest {
   public void tearDown() throws IOException {
     SeriesReaderTestUtil.tearDown(seqResources, unSeqResources);
     IoTDBDescriptor.getInstance().getConfig().setDataNodeId(dataNodeId);
+    
TSFileDescriptor.getInstance().getConfig().setMaxTsBlockLineNumber(maxTsBlockLineNumber);
   }
 
   long getValue(long expectedTime) {
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/sort/SortUtilTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/sort/SortUtilTest.java
index 6c64ae2552b..1209361e72b 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/sort/SortUtilTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/sort/SortUtilTest.java
@@ -31,6 +31,7 @@ import org.apache.iotdb.tsfile.read.common.block.TsBlock;
 import org.apache.iotdb.tsfile.read.common.block.column.DoubleColumn;
 import org.apache.iotdb.tsfile.read.common.block.column.TimeColumn;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -51,11 +52,19 @@ public class SortUtilTest {
 
   private static final String filePrefix = folderPath + File.separator + "tmp";
 
+  private int maxTsBlockSizeInBytes;
+
   @Before
   public void setUp() throws MetadataException, IOException, 
WriteProcessException {
+    maxTsBlockSizeInBytes = 
TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
     TSFileDescriptor.getInstance().getConfig().setMaxTsBlockSizeInBytes(200);
   }
 
+  @After
+  public void tearDown() {
+    
TSFileDescriptor.getInstance().getConfig().setMaxTsBlockSizeInBytes(maxTsBlockSizeInBytes);
+  }
+
   private void clear() {
     File tmpDir = new File(folderPath);
     if (!tmpDir.exists()) return;

Reply via email to