|
|
|
@ -17,31 +17,21 @@
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.alert; |
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
|
import org.apache.dolphinscheduler.dao.AlertDao; |
|
|
|
|
import org.apache.dolphinscheduler.dao.PluginDao; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Alert; |
|
|
|
|
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.junit.jupiter.api.Assertions; |
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
|
|
import org.mockito.InjectMocks; |
|
|
|
|
import org.mockito.Mock; |
|
|
|
|
import org.mockito.Mockito; |
|
|
|
|
import org.mockito.MockitoAnnotations; |
|
|
|
|
import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
|
import org.powermock.reflect.Whitebox; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
|
public class AlertServerTest extends TestCase { |
|
|
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
|
private AlertServer alertServer; |
|
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
|
|
public class AlertServerTest { |
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
private PluginDao pluginDao; |
|
|
|
@ -52,22 +42,28 @@ public class AlertServerTest extends TestCase {
|
|
|
|
|
@Mock |
|
|
|
|
private AlertSenderService alertSenderService; |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testStart() { |
|
|
|
|
@InjectMocks |
|
|
|
|
private AlertServer alertServer; |
|
|
|
|
|
|
|
|
|
Mockito.when(pluginDao.checkPluginDefineTableExist()).thenReturn(true); |
|
|
|
|
@BeforeEach |
|
|
|
|
void init() { |
|
|
|
|
Mockito.lenient().when(pluginDao.checkPluginDefineTableExist()).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(alertConfig.getPort()).thenReturn(50052); |
|
|
|
|
Mockito.lenient().when(alertConfig.getPort()).thenReturn(50052); |
|
|
|
|
|
|
|
|
|
Mockito.doNothing().when(alertSenderService).start(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@Test |
|
|
|
|
public void alertServerStartSuccessfully() { |
|
|
|
|
|
|
|
|
|
alertServer.run(null); |
|
|
|
|
|
|
|
|
|
NettyRemotingServer nettyRemotingServer = Whitebox.getInternalState(alertServer, "nettyRemotingServer"); |
|
|
|
|
|
|
|
|
|
NettyServerConfig nettyServerConfig = Whitebox.getInternalState(nettyRemotingServer, "serverConfig"); |
|
|
|
|
|
|
|
|
|
Assert.assertEquals(50052, nettyServerConfig.getListenPort()); |
|
|
|
|
Assertions.assertEquals(50052, nettyServerConfig.getListenPort()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|