You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ch...@apache.org on 2022/10/06 12:11:01 UTC

[dolphinscheduler] branch dev updated: just add WorkerGroupMapper UT (#12242)

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

chufenggao pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 60c43d5d32 just add WorkerGroupMapper UT (#12242)
60c43d5d32 is described below

commit 60c43d5d326c92be2a030dfb4c65f1c7a0b10be3
Author: Yann Ann <29...@qq.com>
AuthorDate: Thu Oct 6 20:10:48 2022 +0800

    just add WorkerGroupMapper UT (#12242)
---
 .../dao/mapper/WorkerGroupMapperTest.java          | 114 +++++++++++++++++++++
 1 file changed, 114 insertions(+)

diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java
new file mode 100644
index 0000000000..48d146ce3c
--- /dev/null
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.dolphinscheduler.dao.mapper;
+
+import java.util.Date;
+import java.util.List;
+import javax.annotation.Resource;
+import org.apache.dolphinscheduler.dao.BaseDaoTest;
+import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class WorkerGroupMapperTest extends BaseDaoTest {
+
+    @Resource
+    private WorkerGroupMapper workerGroupMapper;
+
+    @Before
+    public void setUp() {
+        clearTestData();
+    }
+
+    @After
+    public void after() {
+        clearTestData();
+    }
+
+    /**
+     * clear all test data
+     */
+    public void clearTestData() {
+        workerGroupMapper.queryAllWorkerGroup()
+            .forEach(workerGroup -> workerGroupMapper.deleteById(workerGroup.getId()));
+    }
+
+    /**
+     * insert a worker group into DB
+     *
+     * @return worker group
+     */
+    private WorkerGroup insertOneWorkerGroup() {
+        WorkerGroup workerGroup = new WorkerGroup();
+        workerGroup.setName("Server1");
+        workerGroup.setDescription("Server1");
+        workerGroup.setCreateTime(new Date());
+        workerGroup.setUpdateTime(new Date());
+        workerGroup.setSystemDefault(true);
+        workerGroup.setOtherParamsJson("");
+        workerGroup.setAddrList("localhost");
+        workerGroupMapper.insert(workerGroup);
+        return workerGroup;
+    }
+
+    /**
+     * test query all worker groups
+     */
+    @Test
+    public void testQueryAllWorkerGroups() {
+        insertOneWorkerGroup();
+        List<WorkerGroup> workerGroups = workerGroupMapper.queryAllWorkerGroup();
+        Assert.assertEquals(1, workerGroups.size());
+    }
+
+    /**
+     * test query worker group by name
+     */
+    @Test
+    public void testQueryWorkerGroupByName() {
+        WorkerGroup workerGroup = insertOneWorkerGroup();
+        List<WorkerGroup> workerGroups = workerGroupMapper.queryWorkerGroupByName(workerGroup.getName());
+        Assert.assertEquals(1, workerGroups.size());
+
+        workerGroups = workerGroupMapper.queryWorkerGroupByName("server2");
+        Assert.assertEquals(0, workerGroups.size());
+    }
+
+    /**
+     * test update workerGroup
+     */
+    @Test
+    public void testUpdate() {
+        WorkerGroup workerGroup = insertOneWorkerGroup();
+        workerGroup.setDescription("Server Update");
+        int update = workerGroupMapper.updateById(workerGroup);
+        Assert.assertEquals(1, update);
+    }
+
+    /**
+     * test delete workerGroup
+     */
+    @Test
+    public void delete() {
+        WorkerGroup workerGroup = insertOneWorkerGroup();
+        int delete = workerGroupMapper.deleteById(workerGroup.getId());
+        Assert.assertEquals(1, delete);
+    }
+}
\ No newline at end of file