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/29 11:29:21 UTC

[iotdb] branch AddCQProcedureTest created (now d6a3c50cda)

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

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


      at d6a3c50cda Add UT for CreateCQProcedure

This branch includes the following new commits:

     new d6a3c50cda Add UT for CreateCQProcedure

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/01: Add UT for CreateCQProcedure

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d6a3c50cda46249d66c83769d4793dc70f846cf2
Author: JackieTien97 <ja...@gmail.com>
AuthorDate: Sat Oct 29 19:29:03 2022 +0800

    Add UT for CreateCQProcedure
---
 confignode/pom.xml                                 |  5 ++
 .../procedure/store/ProcedureFactory.java          |  1 +
 .../iotdb/confignode/service/ConfigNode.java       |  6 ++
 .../procedure/impl/CreateCQProcedureTest.java      | 87 ++++++++++++++++++++++
 4 files changed, 99 insertions(+)

diff --git a/confignode/pom.xml b/confignode/pom.xml
index 90a3b855d1..d4829295ec 100644
--- a/confignode/pom.xml
+++ b/confignode/pom.xml
@@ -59,6 +59,11 @@
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-api-mockito2</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/procedure/store/ProcedureFactory.java b/confignode/src/main/java/org/apache/iotdb/confignode/procedure/store/ProcedureFactory.java
index 9dc6c75e7b..197a2baf99 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/procedure/store/ProcedureFactory.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/procedure/store/ProcedureFactory.java
@@ -101,6 +101,7 @@ public class ProcedureFactory implements IProcedureFactory {
         procedure =
             new CreateCQProcedure(
                 ConfigNode.getInstance().getConfigManager().getCQManager().getExecutor());
+        break;
       case DEACTIVATE_TEMPLATE_PROCEDURE:
         procedure = new DeactivateTemplateProcedure();
         break;
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java b/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
index c3a5692f5e..494e9daee8 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
@@ -27,6 +27,7 @@ import org.apache.iotdb.commons.service.JMXService;
 import org.apache.iotdb.commons.service.RegisterManager;
 import org.apache.iotdb.commons.service.metric.MetricService;
 import org.apache.iotdb.commons.udf.service.UDFClassLoaderManager;
+import org.apache.iotdb.commons.utils.TestOnly;
 import org.apache.iotdb.confignode.client.ConfigNodeRequestType;
 import org.apache.iotdb.confignode.client.sync.SyncConfigNodeClientPool;
 import org.apache.iotdb.confignode.conf.ConfigNodeConfig;
@@ -295,6 +296,11 @@ public class ConfigNode implements ConfigNodeMBean {
     return configManager;
   }
 
+  @TestOnly
+  public void setConfigManager(ConfigManager configManager) {
+    this.configManager = configManager;
+  }
+
   private static class ConfigNodeHolder {
 
     private static final ConfigNode INSTANCE = new ConfigNode();
diff --git a/confignode/src/test/java/org/apache/iotdb/confignode/procedure/impl/CreateCQProcedureTest.java b/confignode/src/test/java/org/apache/iotdb/confignode/procedure/impl/CreateCQProcedureTest.java
new file mode 100644
index 0000000000..d46c2572b4
--- /dev/null
+++ b/confignode/src/test/java/org/apache/iotdb/confignode/procedure/impl/CreateCQProcedureTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.procedure.impl;
+
+import org.apache.iotdb.confignode.manager.ConfigManager;
+import org.apache.iotdb.confignode.manager.cq.CQManager;
+import org.apache.iotdb.confignode.procedure.impl.cq.CreateCQProcedure;
+import org.apache.iotdb.confignode.procedure.store.ProcedureFactory;
+import org.apache.iotdb.confignode.rpc.thrift.TCreateCQReq;
+import org.apache.iotdb.confignode.service.ConfigNode;
+import org.apache.iotdb.tsfile.utils.PublicBAOS;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.io.DataOutputStream;
+import java.nio.ByteBuffer;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class CreateCQProcedureTest {
+
+  @Test
+  public void serializeDeserializeTest() {
+
+    PublicBAOS byteArrayOutputStream = new PublicBAOS();
+    DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream);
+
+    String sql = "create cq testCq1 BEGIN select s1 into root.backup.d1(s1) from root.sg.d1 END";
+
+    TCreateCQReq req =
+        new TCreateCQReq(
+            "testCq1",
+            1000,
+            0,
+            1000,
+            0,
+            (byte) 0,
+            "select s1 into root.backup.d1(s1) from root.sg.d1",
+            sql,
+            "Asia",
+            "root");
+    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
+    CreateCQProcedure createCQProcedure1 = new CreateCQProcedure(req, executor);
+
+    CQManager cqManager = Mockito.mock(CQManager.class);
+    Mockito.when(cqManager.getExecutor()).thenReturn(executor);
+    ConfigManager configManager = Mockito.mock(ConfigManager.class);
+    Mockito.when(configManager.getCQManager()).thenReturn(cqManager);
+    ConfigNode configNode = ConfigNode.getInstance();
+    configNode.setConfigManager(configManager);
+
+    try {
+      createCQProcedure1.serialize(outputStream);
+      ByteBuffer buffer =
+          ByteBuffer.wrap(byteArrayOutputStream.getBuf(), 0, byteArrayOutputStream.size());
+
+      CreateCQProcedure createCQProcedure2 =
+          (CreateCQProcedure) ProcedureFactory.getInstance().create(buffer);
+      assertEquals(createCQProcedure1, createCQProcedure2);
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    } finally {
+      executor.shutdown();
+    }
+  }
+}