Browse Source

[Improvement][Test] Remove powermock in service and server modules (#12164)

* Remove powermock and refactor some related code in dolphinscheduler-service and dolphinscheduler-server modules
* Remove redundant comments
* Add null check
3.2.0-release
Eric Gao 2 years ago committed by GitHub
parent
commit
d1e409e9a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 53
      dolphinscheduler-server/pom.xml
  2. 26
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java
  3. 47
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/utils/ProcessUtilsTest.java
  4. 36
      dolphinscheduler-service/pom.xml
  5. 13
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java
  6. 38
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java
  7. 6
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClient.java
  8. 3
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
  9. 36
      dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java
  10. 4
      dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/ProcessAlertManagerTest.java
  11. 94
      dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/log/LogClientTest.java
  12. 20
      dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java

53
dolphinscheduler-server/pom.xml

@ -15,7 +15,6 @@
~ See the License for the specific language governing permissions and ~ See the License for the specific language governing permissions and
~ limitations under the License. ~ limitations under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -25,8 +24,20 @@
<version>dev-SNAPSHOT</version> <version>dev-SNAPSHOT</version>
</parent> </parent>
<artifactId>dolphinscheduler-server</artifactId> <artifactId>dolphinscheduler-server</artifactId>
<name>dolphinscheduler-server</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>dolphinscheduler-server</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies> <dependencies>
<!-- dolphinscheduler --> <!-- dolphinscheduler -->
@ -47,7 +58,13 @@
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.12.4</version>
<!-- TODO: move this dependency to root pom after removing powermock in the whole project -->
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId> <artifactId>hadoop-common</artifactId>
@ -62,8 +79,8 @@
<artifactId>jdk.tools</artifactId> <artifactId>jdk.tools</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
@ -127,16 +144,16 @@
<artifactId>jsp-api</artifactId> <artifactId>jsp-api</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>jersey-json</artifactId>
<groupId>com.sun.jersey</groupId> <groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>jersey-server</artifactId>
<groupId>com.sun.jersey</groupId> <groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>jersey-core</artifactId>
<groupId>com.sun.jersey</groupId> <groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
@ -154,8 +171,8 @@
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<groupId>org.codehaus.jackson</groupId> <groupId>org.codehaus.jackson</groupId>
@ -179,37 +196,25 @@
<artifactId>hadoop-mapreduce-client-shuffle</artifactId> <artifactId>hadoop-mapreduce-client-shuffle</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>jersey-client</artifactId>
<groupId>com.sun.jersey</groupId> <groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>jersey-core</artifactId>
<groupId>com.sun.jersey</groupId> <groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>jaxb-api</artifactId>
<groupId>javax.xml.bind</groupId> <groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

26
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java

@ -17,10 +17,6 @@
package org.apache.dolphinscheduler.server.utils; package org.apache.dolphinscheduler.server.utils;
import lombok.NonNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.utils.CommonUtils; import org.apache.dolphinscheduler.common.utils.CommonUtils;
import org.apache.dolphinscheduler.common.utils.FileUtils; import org.apache.dolphinscheduler.common.utils.FileUtils;
@ -31,10 +27,11 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.dolphinscheduler.remote.utils.Host; import org.apache.dolphinscheduler.remote.utils.Host;
import org.apache.dolphinscheduler.service.log.LogClient; import org.apache.dolphinscheduler.service.log.LogClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
@ -43,6 +40,13 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.annotation.Nullable;
import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* mainly used to get the start command line of a process. * mainly used to get the start command line of a process.
*/ */
@ -166,8 +170,10 @@ public class ProcessUtils {
} }
} else { } else {
String pids = OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, processId)); String pids = OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, processId));
if (null != pids) {
mat = WINDOWSATTERN.matcher(pids); mat = WINDOWSATTERN.matcher(pids);
} }
}
if (null != mat) { if (null != mat) {
while (mat.find()) { while (mat.find()) {
@ -206,10 +212,12 @@ public class ProcessUtils {
taskExecutionContext.getTaskInstanceId())); taskExecutionContext.getTaskInstanceId()));
} }
FileUtils.createWorkDirIfAbsent(taskExecutionContext.getExecutePath()); FileUtils.createWorkDirIfAbsent(taskExecutionContext.getExecutePath());
cancelApplication(appIds, logger, taskExecutionContext.getTenantCode(), taskExecutionContext.getExecutePath()); cancelApplication(appIds, logger, taskExecutionContext.getTenantCode(),
taskExecutionContext.getExecutePath());
return appIds; return appIds;
} else { } else {
logger.info("The current appId is empty, don't need to kill the yarn job, taskInstanceId: {}", taskExecutionContext.getTaskInstanceId()); logger.info("The current appId is empty, don't need to kill the yarn job, taskInstanceId: {}",
taskExecutionContext.getTaskInstanceId());
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("Kill yarn job failure, taskInstanceId: {}", taskExecutionContext.getTaskInstanceId(), e); logger.error("Kill yarn job failure, taskInstanceId: {}", taskExecutionContext.getTaskInstanceId(), e);

47
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/utils/ProcessUtilsTest.java

@ -17,31 +17,28 @@
package org.apache.dolphinscheduler.server.utils; package org.apache.dolphinscheduler.server.utils;
import static org.powermock.api.mockito.PowerMockito.when; import static org.mockito.ArgumentMatchers.anyString;
import org.apache.commons.lang3.SystemUtils;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.utils.HadoopUtils; import org.apache.dolphinscheduler.common.utils.HadoopUtils;
import org.apache.dolphinscheduler.common.utils.OSUtils; import org.apache.dolphinscheduler.common.utils.OSUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito; import org.mockito.junit.MockitoJUnitRunner;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@RunWith(PowerMockRunner.class) @RunWith(MockitoJUnitRunner.class)
@PrepareForTest({System.class, OSUtils.class, HadoopUtils.class, PropertyUtils.class, SystemUtils.class})
public class ProcessUtilsTest { public class ProcessUtilsTest {
private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class);
@ -54,23 +51,22 @@ public class ProcessUtilsTest {
@Test @Test
public void getPidsStr() throws Exception { public void getPidsStr() throws Exception {
int processId = 1; int processId = 1;
PowerMockito.mockStatic(OSUtils.class); Mockito.mockStatic(OSUtils.class);
Whitebox.setInternalState(SystemUtils.class, "IS_OS_MAC", true); Mockito.when(OSUtils.exeCmd(anyString())).thenReturn(null);
when(OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, processId))).thenReturn(null); String pidList = ProcessUtils.getPidsStr(processId);
String pidListMac = ProcessUtils.getPidsStr(processId); Assert.assertEquals("", pidList);
Assert.assertEquals("", pidListMac);
} }
@Test @Test
public void testGetKerberosInitCommand() { public void testGetKerberosInitCommand() {
PowerMockito.mockStatic(PropertyUtils.class); Mockito.mockStatic(PropertyUtils.class);
PowerMockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false)) Mockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false))
.thenReturn(true); .thenReturn(true);
PowerMockito.when(PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH)).thenReturn("/etc/krb5.conf"); Mockito.when(PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH)).thenReturn("/etc/krb5.conf");
PowerMockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH)).thenReturn("/etc/krb5.keytab"); Mockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH)).thenReturn("/etc/krb5.keytab");
PowerMockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME)).thenReturn("test@DS.COM"); Mockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME)).thenReturn("test@DS.COM");
Assert.assertNotEquals("", ProcessUtils.getKerberosInitCommand()); Assert.assertNotEquals("", ProcessUtils.getKerberosInitCommand());
PowerMockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false)) Mockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false))
.thenReturn(false); .thenReturn(false);
Assert.assertEquals("", ProcessUtils.getKerberosInitCommand()); Assert.assertEquals("", ProcessUtils.getKerberosInitCommand());
} }
@ -84,17 +80,12 @@ public class ProcessUtilsTest {
String executePath = "/ds-exec/1/1/1"; String executePath = "/ds-exec/1/1/1";
TaskExecutionStatus running = TaskExecutionStatus.RUNNING_EXECUTION; TaskExecutionStatus running = TaskExecutionStatus.RUNNING_EXECUTION;
PowerMockito.mockStatic(HadoopUtils.class); Mockito.mockStatic(HadoopUtils.class);
HadoopUtils hadoop = HadoopUtils.getInstance(); HadoopUtils hadoop = HadoopUtils.getInstance();
try { try {
PowerMockito.whenNew(HadoopUtils.class).withAnyArguments().thenReturn(hadoop); Mockito.when(hadoop.getApplicationStatus("application_1585532379175_228491")).thenReturn(running);
} catch (Exception e) { Mockito.when(hadoop.getApplicationStatus("application_1598885606600_3677")).thenReturn(running);
e.printStackTrace();
}
try {
when(hadoop.getApplicationStatus("application_1585532379175_228491")).thenReturn(running);
when(hadoop.getApplicationStatus("application_1598885606600_3677")).thenReturn(running);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
ProcessUtils.cancelApplication(appIds, logger, tenantCode, executePath); ProcessUtils.cancelApplication(appIds, logger, tenantCode, executePath);

36
dolphinscheduler-service/pom.xml

@ -17,17 +17,29 @@
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<artifactId>dolphinscheduler</artifactId>
<groupId>org.apache.dolphinscheduler</groupId> <groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler</artifactId>
<version>dev-SNAPSHOT</version> <version>dev-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dolphinscheduler-service</artifactId> <artifactId>dolphinscheduler-service</artifactId>
<name>dolphinscheduler-service</name> <name>dolphinscheduler-service</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies> <dependencies>
<!-- dolphinscheduler --> <!-- dolphinscheduler -->
<dependency> <dependency>
@ -51,6 +63,14 @@
<artifactId>dolphinscheduler-task-api</artifactId> <artifactId>dolphinscheduler-task-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.12.4</version>
<!-- TODO: move this dependency to root pom after removing powermock in the whole project -->
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.cronutils</groupId> <groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId> <artifactId>cron-utils</artifactId>
@ -63,16 +83,4 @@
</dependency> </dependency>
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project> </project>

13
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java

@ -21,9 +21,9 @@ import org.apache.dolphinscheduler.remote.NettyRemotingClient;
import org.apache.dolphinscheduler.remote.command.Command; import org.apache.dolphinscheduler.remote.command.Command;
import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand;
import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand;
import org.apache.dolphinscheduler.remote.config.NettyClientConfig;
import org.apache.dolphinscheduler.remote.utils.Host; import org.apache.dolphinscheduler.remote.utils.Host;
import org.apache.dolphinscheduler.remote.utils.JsonSerializer; import org.apache.dolphinscheduler.remote.utils.JsonSerializer;
import org.apache.dolphinscheduler.service.factory.NettyRemotingClientFactory;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -34,8 +34,6 @@ public class AlertClientService implements AutoCloseable {
private static final Logger logger = LoggerFactory.getLogger(AlertClientService.class); private static final Logger logger = LoggerFactory.getLogger(AlertClientService.class);
private final NettyClientConfig clientConfig;
private final NettyRemotingClient client; private final NettyRemotingClient client;
private final AtomicBoolean isRunning; private final AtomicBoolean isRunning;
@ -53,8 +51,7 @@ public class AlertClientService implements AutoCloseable {
* alert client * alert client
*/ */
public AlertClientService() { public AlertClientService() {
this.clientConfig = new NettyClientConfig(); this.client = NettyRemotingClientFactory.buildNettyRemotingClient();
this.client = new NettyRemotingClient(clientConfig);
this.isRunning = new AtomicBoolean(true); this.isRunning = new AtomicBoolean(true);
} }
@ -102,8 +99,10 @@ public class AlertClientService implements AutoCloseable {
* @param content content * @param content content
* @return AlertSendResponseCommand * @return AlertSendResponseCommand
*/ */
public AlertSendResponseCommand sendAlert(String host, int port, int groupId, String title, String content, int strategy) { public AlertSendResponseCommand sendAlert(String host, int port, int groupId, String title, String content,
logger.info("sync alert send, host : {}, port : {}, groupId : {}, title : {} , strategy : {} ", host, port, groupId, title, strategy); int strategy) {
logger.info("sync alert send, host : {}, port : {}, groupId : {}, title : {} , strategy : {} ", host, port,
groupId, title, strategy);
AlertSendRequestCommand request = new AlertSendRequestCommand(groupId, title, content, strategy); AlertSendRequestCommand request = new AlertSendRequestCommand(groupId, title, content, strategy);
final Host address = new Host(host, port); final Host address = new Host(host, port);
try { try {

38
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java

@ -0,0 +1,38 @@
/*
* 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.service.factory;
import org.apache.dolphinscheduler.remote.NettyRemotingClient;
import org.apache.dolphinscheduler.remote.config.NettyClientConfig;
import lombok.experimental.UtilityClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@UtilityClass
public class NettyRemotingClientFactory {
private final Logger logger = LoggerFactory.getLogger(NettyRemotingClientFactory.class);
public NettyRemotingClient buildNettyRemotingClient() {
NettyClientConfig nettyClientConfig = new NettyClientConfig();
logger.info("NettyRemotingClient initialized with config: {}", nettyClientConfig);
return new NettyRemotingClient(nettyClientConfig);
}
}

6
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClient.java

@ -33,9 +33,9 @@ import org.apache.dolphinscheduler.remote.command.log.RollViewLogRequestCommand;
import org.apache.dolphinscheduler.remote.command.log.RollViewLogResponseCommand; import org.apache.dolphinscheduler.remote.command.log.RollViewLogResponseCommand;
import org.apache.dolphinscheduler.remote.command.log.ViewLogRequestCommand; import org.apache.dolphinscheduler.remote.command.log.ViewLogRequestCommand;
import org.apache.dolphinscheduler.remote.command.log.ViewLogResponseCommand; import org.apache.dolphinscheduler.remote.command.log.ViewLogResponseCommand;
import org.apache.dolphinscheduler.remote.config.NettyClientConfig;
import org.apache.dolphinscheduler.remote.exceptions.RemotingException; import org.apache.dolphinscheduler.remote.exceptions.RemotingException;
import org.apache.dolphinscheduler.remote.utils.Host; import org.apache.dolphinscheduler.remote.utils.Host;
import org.apache.dolphinscheduler.service.factory.NettyRemotingClientFactory;
import java.util.List; import java.util.List;
@ -59,9 +59,7 @@ public class LogClient implements AutoCloseable {
private static final long LOG_REQUEST_TIMEOUT = 10 * 1000L; private static final long LOG_REQUEST_TIMEOUT = 10 * 1000L;
public LogClient() { public LogClient() {
NettyClientConfig nettyClientConfig = new NettyClientConfig(); client = NettyRemotingClientFactory.buildNettyRemotingClient();
this.client = new NettyRemotingClient(nettyClientConfig);
logger.info("Initialized LogClientService with config: {}", nettyClientConfig);
} }
/** /**

3
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java

@ -169,7 +169,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.micrometer.core.annotation.Counted; import io.micrometer.core.annotation.Counted;
/** /**
@ -1817,7 +1816,7 @@ public class ProcessServiceImpl implements ProcessService {
* @param res origin resource info * @param res origin resource info
* @return {@link ResourceInfo} * @return {@link ResourceInfo}
*/ */
private ResourceInfo updateResourceInfo(ResourceInfo res) { protected ResourceInfo updateResourceInfo(ResourceInfo res) {
ResourceInfo resourceInfo = null; ResourceInfo resourceInfo = null;
// only if mainJar is not null and does not contains "resourceName" field // only if mainJar is not null and does not contains "resourceName" field
if (res != null) { if (res != null) {

36
dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java

@ -23,27 +23,24 @@ import org.apache.dolphinscheduler.remote.command.Command;
import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand;
import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand;
import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseResult; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseResult;
import org.apache.dolphinscheduler.service.factory.NettyRemotingClientFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito; import org.mockito.junit.MockitoJUnitRunner;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** @RunWith(MockitoJUnitRunner.class)
* alert client service test
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({AlertClientService.class})
public class AlertClientServiceTest { public class AlertClientServiceTest {
private static final Logger logger = LoggerFactory.getLogger(AlertClientServiceTest.class); private static final Logger logger = LoggerFactory.getLogger(AlertClientServiceTest.class);
@ -52,13 +49,22 @@ public class AlertClientServiceTest {
private AlertClientService alertClient; private AlertClientService alertClient;
private MockedStatic<NettyRemotingClientFactory> mockedNettyRemotingClientFactory;
@Before @Before
public void before() throws Exception { public void before() throws Exception {
client = PowerMockito.mock(NettyRemotingClient.class); client = Mockito.mock(NettyRemotingClient.class);
PowerMockito.whenNew(NettyRemotingClient.class).withAnyArguments().thenReturn(client); mockedNettyRemotingClientFactory = Mockito.mockStatic(NettyRemotingClientFactory.class);
mockedNettyRemotingClientFactory.when(NettyRemotingClientFactory::buildNettyRemotingClient)
.thenReturn(client);
alertClient = new AlertClientService(); alertClient = new AlertClientService();
} }
@After
public void after() {
mockedNettyRemotingClientFactory.close();
}
@Test @Test
public void testSendAlert() throws Exception { public void testSendAlert() throws Exception {
String host = "127.0.0.1"; String host = "127.0.0.1";
@ -89,7 +95,7 @@ public class AlertClientServiceTest {
new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); new AlertSendResponseCommand(sendResponseStatus, sendResponseResults);
Command resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); Command resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque());
PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); Mockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand);
alertSendResponseCommand = alertSendResponseCommand =
alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode()); alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode());
Assert.assertFalse(alertSendResponseCommand.isSuccess()); Assert.assertFalse(alertSendResponseCommand.isSuccess());
@ -104,7 +110,7 @@ public class AlertClientServiceTest {
alertResult.setMessage(message); alertResult.setMessage(message);
alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults);
resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque());
PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); Mockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand);
alertSendResponseCommand = alertSendResponseCommand =
alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode()); alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode());
Assert.assertFalse(alertSendResponseCommand.isSuccess()); Assert.assertFalse(alertSendResponseCommand.isSuccess());
@ -118,7 +124,7 @@ public class AlertClientServiceTest {
alertResult.setMessage(message); alertResult.setMessage(message);
alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults);
resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque());
PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); Mockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand);
alertSendResponseCommand = alertSendResponseCommand =
alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode()); alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode());
Assert.assertFalse(alertSendResponseCommand.isSuccess()); Assert.assertFalse(alertSendResponseCommand.isSuccess());
@ -131,7 +137,7 @@ public class AlertClientServiceTest {
alertResult.setMessage("Abnormal information inside the alert plug-in code"); alertResult.setMessage("Abnormal information inside the alert plug-in code");
alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults);
resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque());
PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); Mockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand);
alertSendResponseCommand = alertSendResponseCommand =
alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode()); alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode());
Assert.assertFalse(alertSendResponseCommand.isSuccess()); Assert.assertFalse(alertSendResponseCommand.isSuccess());
@ -145,7 +151,7 @@ public class AlertClientServiceTest {
alertResult.setMessage(message); alertResult.setMessage(message);
alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults);
resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque());
PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); Mockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand);
alertSendResponseCommand = alertSendResponseCommand =
alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode()); alertClient.sendAlert(host, port, groupId, title, content, WarningType.FAILURE.getCode());
Assert.assertTrue(alertSendResponseCommand.isSuccess()); Assert.assertTrue(alertSendResponseCommand.isSuccess());

4
dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/ProcessAlertManagerTest.java

@ -33,14 +33,14 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* ProcessAlertManager Test * ProcessAlertManager Test
*/ */
@RunWith(PowerMockRunner.class) @RunWith(MockitoJUnitRunner.class)
public class ProcessAlertManagerTest { public class ProcessAlertManagerTest {
private static final Logger logger = LoggerFactory.getLogger(ProcessAlertManagerTest.class); private static final Logger logger = LoggerFactory.getLogger(ProcessAlertManagerTest.class);

94
dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/log/LogClientTest.java

@ -27,20 +27,18 @@ import org.apache.dolphinscheduler.remote.command.log.RemoveTaskLogResponseComma
import org.apache.dolphinscheduler.remote.command.log.RollViewLogResponseCommand; import org.apache.dolphinscheduler.remote.command.log.RollViewLogResponseCommand;
import org.apache.dolphinscheduler.remote.command.log.ViewLogResponseCommand; import org.apache.dolphinscheduler.remote.command.log.ViewLogResponseCommand;
import org.apache.dolphinscheduler.remote.utils.Host; import org.apache.dolphinscheduler.remote.utils.Host;
import org.apache.dolphinscheduler.service.factory.NettyRemotingClientFactory;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.Test.None;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito; import org.mockito.junit.MockitoJUnitRunner;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class) @RunWith(MockitoJUnitRunner.class)
@PrepareForTest({LogClient.class, NetUtils.class, LoggerUtils.class, NettyRemotingClient.class})
public class LogClientTest { public class LogClientTest {
@Test @Test
@ -49,15 +47,18 @@ public class LogClientTest {
int port = 1234; int port = 1234;
String path = "/tmp/log"; String path = "/tmp/log";
PowerMockito.mockStatic(NetUtils.class); try (
PowerMockito.when(NetUtils.getHost()).thenReturn(localMachine); MockedStatic<NetUtils> mockedNetUtils = Mockito.mockStatic(NetUtils.class);
PowerMockito.mockStatic(LoggerUtils.class); MockedStatic<LoggerUtils> mockedLoggerUtils = Mockito.mockStatic(LoggerUtils.class)) {
PowerMockito.when(LoggerUtils.readWholeFileContent(Mockito.anyString())).thenReturn("application_xx_11"); mockedNetUtils.when(NetUtils::getHost)
.thenReturn(localMachine);
mockedLoggerUtils.when(() -> LoggerUtils.readWholeFileContent(Mockito.anyString()))
.thenReturn("application_xx_11");
LogClient logClient = new LogClient(); LogClient logClient = new LogClient();
String log = logClient.viewLog(localMachine, port, path); String log = logClient.viewLog(localMachine, port, path);
Assert.assertNotNull(log); Assert.assertNotNull(log);
} }
}
@Test @Test
public void testViewLogFromRemote() throws Exception { public void testViewLogFromRemote() throws Exception {
@ -65,74 +66,93 @@ public class LogClientTest {
int port = 1234; int port = 1234;
String path = "/tmp/log"; String path = "/tmp/log";
PowerMockito.mockStatic(NetUtils.class); try (MockedStatic<NetUtils> mockedNetUtils = Mockito.mockStatic(NetUtils.class)) {
PowerMockito.when(NetUtils.getHost()).thenReturn(localMachine + "1"); mockedNetUtils.when(NetUtils::getHost)
.thenReturn(localMachine + "1");
NettyRemotingClient remotingClient = PowerMockito.mock(NettyRemotingClient.class); LogClient logClient = new LogClient();
PowerMockito.whenNew(NettyRemotingClient.class).withAnyArguments().thenReturn(remotingClient); String log = logClient.viewLog(localMachine, port, path);
Assert.assertNotNull(log);
}
Command command = new Command(); Command command = new Command();
command.setBody(JSONUtils.toJsonString(new ViewLogResponseCommand("")).getBytes(StandardCharsets.UTF_8)); command.setBody(JSONUtils.toJsonString(new ViewLogResponseCommand("")).getBytes(StandardCharsets.UTF_8));
PowerMockito.when(remotingClient.sendSync(Mockito.any(Host.class), Mockito.any(Command.class), Mockito.anyLong()))
.thenReturn(command);
LogClient logClient = new LogClient(); LogClient logClient = new LogClient();
String log = logClient.viewLog(localMachine, port, path); String log = logClient.viewLog(localMachine, port, path);
Assert.assertNotNull(log); Assert.assertNotNull(log);
} }
@Test(expected = None.class) @Test
public void testClose() throws Exception { public void testClose() {
NettyRemotingClient remotingClient = PowerMockito.mock(NettyRemotingClient.class); try (
PowerMockito.whenNew(NettyRemotingClient.class).withAnyArguments().thenReturn(remotingClient); MockedStatic<NettyRemotingClientFactory> mockedNettyRemotingClientFactory =
PowerMockito.doNothing().when(remotingClient).close(); Mockito.mockStatic(NettyRemotingClientFactory.class)) {
NettyRemotingClient remotingClient = Mockito.mock(NettyRemotingClient.class);
mockedNettyRemotingClientFactory.when(NettyRemotingClientFactory::buildNettyRemotingClient)
.thenReturn(remotingClient);
LogClient logClient = new LogClient(); LogClient logClient = new LogClient();
logClient.close(); logClient.close();
} }
}
@Test @Test
public void testRollViewLog() throws Exception { public void testRollViewLog() throws Exception {
NettyRemotingClient remotingClient = PowerMockito.mock(NettyRemotingClient.class); try (
PowerMockito.whenNew(NettyRemotingClient.class).withAnyArguments().thenReturn(remotingClient); MockedStatic<NettyRemotingClientFactory> mockedNettyRemotingClientFactory =
Mockito.mockStatic(NettyRemotingClientFactory.class)) {
NettyRemotingClient remotingClient = Mockito.mock(NettyRemotingClient.class);
mockedNettyRemotingClientFactory.when(NettyRemotingClientFactory::buildNettyRemotingClient)
.thenReturn(remotingClient);
Command command = new Command(); Command command = new Command();
command.setBody(JSONUtils.toJsonByteArray(new RollViewLogResponseCommand("success"))); command.setBody(JSONUtils.toJsonByteArray(new RollViewLogResponseCommand("success")));
PowerMockito.when(remotingClient.sendSync(Mockito.any(Host.class), Mockito.any(Command.class), Mockito.anyLong())) Mockito.when(
remotingClient.sendSync(Mockito.any(Host.class), Mockito.any(Command.class), Mockito.anyLong()))
.thenReturn(command); .thenReturn(command);
LogClient logClient = new LogClient(); LogClient logClient = new LogClient();
String msg = logClient.rollViewLog("localhost", 1234, "/tmp/log", 0, 10); String msg = logClient.rollViewLog("localhost", 1234, "/tmp/log", 0, 10);
Assert.assertNotNull(msg); Assert.assertNotNull(msg);
} }
}
@Test @Test
public void testGetLogBytes() throws Exception { public void testGetLogBytes() throws Exception {
NettyRemotingClient remotingClient = PowerMockito.mock(NettyRemotingClient.class); try (
PowerMockito.whenNew(NettyRemotingClient.class).withAnyArguments().thenReturn(remotingClient); MockedStatic<NettyRemotingClientFactory> mockedNettyRemotingClientFactory =
Mockito.mockStatic(NettyRemotingClientFactory.class)) {
NettyRemotingClient remotingClient = Mockito.mock(NettyRemotingClient.class);
mockedNettyRemotingClientFactory.when(NettyRemotingClientFactory::buildNettyRemotingClient)
.thenReturn(remotingClient);
Command command = new Command(); Command command = new Command();
command.setBody(JSONUtils.toJsonByteArray(new GetLogBytesResponseCommand("log".getBytes(StandardCharsets.UTF_8)))); command.setBody(
PowerMockito.when(remotingClient.sendSync(Mockito.any(Host.class), Mockito.any(Command.class), Mockito.anyLong())) JSONUtils.toJsonByteArray(new GetLogBytesResponseCommand("log".getBytes(StandardCharsets.UTF_8))));
Mockito.when(
remotingClient.sendSync(Mockito.any(Host.class), Mockito.any(Command.class), Mockito.anyLong()))
.thenReturn(command); .thenReturn(command);
LogClient logClient = new LogClient(); LogClient logClient = new LogClient();
byte[] logBytes = logClient.getLogBytes("localhost", 1234, "/tmp/log"); byte[] logBytes = logClient.getLogBytes("localhost", 1234, "/tmp/log");
Assert.assertNotNull(logBytes); Assert.assertNotNull(logBytes);
} }
}
@Test @Test
public void testRemoveTaskLog() throws Exception { public void testRemoveTaskLog() throws Exception {
NettyRemotingClient remotingClient = PowerMockito.mock(NettyRemotingClient.class);
PowerMockito.whenNew(NettyRemotingClient.class).withAnyArguments().thenReturn(remotingClient);
try (
MockedStatic<NettyRemotingClientFactory> mockedNettyRemotingClientFactory =
Mockito.mockStatic(NettyRemotingClientFactory.class)) {
NettyRemotingClient remotingClient = Mockito.mock(NettyRemotingClient.class);
mockedNettyRemotingClientFactory.when(NettyRemotingClientFactory::buildNettyRemotingClient)
.thenReturn(remotingClient);
Command command = new Command(); Command command = new Command();
command.setBody(JSONUtils.toJsonByteArray(new RemoveTaskLogResponseCommand(true))); command.setBody(JSONUtils.toJsonByteArray(new RemoveTaskLogResponseCommand(true)));
PowerMockito.when(remotingClient.sendSync(Mockito.any(Host.class), Mockito.any(Command.class), Mockito.anyLong())) Mockito.when(
remotingClient.sendSync(Mockito.any(Host.class), Mockito.any(Command.class), Mockito.anyLong()))
.thenReturn(command); .thenReturn(command);
LogClient logClient = new LogClient(); LogClient logClient = new LogClient();
Boolean status = logClient.removeTaskLog("localhost", 1234, "/log/path"); Boolean status = logClient.removeTaskLog("localhost", 1234, "/log/path");
Assert.assertTrue(status); Assert.assertTrue(status);
} }
}
} }

20
dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java

@ -102,7 +102,6 @@ import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.powermock.reflect.Whitebox;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -823,16 +822,12 @@ public class ProcessServiceTest {
public void testUpdateResourceInfo() throws Exception { public void testUpdateResourceInfo() throws Exception {
// test if input is null // test if input is null
ResourceInfo resourceInfoNull = null; ResourceInfo resourceInfoNull = null;
ResourceInfo updatedResourceInfo1 = Whitebox.invokeMethod(processService, ResourceInfo updatedResourceInfo1 = processService.updateResourceInfo(resourceInfoNull);
"updateResourceInfo",
resourceInfoNull);
Assert.assertNull(updatedResourceInfo1); Assert.assertNull(updatedResourceInfo1);
// test if resource id less than 1 // test if resource id less than 1
ResourceInfo resourceInfoVoid = new ResourceInfo(); ResourceInfo resourceInfoVoid = new ResourceInfo();
ResourceInfo updatedResourceInfo2 = Whitebox.invokeMethod(processService, ResourceInfo updatedResourceInfo2 = processService.updateResourceInfo(resourceInfoVoid);
"updateResourceInfo",
resourceInfoVoid);
Assert.assertNull(updatedResourceInfo2); Assert.assertNull(updatedResourceInfo2);
// test normal situation // test normal situation
@ -843,9 +838,8 @@ public class ProcessServiceTest {
resource.setFileName("test.txt"); resource.setFileName("test.txt");
resource.setFullName("/test.txt"); resource.setFullName("/test.txt");
Mockito.when(resourceMapper.selectById(1)).thenReturn(resource); Mockito.when(resourceMapper.selectById(1)).thenReturn(resource);
ResourceInfo updatedResourceInfo3 = Whitebox.invokeMethod(processService,
"updateResourceInfo", ResourceInfo updatedResourceInfo3 = processService.updateResourceInfo(resourceInfoNormal);
resourceInfoNormal);
Assert.assertEquals(1, updatedResourceInfo3.getId().intValue()); Assert.assertEquals(1, updatedResourceInfo3.getId().intValue());
Assert.assertEquals("test.txt", updatedResourceInfo3.getRes()); Assert.assertEquals("test.txt", updatedResourceInfo3.getRes());
@ -912,12 +906,14 @@ public class ProcessServiceTest {
int testFlag = 1; int testFlag = 1;
// find test lastManualProcessInterval // find test lastManualProcessInterval
ProcessInstance lastManualProcessInterval = processService.findLastManualProcessInterval(definitionCode, dateInterval, testFlag); ProcessInstance lastManualProcessInterval =
processService.findLastManualProcessInterval(definitionCode, dateInterval, testFlag);
Assert.assertEquals(null, lastManualProcessInterval); Assert.assertEquals(null, lastManualProcessInterval);
// find online lastManualProcessInterval // find online lastManualProcessInterval
testFlag = 0; testFlag = 0;
lastManualProcessInterval = processService.findLastManualProcessInterval(definitionCode, dateInterval, testFlag); lastManualProcessInterval =
processService.findLastManualProcessInterval(definitionCode, dateInterval, testFlag);
Assert.assertEquals(null, lastManualProcessInterval); Assert.assertEquals(null, lastManualProcessInterval);
} }

Loading…
Cancel
Save