forked from apache/dolphinscheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improvement][Test] Remove powermock in service and server modules (a…
…pache#12164) * Remove powermock and refactor some related code in dolphinscheduler-service and dolphinscheduler-server modules * Remove redundant comments * Add null check
- Loading branch information
1 parent
a8f5977
commit a2ca5d9
Showing
12 changed files
with
261 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,31 +17,28 @@ | |
|
||
package org.apache.dolphinscheduler.server.utils; | ||
|
||
import static org.powermock.api.mockito.PowerMockito.when; | ||
import org.apache.commons.lang3.SystemUtils; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
|
||
import org.apache.dolphinscheduler.common.Constants; | ||
import org.apache.dolphinscheduler.common.utils.HadoopUtils; | ||
import org.apache.dolphinscheduler.common.utils.OSUtils; | ||
import org.apache.dolphinscheduler.common.utils.PropertyUtils; | ||
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
import org.powermock.reflect.Whitebox; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest({System.class, OSUtils.class, HadoopUtils.class, PropertyUtils.class, SystemUtils.class}) | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class ProcessUtilsTest { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); | ||
|
@@ -54,23 +51,22 @@ public void setUp() { | |
@Test | ||
public void getPidsStr() throws Exception { | ||
int processId = 1; | ||
PowerMockito.mockStatic(OSUtils.class); | ||
Whitebox.setInternalState(SystemUtils.class, "IS_OS_MAC", true); | ||
when(OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, processId))).thenReturn(null); | ||
String pidListMac = ProcessUtils.getPidsStr(processId); | ||
Assert.assertEquals("", pidListMac); | ||
Mockito.mockStatic(OSUtils.class); | ||
Mockito.when(OSUtils.exeCmd(anyString())).thenReturn(null); | ||
String pidList = ProcessUtils.getPidsStr(processId); | ||
Assert.assertEquals("", pidList); | ||
} | ||
|
||
@Test | ||
public void testGetKerberosInitCommand() { | ||
PowerMockito.mockStatic(PropertyUtils.class); | ||
PowerMockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false)) | ||
Mockito.mockStatic(PropertyUtils.class); | ||
Mockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false)) | ||
.thenReturn(true); | ||
PowerMockito.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"); | ||
PowerMockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME)).thenReturn("[email protected]"); | ||
Mockito.when(PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH)).thenReturn("/etc/krb5.conf"); | ||
Mockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH)).thenReturn("/etc/krb5.keytab"); | ||
Mockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME)).thenReturn("[email protected]"); | ||
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); | ||
Assert.assertEquals("", ProcessUtils.getKerberosInitCommand()); | ||
} | ||
|
@@ -84,17 +80,12 @@ public void testCancelApplication() { | |
String executePath = "/ds-exec/1/1/1"; | ||
TaskExecutionStatus running = TaskExecutionStatus.RUNNING_EXECUTION; | ||
|
||
PowerMockito.mockStatic(HadoopUtils.class); | ||
Mockito.mockStatic(HadoopUtils.class); | ||
HadoopUtils hadoop = HadoopUtils.getInstance(); | ||
|
||
try { | ||
PowerMockito.whenNew(HadoopUtils.class).withAnyArguments().thenReturn(hadoop); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
try { | ||
when(hadoop.getApplicationStatus("application_1585532379175_228491")).thenReturn(running); | ||
when(hadoop.getApplicationStatus("application_1598885606600_3677")).thenReturn(running); | ||
Mockito.when(hadoop.getApplicationStatus("application_1585532379175_228491")).thenReturn(running); | ||
Mockito.when(hadoop.getApplicationStatus("application_1598885606600_3677")).thenReturn(running); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
ProcessUtils.cancelApplication(appIds, logger, tenantCode, executePath); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.