<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    blocking task in start-state does not block
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/laszlovandenhoek">László van den Hoek</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/600661#600661">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'm running into the problem that a blocking task in a start-state node does not prevent a token to proceed to the next node, but a "regular" blocking task in a task-node does. I'm using the jBPM 3.2 runtime included with the latest JBoss SOA-P 5.1. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The below JUnit test code illustrates the problem. There are two test cases; the only real difference is that the one tests a blocking start task and the other tests a blocking "regular" task. For me, the first test case fails but the second one succeeds. The way they are written, I would expect this to be the other way around.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I understand from {thread:id=390489} that creating a new ProcessInstance will not automatically create a TaskInstance for the task defined in the start-state, if any. While this strikes me as odd, I can accept that is the way things work. However, once I manually create the StartTaskInstance, I do expect it to block progress to the next node.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>{code}</p><p>package nl.travelcard.das.workflow;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import java.util.HashMap;</p><p>import java.util.Map;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import junit.framework.TestCase;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import org.jbpm.graph.def.ProcessDefinition;</p><p>import org.jbpm.graph.exe.ProcessInstance;</p><p>import org.jbpm.taskmgmt.exe.TaskInstance;</p><p>import org.junit.Before;</p><p>import org.junit.Test;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class JbpmTest extends TestCase {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private ProcessDefinition pd;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Before</p><p>&#160;&#160;&#160; public void setUp() {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.pd = ProcessDefinition.parseXmlString(&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;" + </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&lt;process-definition&#160; xmlns=\"\"&#160; name=\"blockingStartTask\"&gt;" +</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160; &lt;start-state name=\"start\"&gt;" +</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;task blocking=\"true\" name=\"blocking task in start node\"&gt;&lt;/task&gt;" +</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition to=\"task\"&gt;&lt;/transition&gt;" +</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160; &lt;/start-state&gt;" +</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160; &lt;task-node name=\"task\"&gt;" +</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;task blocking=\"true\" name=\"blocking task in task node\" &gt;&lt;/task&gt;" +</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition to=\"end\"&gt;&lt;/transition&gt;" +</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160; &lt;/task-node&gt;" +</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&#160;&#160;&#160; &lt;end-state name=\"end\"&gt;&lt;/end-state&gt;" +</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "&lt;/process-definition&gt;"</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; );</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Test</p><p>&#160;&#160;&#160; public void testBlockingStartTask() {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ProcessInstance pi = pd.createProcessInstance();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //I would have expected a task instance to have been created by now; I guess that's not how it works.</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //assertEquals("expected task was not created", 1, pi.getTaskMgmtInstance().getTaskInstances().size());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("expected task was not created", 1, pi.getTaskMgmtInstance().getTaskInstances().size());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("task has wrong name", "blocking task in start node", ti.getName());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertTrue(ti.isBlocking());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertTrue(ti.isStartTaskInstance());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertTrue(pi.getTaskMgmtInstance().hasBlockingTaskInstances(pi.getRootToken()));</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; pi.getRootToken().signal();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fail("task that should be blocking nevertheless did not block");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (IllegalStateException e) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("state changed despite blocking task", "start", pi.getRootToken().getNode().getName());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("start", pi.getRootToken().getNode().getName());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Test</p><p>&#160;&#160;&#160; public void testBlockingRegularTask() {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ProcessInstance pi = pd.createProcessInstance();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("start", pi.getRootToken().getNode().getName());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; pi.signal(); //this ought to go wrong, but it doesn't (see previous test case)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("task", pi.getRootToken().getNode().getName());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("expected task was not created", 1, pi.getTaskMgmtInstance().getTaskInstances().size());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TaskInstance ti = pi.getTaskMgmtInstance().getTaskInstances().iterator().next();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("task has wrong name", "blocking task in task node", ti.getName());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertTrue(ti.isBlocking());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertFalse(ti.isStartTaskInstance());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertTrue(pi.getTaskMgmtInstance().hasBlockingTaskInstances(pi.getRootToken()));</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; pi.getRootToken().signal();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fail("task that should be blocking nevertheless did not block");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (IllegalStateException e) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("state changed despite blocking task", "task", pi.getRootToken().getNode().getName());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("task", pi.getRootToken().getNode().getName());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ti.end();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertEquals("end", pi.getRootToken().getNode().getName());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; }</p><p>}</p><p>{code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any thoughts?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks in advance!</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/600661#600661">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>