Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
deeplearning
DolphinScheduler
提交
7dcd8b26
DolphinScheduler
项目概览
deeplearning
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
24
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7dcd8b26
编写于
12月 19, 2019
作者:
K
khadgarmage
提交者:
GitHub
12月 19, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
unit test for common utils (#1520)
* httputil osutil encrytiontutil ut
上级
8133015e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
147 addition
and
19 deletion
+147
-19
dolphinscheduler-common/pom.xml
dolphinscheduler-common/pom.xml
+24
-0
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
...a/org/apache/dolphinscheduler/common/utils/FileUtils.java
+3
-3
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/EncryptionUtilsTest.java
...he/dolphinscheduler/common/utils/EncryptionUtilsTest.java
+35
-0
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
...g/apache/dolphinscheduler/common/utils/FileUtilsTest.java
+40
-1
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
...g/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
+11
-11
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/FetchTaskThread.java
...olphinscheduler/server/worker/runner/FetchTaskThread.java
+2
-2
pom.xml
pom.xml
+32
-2
未找到文件。
dolphinscheduler-common/pom.xml
浏览文件 @
7dcd8b26
...
...
@@ -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>
...
...
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
浏览文件 @
7dcd8b26
...
...
@@ -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
);
}
...
...
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/EncryptionUtilsTest.java
0 → 100644
浏览文件 @
7dcd8b26
/*
* 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
(
""
));
}
}
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
浏览文件 @
7dcd8b26
...
...
@@ -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"
);
}
}
\ No newline at end of file
@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
);
}
}
}
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
浏览文件 @
7dcd8b26
...
...
@@ -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
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpUtilsTest
.
class
);
@Test
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
);
}
}
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/FetchTaskThread.java
浏览文件 @
7dcd8b26
...
...
@@ -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
]);
}
}
\ No newline at end of file
}
pom.xml
浏览文件 @
7dcd8b26
...
...
@@ -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>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录