5 Replies Latest reply on Mar 24, 2010 2:38 PM by swiderski.maciej

    working with executions

      Hi all,

       

      I've some trouble with Executions. Here is my process:

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <bpmn:definitions id="ServiceTaskJava"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 BPMN20.xsd"
          xmlns:bpmn="http://schema.omg.org/spec/BPMN/2.0" typeLanguage="http://www.w3.org/2001/XMLSchema"
          expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://sample.bpmn.camunda.com/"
          xmlns:jbpm="http://jbpm.org/4.0/bpmn2">
      
          <bpmn:process id="bar" name="my bar">
      
              <bpmn:startEvent id="s" />
      
              <bpmn:sequenceFlow id="f1" name="s_2_r1" sourceRef="s" targetRef="r1" />
      
              <bpmn:receiveTask id="r1" name="R1" />
              
              <bpmn:sequenceFlow id="f2" name="r1_2_e" sourceRef="r1" targetRef="e" />
      
              <bpmn:endEvent id="e" name="E" />
                  
          </bpmn:process>
      </bpmn:definitions>
      

       

      Here is the depending test:

       

       

      @Test
          public void oneReceiveNode(){
              //deploy process
              repositoryService.createDeployment().addResourceFromClasspath("one_receive_node.bpmn.xml").deploy();
              
              //start instance
              ProcessInstance instance = executionService.startProcessInstanceByKey("bar");
              Assert.assertNotNull(instance);
              
              //signal first execution
              Execution e1 = instance.findActiveExecutionIn("r1");
              Assert.assertNotNull(e1);
              executionService.signalExecutionById(e1.getId());
              
              Assert.assertTrue(instance.isEnded());
          }
      

       

      The last assert fails. Can anyone tell me why?

       

      Thanks in advance - Claus

       

      Nachricht geändert durch Claus Straube changed formatting...

        • 1. Re: working with executions
          swiderski.maciej

          Hi,

           

          In my opinion you should not signal when execution is in task. You should complete your task. To do so you use TaskQuery (constructed via TaskService) and once you find a task assigned for a user you can complete task using completeTask method on Task instance.

           

          Take a look at examples delivered with jBPM distribution regarding tasks.

           

          Cheers,

          Maciej

          • 2. Re: working with executions

            Hi Maciej,

             

            first: thanks for your response. In my understanding the TaskService is for human interaction. But that's not what I want to do. I want to finish a "BPMN 2.0 receiveTask". The documentation says this:

            Process execution will wait in such a receive task. The process can then be continued using the familiar jBPM signal methods. Note that this will probably change in the future, since a 'signal' has a completely different meaning in BPMN 2.0.

             

            As a code sample they provided this java snippet:

             

            Execution execution = processInstance.findActiveExecutionIn("receiveTask");
            executionService.signalExecutionById(execution.getId());
            

             

            This is the xml snippet:

             

            <receiveTask id="receiveTask" name="wait" /> 
            

             

            The documentation says, that I can continue the process if I "signal" it. So I don't want to assign a task to a user or something. So my question is still open.

             

            Best regards - Claus

            • 3. Re: working with executions
              swiderski.maciej

              I was expecting that you will respond like this I was about to put a comment that it my post was more related to regular jpdl than BPMN...but pressed the button too early.

               

              ok, perhaps the problem is that you reference old process instance?! signalExecution... method return processInstance object try your last assertion on that instead.

               

              Cheers,

              Maciej

              • 4. Re: working with executions

                Hi Maciej,

                 

                I think that's it. The following test worked:

                 

                 

                @Test
                    public void oneReceiveNode(){
                        //deploy process
                        repositoryService.createDeployment().addResourceFromClasspath("one_receive_node.bpmn.xml").deploy();
                        
                        //start instance
                        ProcessInstance instance = executionService.startProcessInstanceByKey("bar");
                        Assert.assertNotNull(instance);
                        
                        //signal first execution
                        Execution e1 = instance.findActiveExecutionIn("r1");
                        Assert.assertNotNull(e1);
                        ProcessInstance instance2 = executionService.signalExecutionById(e1.getId());
                        
                        Assert.assertTrue(instance2.isEnded());
                    }
                

                 

                That means a process instance will be "refreshed", if I do a execution on it? I don't find that intuitive... But okay -it works Thank you!

                 

                Best regards - Claus

                • 5. Re: working with executions
                  swiderski.maciej

                  Hi,

                   

                  glad I could help.

                   

                  Yes, the process instance will be reloaded since the execution was in wait state so process instance was persisted into data store, so the instance you had before is not valid any more.

                   

                  I agree that it is not so visible when working with unit tests.

                   

                  Cheers,

                  Maciej