parent
8133015e25
commit
7dcd8b26f7
|
|
@ -47,6 +47,30 @@
|
|||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito2</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
|
|
|
|||
|
|
@ -110,10 +110,9 @@ public class FileUtils {
|
|||
* create directory and user
|
||||
* @param execLocalPath execute local path
|
||||
* @param userName user name
|
||||
* @param logger logger
|
||||
* @throws IOException errors
|
||||
*/
|
||||
public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName, Logger logger) throws IOException{
|
||||
public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName) throws IOException{
|
||||
//if work dir exists, first delete
|
||||
File execLocalPathFile = new File(execLocalPath);
|
||||
|
||||
|
|
@ -123,13 +122,14 @@ public class FileUtils {
|
|||
|
||||
//create work dir
|
||||
org.apache.commons.io.FileUtils.forceMkdir(execLocalPathFile);
|
||||
logger.info("create dir success {}" , execLocalPath);
|
||||
|
||||
|
||||
//if not exists this user,then create
|
||||
if (!OSUtils.getUserList().contains(userName)){
|
||||
OSUtils.createUser(userName);
|
||||
}
|
||||
|
||||
logger.info("create user name success {}", userName);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.common.utils;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* encryption utils
|
||||
*/
|
||||
public class EncryptionUtilsTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetMd5() {
|
||||
Assert.assertEquals(EncryptionUtils.getMd5(null), EncryptionUtils.getMd5(""));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,11 +18,50 @@ package org.apache.dolphinscheduler.common.utils;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import static org.apache.dolphinscheduler.common.Constants.YYYYMMDDHHMMSS;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(DateUtils.class)
|
||||
public class FileUtilsTest {
|
||||
|
||||
@Test
|
||||
public void suffix() {
|
||||
Assert.assertEquals(FileUtils.suffix("ninfor.java"),"java");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDownloadFilename() {
|
||||
PowerMockito.mockStatic(DateUtils.class);
|
||||
PowerMockito.when(DateUtils.getCurrentTime(YYYYMMDDHHMMSS)).thenReturn("20190101101059");
|
||||
Assert.assertEquals(FileUtils.getDownloadFilename("test"),
|
||||
"/tmp/dolphinscheduler/download/20190101101059/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploadFilename() {
|
||||
Assert.assertEquals(FileUtils.getUploadFilename("aaa","bbb"),
|
||||
"/tmp/dolphinscheduler/aaa/resources/bbb");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessExecDir() {
|
||||
String dir = FileUtils.getProcessExecDir(1,2,3, 4);
|
||||
Assert.assertEquals(dir, "/tmp/dolphinscheduler/exec/process/1/2/3/4");
|
||||
dir = FileUtils.getProcessExecDir(1,2,3);
|
||||
Assert.assertEquals(dir, "/tmp/dolphinscheduler/exec/process/1/2/3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWorkDirAndUserIfAbsent() {
|
||||
try {
|
||||
FileUtils.createWorkDirAndUserIfAbsent("/tmp/createWorkDirAndUserIfAbsent", "test123");
|
||||
Assert.assertTrue(true);
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.common.utils;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -27,21 +28,20 @@ import org.slf4j.LoggerFactory;
|
|||
* HttpClient utils test
|
||||
*/
|
||||
public class HttpUtilsTest {
|
||||
|
||||
|
||||
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(HttpUtilsTest.class);
|
||||
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void getTest(){
|
||||
|
||||
String result = HttpUtils.get("http://192.168.xx.xx:8088/ws/v1/cluster/info");
|
||||
logger.info(result);
|
||||
|
||||
|
||||
public void testGetTest(){
|
||||
//success
|
||||
String result = HttpUtils.get("https://github.com/manifest.json");
|
||||
Assert.assertNotNull(result);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
String string = jsonObject.getJSONObject("clusterInfo").getString("haState");
|
||||
logger.info(string);
|
||||
Assert.assertEquals(jsonObject.getString("name"), "GitHub");
|
||||
|
||||
result = HttpUtils.get("https://123.333.111.33/ccc");
|
||||
Assert.assertNull(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ public class FetchTaskThread implements Runnable{
|
|||
|
||||
// check and create users
|
||||
FileUtils.createWorkDirAndUserIfAbsent(execLocalPath,
|
||||
tenant.getTenantCode(), logger);
|
||||
tenant.getTenantCode());
|
||||
|
||||
logger.info("task : {} ready to submit to task scheduler thread",taskInstId);
|
||||
// submit task
|
||||
|
|
@ -334,4 +334,4 @@ public class FetchTaskThread implements Runnable{
|
|||
private int getTaskInstanceId(String taskQueueStr){
|
||||
return Integer.parseInt(taskQueueStr.split(Constants.UNDERLINE)[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
34
pom.xml
34
pom.xml
|
|
@ -112,6 +112,8 @@
|
|||
<jcip.version>1.0</jcip.version>
|
||||
<maven.deploy.skip>false</maven.deploy.skip>
|
||||
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
|
||||
<mockito.version>2.21.0</mockito.version>
|
||||
<powermock.version>2.0.2</powermock.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
@ -302,6 +304,36 @@
|
|||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito2</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
|
|
@ -613,12 +645,10 @@
|
|||
<configuration>
|
||||
<includes>
|
||||
<include>**/common/utils/*.java</include>
|
||||
|
||||
<include>**/common/graph/*.java</include>
|
||||
<include>**/common/queue/*.java</include>
|
||||
<include>**/api/utils/CheckUtilsTest.java</include>
|
||||
<include>**/api/utils/FileUtilsTest.java</include>
|
||||
|
||||
<include>**/alert/utils/ExcelUtilsTest.java</include>
|
||||
<include>**/alert/utils/FuncUtilsTest.java</include>
|
||||
<include>**/alert/utils/JSONUtilsTest.java</include>
|
||||
|
|
|
|||
Loading…
Reference in New Issue