AnsweredAssumed Answered

Issue Getting Signal Boundary Event to Trigger

Question asked by zhengzizhan on Aug 7, 2016
Hi all,

I've been working on a project using Activiti 6.0.0.Beta2, and I've run into an issue with signal boundary events attached to user tasks not triggering. I've searched and made adjustments to my code based on what other people on this forum have said worked for them, but unfortunately I'm still having the same issue. I've created a unit test in Java along with a corresponding BPMN diagram which I've included below to illustrate the problem. The BPMN diagram is as follows:

[img]http://i.imgur.com/0sEVmNy.png[/img]

The corresponding XML source code for the diagram follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:yaoqiang="http://bpmn.sourceforge.net" exporter="" exporterVersion="" expressionLanguage="http://www.w3.org/1999/XPath" id="m1452892595912" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL http://bpmn.sourceforge.net/schemas/BPMN20.xsd">
  <signal activiti:scope="processInstance" id="cancelSignal" name="Cancel Signal"/>
  <process id="signalTestProcess" isClosed="false" isExecutable="true" processType="None">
    <userTask completionQuantity="1" id="userTask" implementation="##unspecified" isForCompensation="false" name="User Task" startQuantity="1">
      <incoming>startFlow</incoming>
      <outgoing>normalEndFlow</outgoing>
    </userTask>
    <boundaryEvent attachedToRef="userTask" cancelActivity="true" id="cancelTask" name="Cancel Task" parallelMultiple="false">
      <outgoing>cancelFlow</outgoing>
      <outputSet/>
      <signalEventDefinition id="cancelTaskEvent" signalRef="cancelSignal"/>
    </boundaryEvent>
    <startEvent id="startEvent" isInterrupting="true" name="Start Event" parallelMultiple="false">
      <outgoing>startFlow</outgoing>
      <outputSet/>
    </startEvent>
    <sequenceFlow id="startFlow" sourceRef="startEvent" targetRef="userTask"/>
    <endEvent id="normalEndEvent" name="End Event">
      <incoming>normalEndFlow</incoming>
      <inputSet/>
    </endEvent>
    <sequenceFlow id="cancelFlow" sourceRef="cancelTask" targetRef="cancelEndEvent"/>
    <endEvent id="cancelEndEvent" name="End Event">
      <incoming>cancelFlow</incoming>
      <inputSet/>
    </endEvent>
    <sequenceFlow id="normalEndFlow" sourceRef="userTask" targetRef="normalEndEvent"/>
  </process>
</definitions>

The code for the unit test follows:

    runtimeService.startProcessInstanceByKey("signalTestProcess");

    Assert.assertEquals(1, runtimeService.createExecutionQuery().signalEventSubscriptionName("Cancel Signal").list().size());

    runtimeService.signalEventReceived("Cancel Signal",
      runtimeService.createExecutionQuery()
                    .signalEventSubscriptionName("Cancel Signal")
                    .singleResult()
                    .getId());

    println(historyService.createHistoricActivityInstanceQuery()
                          .unfinished()
                          .list()
                          .map(h => h.getActivityName)
                          .mkString("\n"));

    Assert.assertEquals(0, taskService.createTaskQuery().count());

When I run the unit test I get the error "java.lang.AssertionError: Expected :0 Actual :1" corresponding to the assertion in the last line. Also, the println function prints "User Task". These results seem to imply that after signalEventReceived is run, the execution remains at User Task instead of going down the signal boundary event flow. In terms of common issues with signal events that I've addressed in my code, the signal name (and not the signal id) is passed to signalEventReceived and the cancelActivity attribute for the signal boundary event is set to true. Also, as the first assertion passes successfully, I'm pretty certain that the correct execution id is being passed to signalEventReceived. If anyone could provide insight on why the execution still refuses to go down the signal boundary event flow I'd greatly appreciate it. Thanks!

Outcomes