Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pentaLiker
DolphinScheduler
提交
15436cfc
DolphinScheduler
项目概览
pentaLiker
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
1
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,发现更多精彩内容 >>
未验证
提交
15436cfc
编写于
10月 16, 2020
作者:
D
dailidong
提交者:
GitHub
10月 16, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Delete ThreadUtilsTest.java
not useful test
上级
ed3f0891
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
175 deletion
+0
-175
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/threadutils/ThreadUtilsTest.java
.../dolphinscheduler/common/threadutils/ThreadUtilsTest.java
+0
-175
未找到文件。
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/threadutils/ThreadUtilsTest.java
已删除
100644 → 0
浏览文件 @
ed3f0891
/*
* 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.threadutils
;
import
org.apache.dolphinscheduler.common.thread.Stopper
;
import
org.apache.dolphinscheduler.common.thread.ThreadPoolExecutors
;
import
org.apache.dolphinscheduler.common.thread.ThreadUtils
;
import
org.junit.Test
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Calendar
;
import
java.util.concurrent.*
;
import
static
org
.
junit
.
Assert
.*;
public
class
ThreadUtilsTest
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ThreadUtilsTest
.
class
);
/**
* create a naming thread
*/
@Test
public
void
testNewDaemonFixedThreadExecutor
()
{
// create core size and max size are all 3
ExecutorService
testExec
=
ThreadUtils
.
newDaemonFixedThreadExecutor
(
"test-exec-thread"
,
3
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
final
int
index
=
i
;
testExec
.
submit
(()
->
{
logger
.
info
(
"do some work index "
+
index
);
});
}
assertFalse
(
testExec
.
isShutdown
());
testExec
.
shutdownNow
();
assertTrue
(
testExec
.
isShutdown
());
}
/**
* test schedulerThreadExecutor as for print time in scheduler
* default check thread is 1
*/
@Test
public
void
testNewDaemonScheduleThreadExecutor
()
{
ScheduledExecutorService
scheduleService
=
ThreadUtils
.
newDaemonThreadScheduledExecutor
(
"scheduler-thread"
,
1
);
Calendar
start
=
Calendar
.
getInstance
();
Calendar
globalTimer
=
Calendar
.
getInstance
();
globalTimer
.
set
(
2019
,
Calendar
.
DECEMBER
,
1
,
0
,
0
,
0
);
// current
Calendar
end
=
Calendar
.
getInstance
();
end
.
set
(
2019
,
Calendar
.
DECEMBER
,
1
,
0
,
0
,
3
);
Runnable
schedulerTask
=
new
Runnable
()
{
@Override
public
void
run
()
{
start
.
set
(
2019
,
Calendar
.
DECEMBER
,
1
,
0
,
0
,
0
);
int
index
=
0
;
// send heart beat work
while
(
start
.
getTime
().
getTime
()
<=
end
.
getTime
().
getTime
())
{
System
.
out
.
println
(
"worker here"
);
System
.
out
.
println
(
index
++);
start
.
add
(
Calendar
.
SECOND
,
1
);
globalTimer
.
add
(
Calendar
.
SECOND
,
1
);
}
}
};
scheduleService
.
scheduleAtFixedRate
(
schedulerTask
,
2
,
10
,
TimeUnit
.
SECONDS
);
assertFalse
(
scheduleService
.
isShutdown
());
try
{
Thread
.
sleep
(
2000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
scheduleService
.
shutdownNow
();
assertTrue
(
scheduleService
.
isShutdown
());
}
/**
* test stopper is working normal
*/
@Test
public
void
testStopper
()
{
assertTrue
(
Stopper
.
isRunning
());
Stopper
.
stop
();
assertTrue
(
Stopper
.
isStopped
());
}
/**
* test threadPoolExecutors with 3 workers and current each 5 tasks
*/
@Test
public
void
testThreadInfo
()
throws
InterruptedException
{
ThreadPoolExecutors
workers
=
ThreadPoolExecutors
.
getInstance
(
"worker"
,
1
);
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
int
index
=
i
;
workers
.
execute
(()
->
{
for
(
int
j
=
0
;
j
<
1
;
++
j
)
{
try
{
Thread
.
sleep
(
100
);
logger
.
info
(
"worker %s is doing the task"
,
index
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
"InterruptedException"
,
e
);
}
}
});
}
Thread
.
sleep
(
1001
);
workers
.
shutdown
();
}
/**
* test a single daemon thread pool
*/
@Test
public
void
testNewDaemonSingleThreadExecutor
()
{
ExecutorService
threadTest
=
ThreadUtils
.
newDaemonSingleThreadExecutor
(
"thread_test"
);
threadTest
.
execute
(()
->
{
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
logger
.
info
(
"daemon working "
);
}
});
assertFalse
(
threadTest
.
isShutdown
());
threadTest
.
shutdownNow
();
assertTrue
(
threadTest
.
isShutdown
());
}
@Test
public
void
testNewDaemonCachedThreadPool
()
{
ThreadPoolExecutor
threadPoolExecutor
=
ThreadUtils
.
newDaemonCachedThreadPool
(
"threadTest-"
);
Thread
thread1
=
threadPoolExecutor
.
getThreadFactory
().
newThread
(()
->
{
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
logger
.
info
(
"this task is with index "
+
i
);
}
});
assertTrue
(
thread1
.
getName
().
startsWith
(
"threadTest-"
));
assertFalse
(
threadPoolExecutor
.
isShutdown
());
threadPoolExecutor
.
shutdown
();
assertTrue
(
threadPoolExecutor
.
isShutdown
());
}
@Test
public
void
testNewDaemonCachedThreadPoolWithThreadNumber
()
{
ThreadPoolExecutor
threadPoolExecutor
=
ThreadUtils
.
newDaemonCachedThreadPool
(
"threadTest--"
,
3
,
10
);
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
threadPoolExecutor
.
getThreadFactory
().
newThread
(()
->
{
assertEquals
(
3
,
threadPoolExecutor
.
getActiveCount
());
logger
.
info
(
"this task is first work to do"
);
});
}
assertFalse
(
threadPoolExecutor
.
isShutdown
());
threadPoolExecutor
.
shutdown
();
assertTrue
(
threadPoolExecutor
.
isShutdown
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录