Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
开发团队
Flowable Engine
提交
73766c38
F
Flowable Engine
项目概览
开发团队
/
Flowable Engine
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Flowable Engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73766c38
编写于
5月 03, 2013
作者:
F
Frederik Heremans
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added concurrency-test (excluding h2 due to full-table locks)
上级
d5e0cb8d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
194 addition
and
0 deletion
+194
-0
modules/activiti-engine/src/test/java/org/activiti/engine/test/concurrency/ConcurrentEngineUsageTest.java
...ti/engine/test/concurrency/ConcurrentEngineUsageTest.java
+107
-0
modules/activiti-engine/src/test/java/org/activiti/engine/test/concurrency/SetRandomVariablesTaskListener.java
...gine/test/concurrency/SetRandomVariablesTaskListener.java
+58
-0
modules/activiti-engine/src/test/resources/org/activiti/engine/test/concurrency/ConcurrentEngineUsageTest.testConcurrentUsage.bpmn20.xml
.../ConcurrentEngineUsageTest.testConcurrentUsage.bpmn20.xml
+29
-0
未找到文件。
modules/activiti-engine/src/test/java/org/activiti/engine/test/concurrency/ConcurrentEngineUsageTest.java
0 → 100644
浏览文件 @
73766c38
/* Licensed 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.activiti.engine.test.concurrency
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
org.activiti.engine.impl.history.HistoryLevel
;
import
org.activiti.engine.impl.identity.Authentication
;
import
org.activiti.engine.impl.test.PluggableActivitiTestCase
;
import
org.activiti.engine.task.Task
;
import
org.activiti.engine.test.Deployment
;
/**
* Test that uses a number of threads to start processes and complete tasks concurrently.
*
* @author Frederik Heremans
*/
public
class
ConcurrentEngineUsageTest
extends
PluggableActivitiTestCase
{
@Deployment
public
void
testConcurrentUsage
()
throws
Exception
{
if
(!
processEngineConfiguration
.
getDatabaseType
().
equals
(
"h2"
))
{
int
numberOfThreads
=
5
;
int
numberOfProcessesPerThread
=
5
;
int
totalNumberOfTasks
=
2
*
numberOfThreads
*
numberOfProcessesPerThread
;
ThreadPoolExecutor
executor
=
new
ThreadPoolExecutor
(
10
,
10
,
1000
,
TimeUnit
.
MILLISECONDS
,
new
ArrayBlockingQueue
<
Runnable
>(
numberOfThreads
));
for
(
int
i
=
0
;
i
<
numberOfThreads
;
i
++)
{
executor
.
execute
(
new
ConcurrentProcessRunnerRunnable
(
numberOfProcessesPerThread
,
"kermit"
+
i
));
}
// Wait for termination or timeout and check if all tasks are complete
executor
.
shutdown
();
executor
.
awaitTermination
(
20000
,
TimeUnit
.
MILLISECONDS
);
assertEquals
(
0
,
executor
.
getActiveCount
());
// Check there are no processes active anymore
assertEquals
(
0
,
runtimeService
.
createProcessInstanceQuery
().
count
());
if
(
processEngineConfiguration
.
getHistoryLevel
().
isAtLeast
(
HistoryLevel
.
ACTIVITY
))
{
// Check if all processes and tasks are complete
assertEquals
(
numberOfProcessesPerThread
*
numberOfThreads
,
historyService
.
createHistoricProcessInstanceQuery
()
.
finished
().
count
());
assertEquals
(
totalNumberOfTasks
,
historyService
.
createHistoricTaskInstanceQuery
()
.
finished
().
count
());
}
}
}
private
class
ConcurrentProcessRunnerRunnable
implements
Runnable
{
private
String
drivingUser
;
private
int
numberOfProcesses
;
public
ConcurrentProcessRunnerRunnable
(
int
numberOfProcesses
,
String
drivingUser
)
{
this
.
drivingUser
=
drivingUser
;
this
.
numberOfProcesses
=
numberOfProcesses
;
}
@Override
public
void
run
()
{
Authentication
.
setAuthenticatedUserId
(
drivingUser
);
boolean
finishTask
=
false
;
boolean
tasksAvailable
=
false
;
while
(
numberOfProcesses
>
0
||
tasksAvailable
)
{
if
(
numberOfProcesses
>
0
&&
!
finishTask
)
{
// Start a new process
runtimeService
.
startProcessInstanceByKey
(
"concurrentProcess"
,
Collections
.
singletonMap
(
"assignee"
,
(
Object
)
drivingUser
));
finishTask
=
true
;
if
(
numberOfProcesses
==
0
)
{
// Make sure while-loop doesn't stop when processes are all started
tasksAvailable
=
taskService
.
createTaskQuery
().
taskAssignee
(
drivingUser
).
count
()
>
0
;
}
numberOfProcesses
=
numberOfProcesses
-
1
;
}
else
{
// Finish a task
List
<
Task
>
taskToComplete
=
taskService
.
createTaskQuery
().
taskAssignee
(
drivingUser
).
listPage
(
0
,
1
);
tasksAvailable
=
taskToComplete
.
size
()
>
0
;
taskService
.
complete
(
taskToComplete
.
get
(
0
).
getId
());
finishTask
=
false
;
}
}
}
}
}
modules/activiti-engine/src/test/java/org/activiti/engine/test/concurrency/SetRandomVariablesTaskListener.java
0 → 100644
浏览文件 @
73766c38
/* Licensed 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.activiti.engine.test.concurrency
;
import
java.util.Random
;
import
org.activiti.engine.delegate.DelegateTask
;
import
org.activiti.engine.delegate.TaskListener
;
/**
* Tasklistener that sets some random process and task-variables.
*
* @author Frederik Heremans
*/
public
class
SetRandomVariablesTaskListener
implements
TaskListener
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
public
void
notify
(
DelegateTask
delegateTask
)
{
String
varName
=
null
;
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
varName
=
"variable-"
+
new
Random
().
nextInt
(
10
);
delegateTask
.
getExecution
().
setVariable
(
varName
,
getRandomValue
());
}
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
varName
=
"task-variable-"
+
new
Random
().
nextInt
(
10
);
delegateTask
.
setVariableLocal
(
varName
,
getRandomValue
());
}
}
protected
Object
getRandomValue
()
{
switch
(
new
Random
().
nextInt
(
4
))
{
case
0
:
return
new
Random
().
nextLong
();
case
1
:
return
new
Random
().
nextDouble
();
case
2
:
return
"Activiti is a light-weight workflow and Business Process Management (BPM) Platform"
;
default
:
return
"Some bytearray"
.
getBytes
();
}
}
}
modules/activiti-engine/src/test/resources/org/activiti/engine/test/concurrency/ConcurrentEngineUsageTest.testConcurrentUsage.bpmn20.xml
0 → 100644
浏览文件 @
73766c38
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns=
"http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti=
"http://activiti.org/bpmn"
targetNamespace=
"TwoTaskCategory"
>
<process
id=
"concurrentProcess"
name=
"Just another process"
>
<documentation>
Two task process description
</documentation>
<startEvent
id=
"theStart"
/>
<sequenceFlow
id=
"flow1"
sourceRef=
"theStart"
targetRef=
"theTask"
/>
<userTask
id=
"theTask"
name=
"my task"
activiti:assignee=
"${assignee}"
>
<extensionElements>
<activiti:taskListener
event=
"create"
class=
"org.activiti.engine.test.concurrency.SetRandomVariablesTaskListener"
/>
<activiti:taskListener
event=
"complete"
class=
"org.activiti.engine.test.concurrency.SetRandomVariablesTaskListener"
/>
</extensionElements>
</userTask>
<sequenceFlow
id=
"flow2"
sourceRef=
"theTask"
targetRef=
"theSecondTask"
/>
<userTask
id=
"theSecondTask"
name=
"my task"
activiti:assignee=
"${assignee}"
>
<extensionElements>
<activiti:taskListener
event=
"create"
class=
"org.activiti.engine.test.concurrency.SetRandomVariablesTaskListener"
/>
<activiti:taskListener
event=
"complete"
class=
"org.activiti.engine.test.concurrency.SetRandomVariablesTaskListener"
/>
</extensionElements>
</userTask>
<sequenceFlow
id=
"flow3"
sourceRef=
"theSecondTask"
targetRef=
"theEnd"
/>
<endEvent
id=
"theEnd"
/>
</process>
</definitions>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录