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

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

commit b04befd13f3b12733d75716cd898369e476db178
Author: JackieTien97 <[email protected]>
AuthorDate: Tue Nov 23 11:23:46 2021 +0800

    add IT
---
 .../IoTDBLastQueryWithTimeFilterIT.java            | 120 +++++++++++++++++++++
 1 file changed, 120 insertions(+)

diff --git 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLastQueryWithTimeFilterIT.java
 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLastQueryWithTimeFilterIT.java
new file mode 100644
index 0000000..a9aa84a
--- /dev/null
+++ 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLastQueryWithTimeFilterIT.java
@@ -0,0 +1,120 @@
+/*
+ * 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.integration;
+
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.jdbc.Config;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class IoTDBLastQueryWithTimeFilterIT {
+
+  private static final String[] dataSet1 =
+      new String[] {
+          "INSERT INTO root.sg1.d1(timestamp,s1) "
+              + "values(1, 1)",
+          "flush"
+      };
+
+  private static final String TIMESEIRES_STR = "timeseries";
+  private static final String VALUE_STR = "value";
+  private static boolean enableLastCache;
+
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvironmentUtils.closeStatMonitor();
+    EnvironmentUtils.envSetUp();
+    enableLastCache = 
IoTDBDescriptor.getInstance().getConfig().isLastCacheEnabled();
+    IoTDBDescriptor.getInstance().getConfig().setEnableLastCache(false);
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    prepareData();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    
IoTDBDescriptor.getInstance().getConfig().setEnableLastCache(enableLastCache);
+    EnvironmentUtils.cleanEnv();
+  }
+
+  @Test
+  public void lastWithTimeFilterTest() throws Exception {
+
+    try (Connection connection =
+        DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", 
"root");
+        Statement statement = connection.createStatement()) {
+
+      statement.execute("select last s1 from root.sg1.d1 where time > 1");
+
+      ResultSet resultSet = statement.getResultSet();
+      int cnt = 0;
+      while (resultSet.next()) {
+        fail();
+      }
+      Assert.assertEquals(0, cnt);
+    }
+  }
+
+  @Test
+  public void lastWithoutTimeFilterTest() throws Exception {
+
+    String[] retArray =
+        new String[] {
+            "root.sg1,d1.s1,1",
+        };
+    try (Connection connection =
+        DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", 
"root");
+        Statement statement = connection.createStatement()) {
+
+      statement.execute("select last s1 from root.sg1.d1");
+
+      ResultSet resultSet = statement.getResultSet();
+      int cnt = 0;
+      while (resultSet.next()) {
+        String ans = resultSet.getString(TIMESEIRES_STR) + "," + 
resultSet.getString(VALUE_STR);
+        Assert.assertEquals(retArray[cnt], ans);
+      }
+      Assert.assertEquals(retArray.length, cnt);
+    }
+  }
+
+  private static void prepareData() {
+    try (Connection connection =
+        DriverManager.getConnection(
+            Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+
+      for (String sql : dataSet1) {
+        statement.execute(sql);
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+}

Reply via email to