You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/10/17 11:58:15 UTC

[iotdb] 02/02: Add UT for CQScheduleTask#getFirstExecutionTime

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

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

commit d77bd7792d4ca04ad8f3889c8d5c1c2e8fe932a8
Author: JackieTien97 <ja...@gmail.com>
AuthorDate: Mon Oct 17 19:58:02 2022 +0800

    Add UT for CQScheduleTask#getFirstExecutionTime
---
 .../confignode/manager/cq/CQScheduleTask.java      |  6 ++-
 .../iotdb/confignode/cq/CQScheduleTaskTest.java    | 44 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/cq/CQScheduleTask.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/cq/CQScheduleTask.java
index e0c734fc2a..48ab4e3b8e 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/cq/CQScheduleTask.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/cq/CQScheduleTask.java
@@ -125,8 +125,12 @@ public class CQScheduleTask implements Runnable {
   }
 
   public static long getFirstExecutionTime(long boundaryTime, long everyInterval) {
-    // TODO may need to consider nano precision
     long now = System.currentTimeMillis();
+    return getFirstExecutionTime(boundaryTime, everyInterval, now);
+  }
+
+  public static long getFirstExecutionTime(long boundaryTime, long everyInterval, long now) {
+    // TODO may need to consider nano precision
     if (now <= boundaryTime) {
       return boundaryTime;
     } else {
diff --git a/confignode/src/test/java/org/apache/iotdb/confignode/cq/CQScheduleTaskTest.java b/confignode/src/test/java/org/apache/iotdb/confignode/cq/CQScheduleTaskTest.java
new file mode 100644
index 0000000000..44f8536ee0
--- /dev/null
+++ b/confignode/src/test/java/org/apache/iotdb/confignode/cq/CQScheduleTaskTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.confignode.cq;
+
+import org.apache.iotdb.confignode.manager.cq.CQScheduleTask;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class CQScheduleTaskTest {
+
+  @Test
+  public void testGetFirstExecutionTime1() {
+    long now = 100L;
+    long boundaryTime = 0L;
+    long everyInterval = 30L;
+    assertEquals(120L, CQScheduleTask.getFirstExecutionTime(boundaryTime, everyInterval, now));
+  }
+
+  @Test
+  public void testGetFirstExecutionTime2() {
+    long now = 100L;
+    long boundaryTime = 110L;
+    long everyInterval = 30L;
+    assertEquals(110L, CQScheduleTask.getFirstExecutionTime(boundaryTime, everyInterval, now));
+  }
+}