forked from kiegroup/jbpm
-
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.
JBPM-5084: troubleshooting function for workitem: unit test
- Loading branch information
xiabai
committed
May 25, 2016
1 parent
cba333c
commit 487792c
Showing
9 changed files
with
612 additions
and
3 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...st-coverage/src/test/java/org/jbpm/test/functional/workitem/ExceptionWorkItemHandler.java
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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.jbpm.test.functional.workitem; | ||
|
||
import org.jbpm.process.workitem.AbstractLogOrThrowWorkItemHandler; | ||
import org.kie.api.runtime.process.WorkItem; | ||
import org.kie.api.runtime.process.WorkItemManager; | ||
|
||
public class ExceptionWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { | ||
|
||
@Override | ||
public void executeWorkItem( WorkItem workItem, WorkItemManager manager ) { | ||
String exception = workItem.getParameter( "exception" ).toString(); | ||
try { | ||
if ( "no".equals( exception ) ) { | ||
manager.completeWorkItem( workItem.getId(), null ); | ||
} | ||
else { | ||
throwExceptionSoThatWorkItemIsNOTCompleted( workItem ); | ||
} | ||
} catch ( RuntimeException e ) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void abortWorkItem( WorkItem workItem, WorkItemManager manager ) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
private void throwExceptionSoThatWorkItemIsNOTCompleted( WorkItem workItem ) { | ||
throw new RuntimeException( "Did not complete work item " + workItem.getName() + "/" + workItem.getId() | ||
+ " from node " + ((org.drools.core.process.instance.WorkItem) workItem).getNodeId() ); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...-coverage/src/test/java/org/jbpm/test/functional/workitem/NoExceptionWorkItemHandler.java
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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.jbpm.test.functional.workitem; | ||
|
||
import org.jbpm.process.workitem.AbstractLogOrThrowWorkItemHandler; | ||
import org.kie.api.runtime.process.WorkItem; | ||
import org.kie.api.runtime.process.WorkItemManager; | ||
|
||
|
||
public class NoExceptionWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { | ||
|
||
@Override | ||
public void executeWorkItem( WorkItem workItem, WorkItemManager manager ) { | ||
// doNothing | ||
manager.completeWorkItem(workItem.getId(), null); | ||
|
||
} | ||
|
||
@Override | ||
public void abortWorkItem( WorkItem workItem, WorkItemManager manager ) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...-coverage/src/test/java/org/jbpm/test/functional/workitem/RetrySyncWorkItemByJPATest.java
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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.jbpm.test.functional.workitem; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.drools.core.process.instance.WorkItemManager; | ||
import org.jbpm.test.JbpmTestCase; | ||
import org.junit.Test; | ||
import org.kie.api.runtime.KieSession; | ||
import org.kie.api.runtime.manager.RuntimeEngine; | ||
import org.kie.api.runtime.process.NodeInstance; | ||
import org.kie.api.runtime.process.ProcessInstance; | ||
import org.kie.api.task.TaskService; | ||
import org.kie.api.task.model.TaskSummary; | ||
import org.kie.internal.runtime.manager.context.EmptyContext; | ||
|
||
public class RetrySyncWorkItemByJPATest extends JbpmTestCase { | ||
|
||
private static final String RETRY_WORKITEM_JPA_PROCESS_ID = "org.jbpm.test.retryWorkitem-jpa"; | ||
|
||
public RetrySyncWorkItemByJPATest() { | ||
super( true, true ); | ||
} | ||
|
||
@Test | ||
public void workItemRecoveryTestByJPA() { | ||
manager = createRuntimeManager( "org/jbpm/test/functional/workitem/retry-workitem-jpa.bpmn2" ); | ||
RuntimeEngine runtimeEngine = getRuntimeEngine( EmptyContext.get() ); | ||
KieSession kieSession = runtimeEngine.getKieSession(); | ||
WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager(); | ||
|
||
workItemManager.registerWorkItemHandler( "ExceptionWorkitem", new ExceptionWorkItemHandler() ); | ||
ProcessInstance pi = kieSession.startProcess( RETRY_WORKITEM_JPA_PROCESS_ID ); | ||
TaskService taskService = runtimeEngine.getTaskService(); | ||
|
||
assertProcessInstanceActive( pi.getId() ); | ||
assertNodeTriggered( pi.getId(), "lockingNode" ); | ||
assertNodeActive( pi.getId(), kieSession, "lockingNode" ); | ||
|
||
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner( "john", "en-UK" ); | ||
assertEquals( 1, tasks.size() ); | ||
TaskSummary taskSummary = tasks.get( 0 ); | ||
|
||
taskService.start( taskSummary.getId(), "john" ); | ||
taskService.complete( taskSummary.getId(), "john", null ); | ||
|
||
ProcessInstance processInstance = (org.kie.api.runtime.process.WorkflowProcessInstance) kieSession.getProcessInstance( pi.getId() ); | ||
Collection<NodeInstance> nis = ((org.kie.api.runtime.process.WorkflowProcessInstance) processInstance).getNodeInstances(); | ||
retryWorkItem( workItemManager, nis ); | ||
assertProcessInstanceCompleted( processInstance.getId() ); | ||
} | ||
|
||
private void retryWorkItem( WorkItemManager workItemManager, Collection<NodeInstance> nis ) { | ||
for ( NodeInstance di : nis ) { | ||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put( "exception", "no" ); | ||
workItemManager.retryWorkItem( di.getId(), map ); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...verage/src/test/java/org/jbpm/test/functional/workitem/RetrySyncWorkItemByMemoryTest.java
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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.jbpm.test.functional.workitem; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.drools.core.process.instance.WorkItemManager; | ||
import org.jbpm.test.JbpmTestCase; | ||
import org.junit.Test; | ||
import org.kie.api.runtime.KieSession; | ||
import org.kie.api.runtime.manager.RuntimeEngine; | ||
import org.kie.api.runtime.process.NodeInstance; | ||
import org.kie.api.runtime.process.ProcessInstance; | ||
import org.kie.internal.runtime.manager.context.EmptyContext; | ||
|
||
public class RetrySyncWorkItemByMemoryTest extends JbpmTestCase { | ||
|
||
private static final String RETRY_WORKITEM_MEMORY_PROCESS_ID = "org.jbpm.test.retry-workitem-memory"; | ||
|
||
public RetrySyncWorkItemByMemoryTest() { | ||
super( false, false ); | ||
} | ||
|
||
@Test | ||
public void workItemRecoveryTestByMemory() { | ||
manager = createRuntimeManager( "org/jbpm/test/functional/workitem/retry-workitem-memory.bpmn2" ); | ||
RuntimeEngine runtimeEngine = getRuntimeEngine( EmptyContext.get() ); | ||
KieSession kieSession = runtimeEngine.getKieSession(); | ||
WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager(); | ||
|
||
workItemManager.registerWorkItemHandler( "ExceptionWorkitem", new ExceptionWorkItemHandler() ); | ||
workItemManager.registerWorkItemHandler( "NoExceptionWorkitem", new NoExceptionWorkItemHandler() ); | ||
ProcessInstance pi = kieSession.startProcess( RETRY_WORKITEM_MEMORY_PROCESS_ID ); | ||
org.junit.Assert.assertEquals( pi.getState(), 1 ); | ||
|
||
org.kie.api.runtime.process.WorkflowProcessInstance p = (org.kie.api.runtime.process.WorkflowProcessInstance) kieSession.getProcessInstance( pi.getId() ); | ||
Collection<NodeInstance> nis = ((org.kie.api.runtime.process.WorkflowProcessInstance) p).getNodeInstances(); | ||
retryWorkItem( workItemManager, nis ); | ||
org.junit.Assert.assertEquals( p.getState(), 2 ); | ||
|
||
} | ||
|
||
private void retryWorkItem( WorkItemManager workItemManager, Collection<NodeInstance> nis ) { | ||
for ( NodeInstance di : nis ) { | ||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put( "exception", "no" ); | ||
workItemManager.retryWorkItem( di.getId(), map ); | ||
} | ||
} | ||
} |
Oops, something went wrong.