[jboss-svn-commits] JBL Code SVN: r34468 - in labs/jbossrules/branches/trunk_20100722_esteban_diega: drools-core/src/main/java/org/drools/workflow/instance/impl and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 2 14:25:47 EDT 2010
Author: eaa
Date: 2010-08-02 14:25:46 -0400 (Mon, 02 Aug 2010)
New Revision: 34468
Added:
labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ProcessNodeExecutionException.java
Removed:
labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ManagedRuntimeException.java
Modified:
labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-compiler/src/test/java/org/drools/integrationtests/ProcessNodeExceptionOccurredEventTest.java
labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/NodeInstanceImpl.java
Log:
JBRULES-2595: Extend ProcessEventListener to add support for low-level exceptions occurred in a process execution
- ManagedRuntimeException renamed to ProcessNodeExecutionException
- Added a test for exceptions occurred inside handler
Modified: labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-compiler/src/test/java/org/drools/integrationtests/ProcessNodeExceptionOccurredEventTest.java
===================================================================
--- labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-compiler/src/test/java/org/drools/integrationtests/ProcessNodeExceptionOccurredEventTest.java 2010-08-02 18:22:14 UTC (rev 34467)
+++ labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-compiler/src/test/java/org/drools/integrationtests/ProcessNodeExceptionOccurredEventTest.java 2010-08-02 18:25:46 UTC (rev 34468)
@@ -1,5 +1,6 @@
package org.drools.integrationtests;
+import org.drools.runtime.process.ProcessInstance;
import org.drools.impl.StatefulKnowledgeSessionImpl.ProcessEventListenerWrapper;
import org.drools.Person;
import java.util.List;
@@ -37,6 +38,7 @@
import org.drools.workflow.core.node.EndNode;
import org.drools.workflow.core.node.StartNode;
import org.drools.workflow.core.node.SubProcessNode;
+import org.drools.workflow.instance.impl.ProcessNodeExecutionException;
import static org.junit.Assert.*;
@@ -155,6 +157,32 @@
}
}
+ private class MyBusinessException extends RuntimeException{
+ private ProcessNodeExceptionOccurredEvent source;
+
+ public MyBusinessException(ProcessNodeExceptionOccurredEvent source){
+ this.source = source;
+ }
+
+ public String getProcessName(){
+ return this.source.getProcessInstance().getProcessName();
+ }
+
+ public String getNodeName(){
+ return this.source.getNodeInstance().getNodeName();
+ }
+
+ public Throwable getOriginalException(){
+ return this.source.getError();
+ }
+
+ @Override
+ public String toString() {
+ return "MyBusinessException{" + "Original Exception= '" + this.getOriginalException().toString() + "', Process= '"+this.getProcessName()+"', Process= '"+this.getProcessName()+"}";
+ }
+
+ }
+
/**
* Test of ProcessNodeExceptionOccurredEvent inside an action node and inside
* a WorkItemHandler too.
@@ -206,7 +234,6 @@
ksession.startProcess("org.drools.test.process1");
fail("An exception should occurr!");
} catch (RuntimeException ex) {
- //ok
}
assertEquals(1, this.exceptionCount);
this.exceptionCount = 0;
@@ -214,6 +241,62 @@
ksession.dispose();
}
+ @Test
+ public void testListenerException(){
+ //Create a new kbase with the given flow.
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ kbuilder.add(ResourceFactory.newClassPathResource("org/drools/integrationtests/ProcessNodeExceptionOccurredEventTest.rf"), ResourceType.DRF);
+ if (kbuilder.hasErrors()) {
+ Assert.fail(kbuilder.getErrors().toString());
+ }
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+ kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
+
+ //Create a ksession and add a custom ProcessEventListener
+ final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
+ ksession.addEventListener(new DefaultProcessEventListener(){
+
+ @Override
+ public void onNodeException(ProcessNodeExceptionOccurredEvent event) {
+ if (event.getError() instanceof MyBusinessException){
+ return;
+ }
+ System.out.println("\t"+event.getNodeInstance().getNodeName());
+ exceptionCount++;
+ throw new MyBusinessException(event);
+ }
+
+ });
+
+ //Insert all the needed globals. Inserting a person will make that the
+ //Action node works fine.
+ List<String> list = new ArrayList<String>();
+ Person person = new Person();
+ person.setName("John");
+ ksession.setGlobal("person", person);
+ ksession.setGlobal("list", list);
+
+ //Register a WorkItemHandler. This handler will throw an exception when
+ //invoked.
+ ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new FailWorkItemHandler());
+
+
+ this.expectedResult = new ExpectedResult("flow","HumanTask", "MyBusinessException");
+ try {
+ ksession.startProcess("org.drools.test.process1");
+ fail("An exception should occurr!");
+ } catch (ProcessNodeExecutionException ex) {
+ System.out.println("\tProcessNodeExecutionException: "+ex.getCause());
+ assertTrue(ex.getCause() instanceof MyBusinessException);
+ assertEquals("flow", ((MyBusinessException)ex.getCause()).getProcessName());
+ assertEquals("HumanTask", ((MyBusinessException)ex.getCause()).getNodeName());
+ }
+ assertEquals(1, this.exceptionCount);
+ this.exceptionCount = 0;
+
+ ksession.dispose();
+ }
+
/**
* Test for ProcessNodeExceptionOccurredEvent events thrown inside a subprocess.
* This test will define the main process and subprocess using apis instead
Deleted: labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ManagedRuntimeException.java
===================================================================
--- labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ManagedRuntimeException.java 2010-08-02 18:22:14 UTC (rev 34467)
+++ labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ManagedRuntimeException.java 2010-08-02 18:25:46 UTC (rev 34468)
@@ -1,14 +0,0 @@
-package org.drools.workflow.instance.impl;
-
-/**
- * Wrapper of a RuntimeException. This exception means that the original
- * RuntieException was already managed.
- * @author esteban
- */
-public class ManagedRuntimeException extends RuntimeException{
-
- public ManagedRuntimeException(Throwable cause) {
- super(cause);
- }
-
-}
Modified: labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/NodeInstanceImpl.java
===================================================================
--- labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/NodeInstanceImpl.java 2010-08-02 18:22:14 UTC (rev 34467)
+++ labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/NodeInstanceImpl.java 2010-08-02 18:25:46 UTC (rev 34468)
@@ -113,13 +113,15 @@
}
try {
internalTrigger(from, type);
- } catch (ManagedRuntimeException ex) {
+ } catch (ProcessNodeExecutionException ex) {
+ //We don't wont to wrap a ProcessNodeExecutionException again.
throw ex;
} catch (RuntimeException ex) {
if (!hidden) {
((EventSupport) workingMemory).getRuleFlowEventSupport().fireRuleFlowNodeExceptionOccurred(processInstance, this, ex, workingMemory);
}
- throw new ManagedRuntimeException(ex);
+ //The exception is wrapped in a ProcessNodeExecutionException
+ throw new ProcessNodeExecutionException(ex);
}
if (!hidden) {
((EventSupport) workingMemory).getRuleFlowEventSupport().fireAfterRuleFlowNodeTriggered(this, (InternalWorkingMemory) workingMemory);
Copied: labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ProcessNodeExecutionException.java (from rev 34461, labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ManagedRuntimeException.java)
===================================================================
--- labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ProcessNodeExecutionException.java (rev 0)
+++ labs/jbossrules/branches/trunk_20100722_esteban_diega/drools-core/src/main/java/org/drools/workflow/instance/impl/ProcessNodeExecutionException.java 2010-08-02 18:25:46 UTC (rev 34468)
@@ -0,0 +1,14 @@
+package org.drools.workflow.instance.impl;
+
+/**
+ * Exception thrown when an unexpected Exception occurs while executing
+ * a node inside a process.
+ * @author esteban
+ */
+public class ProcessNodeExecutionException extends RuntimeException{
+
+ public ProcessNodeExecutionException(Throwable cause) {
+ super(cause);
+ }
+
+}
More information about the jboss-svn-commits
mailing list