You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ke...@apache.org on 2022/01/11 04:46:29 UTC
[dolphinscheduler] branch dev updated: [Bug-7849] Add unit test for alert server, fix #7849 (#7850)
This is an automated email from the ASF dual-hosted git repository.
kerwin 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 4f4d9d1 [Bug-7849] Add unit test for alert server, fix #7849 (#7850)
4f4d9d1 is described below
commit 4f4d9d12ceb75b1e8d6db08791980c14bd105b20
Author: springmonster <ch...@163.com>
AuthorDate: Tue Jan 11 12:46:21 2022 +0800
[Bug-7849] Add unit test for alert server, fix #7849 (#7850)
---
.../alert/AlertPluginManagerTest.java | 50 ++++++++++++++++++
.../dolphinscheduler/alert/AlertServerTest.java | 60 ++++++++++++++++++++++
2 files changed, 110 insertions(+)
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertPluginManagerTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertPluginManagerTest.java
new file mode 100644
index 0000000..f7e7e56
--- /dev/null
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertPluginManagerTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.alert;
+
+import junit.framework.TestCase;
+import org.apache.dolphinscheduler.dao.PluginDao;
+import org.apache.dolphinscheduler.dao.entity.PluginDefine;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AlertPluginManagerTest extends TestCase {
+
+ @InjectMocks
+ private AlertPluginManager alertPluginManager;
+
+ @Mock
+ private PluginDao pluginDao;
+
+ @Test
+ public void testAlertPluginManager() {
+ Mockito.when(pluginDao.addOrUpdatePluginDefine(Mockito.any(PluginDefine.class))).thenReturn(0);
+
+ alertPluginManager.installPlugin();
+
+ Assert.assertEquals(1, alertPluginManager.size());
+
+ Assert.assertNotNull(alertPluginManager.getAlertChannel(0));
+ }
+}
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java
new file mode 100644
index 0000000..bd5396a
--- /dev/null
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.alert;
+
+import junit.framework.TestCase;
+import org.apache.dolphinscheduler.dao.PluginDao;
+import org.apache.dolphinscheduler.remote.NettyRemotingServer;
+import org.apache.dolphinscheduler.remote.config.NettyServerConfig;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.powermock.reflect.Whitebox;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class AlertServerTest extends TestCase {
+
+ @InjectMocks
+ private AlertServer alertServer;
+
+ @Mock
+ private PluginDao pluginDao;
+
+ @Mock
+ private AlertConfig alertConfig;
+
+ @Test
+ public void testStart() {
+ Mockito.when(pluginDao.checkPluginDefineTableExist()).thenReturn(true);
+
+ Mockito.when(alertConfig.getPort()).thenReturn(50053);
+
+ alertServer.start();
+
+ NettyRemotingServer nettyRemotingServer = Whitebox.getInternalState(alertServer, "server");
+
+ NettyServerConfig nettyServerConfig = Whitebox.getInternalState(nettyRemotingServer, "serverConfig");
+
+ Assert.assertEquals(50053, nettyServerConfig.getListenPort());
+ }
+}