4 Replies Latest reply on Jan 4, 2007 1:27 AM by gwzoller

    A Bug or Newbie Error?

    gwzoller

      Hello,

      I was playing around learning jBPM and wrote a simple test program that gave me unexpected results. Process def and test code given below, but here's the problem in a nutshell. I have a task node "Collect Canditate Info" with 1 task that when complete transitions the node to the next task node "Check Background" which has 2 tasks. My sample program walks the process and prints the number and names of the tasks for these two nodes. The first node, Collect Candidate Info, is fine--1 task correctly named is shown.

      But... after successfully transitioning to "Check Background" my program shows 3 tasks--the one left over from the previous node plus the 2 I expect to see in the now-current node. For some reason the previous task nodes tasks aren't getting cleared out.

      I would expect that after moving to the next node the previous node's tasks should no longer be visible, or at least certainly not mixed in with the current nodes tasks.

      Am I doing something wrong, or is my expectation of correct operation incomplete, or is this just an 'ol fashion bug?

      I'm using the jbpm starters kit 3.1.2.

      Thanks in advance for any replies!
      Greg



      Here's the process definition:

      <?xml version="1.0" encoding="UTF-8"?>

      <process-definition
      xmlns="urn:jbpm.org:jpdl-3.1" name="Hire New Employee">

      <start-state name="start">

      </start-state>
      <task-node name="Check Background">



      </task-node>
      <task-node name="Collect Candidate Info">


      </task-node>
      <task-node name="Interview Candidate">

      </task-node>






      <end-state name="Hire"></end-state>
      <end-state name="Pass"></end-state>
      </process-definition>


      Here's the test program:

      package com.sample;

      import java.io.FileInputStream;
      import junit.framework.TestCase;
      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.exe.ProcessInstance;
      import org.jbpm.taskmgmt.exe.TaskInstance;

      public class GregsTest extends TestCase {

      public void testSimpleProcess() throws Exception {

      // Extract a process definition from the processdefinition.xml file.
      FileInputStream fis = new FileInputStream("processes/Hire New Employee/processdefinition.xml");
      ProcessDefinition processDefinition = ProcessDefinition.parseXmlInputStream(fis);
      assertNotNull("Definition should not be null", processDefinition);

      // Create an instance of the process definition.
      ProcessInstance instance = new ProcessInstance(processDefinition);
      assertEquals(
      "Instance is in start state",
      instance.getRootToken().getNode().getName(),
      "start");
      assertNull(
      "Message variable should not exist yet",
      instance.getContextInstance().getVariable("message"));

      // Move the process instance from its start state to the first state.
      // The configured action should execute and the appropriate message
      // should appear in the message process variable.
      instance.signal();
      assertEquals(
      "Collecting candidate information",
      instance.getRootToken().getNode().getName(),
      "Collect Candidate Info");

      // Move the process instance to the end state. The configured action
      // should execute again. The message variable contains a new value.
      System.out.println("YYY: Number of Tasks in node is "
      + instance.getTaskMgmtInstance().getTaskInstances().size());
      TaskInstance taskInstance = (TaskInstance)
      instance.getTaskMgmtInstance().getTaskInstances().iterator().next();

      System.out.println("ZZZ: Node Now is "+ instance.getRootToken().getNode().getName());
      System.out.println("ZZZ: Task now is "+taskInstance.getName());

      taskInstance.end();
      System.out.println("ZZZ: Node Now is "+ instance.getRootToken().getNode().getName());

      assertEquals(
      "Instance is in Check Background state",
      instance.getRootToken().getNode().getName(),
      "Check Background");

      System.out.println("YYY: Number of Tasks in node is "
      + instance.getTaskMgmtInstance().getTaskInstances().size());
      java.util.Iterator taskScan = instance.getTaskMgmtInstance().getTaskInstances().iterator();
      while(taskScan.hasNext()) {
      TaskInstance aTask = (TaskInstance) taskScan.next();
      // System.out.println("ZZZ: Node Now is "+ instance.getRootToken().getNode().getName());
      System.out.println("ZZZ: Task now is "+aTask.getName());
      //aTask.end();
      }
      }

      }

        • 1. Re: A Bug or Newbie Error?
          kukeltje

          hmmm... do you realy think such a simple fundamental 'issue' would not have been caught in the tests? Look at the api, you' ll see there are other methods to retrieve (unfinished) tasks and/or methods to check whether a task is finished or not.

          • 2. Re: A Bug or Newbie Error?
            gwzoller

            Easy, friend. :-) I didn't say this is necessarily a bug, although it could be. Fundamental bugs certainly can slip by testing of any software on occasion.

            I got these API calls from one of the tutorials. I'll go back and look for the others you mention, but that doesn't change my experience that these particular APIs didn't return the results semantically I expected. Therefore
            either I have an incomplete understanding of the use/function of these particular methods or there may be a bug.

            I'm hoping someone on the forum can either help me identify what I'm doing wrong or confirm that my results are not what is logically expected.

            Cheers,
            Greg

            • 3. Re: A Bug or Newbie Error?
              kukeltje

              At ease... indeed ;-) Fundamental bugs can slip by testing, fundamental functionality.... naahhhh.... :-)

              OK, so instead of you looking at the api, I did it (once, since it is a happy new year!!)

              The api docs say this:

               /**
               * returns all the taskInstances for the this process instance. This
               * includes task instances that have been completed previously.
               */
              


              and... surprise surprise... there is another method:

               /**
               * is the collection of {@link TaskInstance}s on the given token that are not ended.
               */
               public Collection getUnfinishedTasks(Token token) {
              
              


              So I not only confirmed (as in the previous post) that the results are indeed not as you expected, but gave a (more) detailed explanation.

              • 4. Re: A Bug or Newbie Error?
                gwzoller

                Fantastic! Many thanks!! This clears up my mystery and my erroneous functional expectation.

                Happy new year