diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/event/LocalInterruptingTimerBoundaryEventIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/event/LocalInterruptingTimerBoundaryEventIT.java index c5d380c0144..0328c7fa3bf 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/event/LocalInterruptingTimerBoundaryEventIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/event/LocalInterruptingTimerBoundaryEventIT.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.bonitasoft.engine.bpm.flownode.ActivityInstanceCriterion; import org.bonitasoft.engine.bpm.flownode.ArchivedActivityInstance; @@ -26,6 +27,7 @@ import org.bonitasoft.engine.bpm.process.ProcessInstance; import org.bonitasoft.engine.bpm.process.ProcessInstanceCriterion; import org.bonitasoft.engine.bpm.process.impl.ProcessDefinitionBuilder; +import org.bonitasoft.engine.bpm.process.impl.UserTaskDefinitionBuilder; import org.bonitasoft.engine.event.AbstractEventIT; import org.bonitasoft.engine.exception.BonitaRuntimeException; import org.bonitasoft.engine.expression.Expression; @@ -336,4 +338,41 @@ private ProcessDefinition deployAndEnableProcessWithCallActivity(final String pr return deployAndEnableProcessWithActor(processDefBuilder.done(), ACTOR_NAME, user); } + @Test + public void timerBoundaryEvent_should_not_trigger_and_be_deleted_at_flownode_abortion() throws Exception { + final int timerDuration = 20_000;//long enough not to trigger + SchedulerService schedulerService = getServiceAccessor().getSchedulerService(); + + final ProcessDefinitionBuilder processDefinitionBuilder = new ProcessDefinitionBuilder() + .createNewInstance("pTimerBoundary", "2.0"); + processDefinitionBuilder.addActor(ACTOR_NAME); + processDefinitionBuilder.addStartEvent("start"); + final UserTaskDefinitionBuilder userTaskDefinitionBuilder = processDefinitionBuilder.addUserTask("step1", + ACTOR_NAME); + userTaskDefinitionBuilder.addBoundaryEvent("Boundary timer").addTimerEventTriggerDefinition(TimerType.DURATION, + new ExpressionBuilder().createConstantLongExpression(timerDuration)); + userTaskDefinitionBuilder.addUserTask("exceptionStep", ACTOR_NAME); + processDefinitionBuilder.addUserTask("step2", ACTOR_NAME); + processDefinitionBuilder.addEndEvent("end").addTerminateEventTrigger(); + processDefinitionBuilder.addEndEvent("end2").addTerminateEventTrigger(); + processDefinitionBuilder.addTransition("start", "step1"); + processDefinitionBuilder.addTransition("start", "step2"); + processDefinitionBuilder.addTransition("step1", "end"); + processDefinitionBuilder.addTransition("step2", "end2"); + processDefinitionBuilder.addTransition("Boundary timer", "exceptionStep"); + processDefinitionBuilder.addTransition("exceptionStep", "end"); + + final ProcessDefinition processDefinition = deployAndEnableProcessWithActor(processDefinitionBuilder.done(), + ACTOR_NAME, user); + + final ProcessInstance processInstance = getProcessAPI().startProcess(processDefinition.getId()); + + waitForUserTask(processInstance.getId(), "step1"); + waitForUserTaskAssignAndExecuteIt(processInstance, "step2", user, Map.of()); + waitForProcessToFinish(processInstance); + List allJobs = schedulerService.getAllJobs(); + assertThat(allJobs).isEmpty(); + disableAndDeleteProcess(processDefinition); + } + } diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/BPMLocalIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/BPMLocalIT.java index 6392753ecac..5ac3ec03a69 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/BPMLocalIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/BPMLocalIT.java @@ -13,7 +13,6 @@ **/ package org.bonitasoft.engine.test; -import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.*; import java.io.File; @@ -37,11 +36,14 @@ import org.bonitasoft.engine.bpm.bar.BusinessArchive; import org.bonitasoft.engine.bpm.bar.BusinessArchiveBuilder; import org.bonitasoft.engine.bpm.connector.ConnectorEvent; -import org.bonitasoft.engine.bpm.flownode.*; +import org.bonitasoft.engine.bpm.flownode.ActivityExecutionException; +import org.bonitasoft.engine.bpm.flownode.ActivityInstanceNotFoundException; +import org.bonitasoft.engine.bpm.flownode.ActivityStates; +import org.bonitasoft.engine.bpm.flownode.FlowNodeInstance; +import org.bonitasoft.engine.bpm.flownode.FlowNodeInstanceSearchDescriptor; import org.bonitasoft.engine.bpm.process.ProcessDefinition; import org.bonitasoft.engine.bpm.process.ProcessInstance; import org.bonitasoft.engine.bpm.process.impl.ProcessDefinitionBuilder; -import org.bonitasoft.engine.bpm.process.impl.UserTaskDefinitionBuilder; import org.bonitasoft.engine.connectors.VariableStorage; import org.bonitasoft.engine.core.process.comment.api.SCommentService; import org.bonitasoft.engine.core.process.instance.api.ActivityInstanceService; @@ -57,7 +59,6 @@ import org.bonitasoft.engine.persistence.OrderByType; import org.bonitasoft.engine.persistence.QueryOptions; import org.bonitasoft.engine.platform.Platform; -import org.bonitasoft.engine.scheduler.SchedulerService; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.service.ServiceAccessor; @@ -547,41 +548,4 @@ public void should_warn_when_setting_remote_connection_with_local_engine() throw Assertions.assertThat(log).contains( "You are declaring an API access to Bonita Engine as a remote connection, whereas it looks like you are running in the same JVM."); } - - @Test - public void timerBoundaryEvent_should_not_trigger_and_be_deleted_at_flownode_execution() throws Exception { - final int timerDuration = 10000;//long enough not to trigger - SchedulerService schedulerService = getServiceAccessor().getSchedulerService(); - - final ProcessDefinitionBuilder processDefinitionBuilder = new ProcessDefinitionBuilder() - .createNewInstance("pTimerBoundary", "2.0"); - processDefinitionBuilder.addActor(ACTOR_NAME); - processDefinitionBuilder.addStartEvent("start"); - final UserTaskDefinitionBuilder userTaskDefinitionBuilder = processDefinitionBuilder.addUserTask("step1", - ACTOR_NAME); - userTaskDefinitionBuilder.addBoundaryEvent("Boundary timer").addTimerEventTriggerDefinition(TimerType.DURATION, - new ExpressionBuilder().createConstantLongExpression(timerDuration)); - userTaskDefinitionBuilder.addUserTask("exceptionStep", ACTOR_NAME); - userTaskDefinitionBuilder.addUserTask("step2", ACTOR_NAME); - processDefinitionBuilder.addEndEvent("end"); - processDefinitionBuilder.addTransition("start", "step1"); - processDefinitionBuilder.addTransition("step1", "step2"); - processDefinitionBuilder.addTransition("Boundary timer", "exceptionStep"); - processDefinitionBuilder.addTransition("exceptionStep", "end"); - - final ProcessDefinition processDefinition = deployAndEnableProcessWithActor(processDefinitionBuilder.done(), - ACTOR_NAME, john); - - final ProcessInstance processInstance = getProcessAPI().startProcess(processDefinition.getId()); - - waitForUserTaskAndExecuteIt(processInstance, "step1", john); - Thread.sleep(1000);//The work needs some time to finish - List allJobs = schedulerService.getAllJobs(); - assertThat(allJobs).isEmpty(); - waitForUserTaskAndExecuteIt(processInstance, "step2", john); - waitForProcessToFinish(processInstance); - - disableAndDeleteProcess(processDefinition); - } - } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/FlowNodeExecutorImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/FlowNodeExecutorImpl.java index cc69af8e925..61da65dbb73 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/FlowNodeExecutorImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/FlowNodeExecutorImpl.java @@ -16,9 +16,6 @@ import static org.bonitasoft.engine.classloader.ClassLoaderIdentifier.identifier; import static org.bonitasoft.engine.core.process.instance.model.SStateCategory.ABORTING; -import java.util.Collections; -import java.util.List; - import org.bonitasoft.engine.SArchivingException; import org.bonitasoft.engine.bpm.process.ProcessInstanceState; import org.bonitasoft.engine.builder.BuilderFactory; @@ -30,17 +27,13 @@ import org.bonitasoft.engine.core.process.definition.ProcessDefinitionService; import org.bonitasoft.engine.core.process.definition.exception.SProcessDefinitionNotFoundException; import org.bonitasoft.engine.core.process.definition.model.SProcessDefinition; -import org.bonitasoft.engine.core.process.definition.model.event.SBoundaryEventDefinition; -import org.bonitasoft.engine.core.process.definition.model.event.SCatchEventDefinition; import org.bonitasoft.engine.core.process.instance.api.ActivityInstanceService; -import org.bonitasoft.engine.core.process.instance.api.event.EventInstanceService; import org.bonitasoft.engine.core.process.instance.api.exceptions.SActivityExecutionException; import org.bonitasoft.engine.core.process.instance.api.exceptions.SActivityStateExecutionException; import org.bonitasoft.engine.core.process.instance.api.exceptions.SFlowNodeExecutionException; import org.bonitasoft.engine.core.process.instance.api.exceptions.SFlowNodeModificationException; import org.bonitasoft.engine.core.process.instance.api.exceptions.SFlowNodeNotFoundException; import org.bonitasoft.engine.core.process.instance.api.exceptions.SFlowNodeReadException; -import org.bonitasoft.engine.core.process.instance.api.exceptions.event.trigger.SEventTriggerInstanceDeletionException; import org.bonitasoft.engine.core.process.instance.api.states.FlowNodeState; import org.bonitasoft.engine.core.process.instance.api.states.StateCode; import org.bonitasoft.engine.core.process.instance.model.SActivityInstance; @@ -48,14 +41,11 @@ import org.bonitasoft.engine.core.process.instance.model.SFlowNodeInstance; import org.bonitasoft.engine.core.process.instance.model.SProcessInstance; import org.bonitasoft.engine.core.process.instance.model.builder.SUserTaskInstanceBuilderFactory; -import org.bonitasoft.engine.core.process.instance.model.event.SCatchEventInstance; import org.bonitasoft.engine.dependency.model.ScopeType; import org.bonitasoft.engine.execution.archive.BPMArchiverService; -import org.bonitasoft.engine.execution.job.JobNameBuilder; import org.bonitasoft.engine.execution.state.FlowNodeStateManager; import org.bonitasoft.engine.execution.work.BPMWorkFactory; -import org.bonitasoft.engine.persistence.*; -import org.bonitasoft.engine.scheduler.SchedulerService; +import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.work.SWorkRegisterException; import org.bonitasoft.engine.work.WorkService; import org.slf4j.Logger; @@ -85,8 +75,6 @@ public class FlowNodeExecutorImpl implements FlowNodeExecutor { private final BPMWorkFactory workFactory; private final ProcessInstanceInterruptor processInstanceInterruptor; private final BPMArchiverService bpmArchiverService; - private final EventInstanceService eventInstanceService; - private final SchedulerService schedulerService; public FlowNodeExecutorImpl(final FlowNodeStateManager flowNodeStateManager, final ActivityInstanceService activityInstanceManager, @@ -96,8 +84,7 @@ public FlowNodeExecutorImpl(final FlowNodeStateManager flowNodeStateManager, final ClassLoaderService classLoaderService, final WorkService workService, BPMWorkFactory workFactory, final ProcessInstanceInterruptor processInstanceInterruptor, - final BPMArchiverService bpmArchiverService, EventInstanceService eventInstanceService, - SchedulerService schedulerService) { + final BPMArchiverService bpmArchiverService) { this.flowNodeStateManager = flowNodeStateManager; activityInstanceService = activityInstanceManager; this.containerRegistry = containerRegistry; @@ -109,8 +96,6 @@ public FlowNodeExecutorImpl(final FlowNodeStateManager flowNodeStateManager, this.processDefinitionService = processDefinitionService; this.commentService = commentService; this.bpmArchiverService = bpmArchiverService; - this.eventInstanceService = eventInstanceService; - this.schedulerService = schedulerService; } @@ -297,7 +282,6 @@ public void childFinished(final long processDefinitionId, final long parentId, S final FlowNodeState state = flowNodeStateManager.getState(activityInstanceParent.getStateId()); final boolean shouldContinueParent = state.notifyChildFlowNodeHasFinished(sProcessDefinition, activityInstanceParent, childFlowNode); - deleteTimerJobsOnFlownode(childFlowNode); if (shouldContinueParent) { // it should never happen, because the terminal state never waits children to finish if (activityInstanceParent.isTerminal()) { @@ -311,58 +295,6 @@ public void childFinished(final long processDefinitionId, final long parentId, S } } - private void deleteTimerJobsOnFlownode(SFlowNodeInstance flowNodeInstance) - throws SProcessDefinitionNotFoundException, SBonitaReadException { - // We have no way of going from flownodeInst -> boundary timer of flownode, so we have to do a search - SProcessDefinition processDefinition = processDefinitionService - .getProcessDefinition(flowNodeInstance.getProcessDefinitionId()); - List processBoundaryEventDefinitions = processDefinition.getProcessContainer() - .getBoundaryEvents(); - for (SBoundaryEventDefinition sBoundaryEventDefinition : processBoundaryEventDefinitions) { - final List orderByOptions = Collections - .singletonList(new OrderByOption(SCatchEventInstance.class, "id", OrderByType.ASC)); - final FilterOption filterOption = new FilterOption(SCatchEventInstance.class, "activityInstanceId", - flowNodeInstance.getId()); - QueryOptions queryOptions = new QueryOptions(0, 100, orderByOptions, - Collections.singletonList(filterOption), null); - List sBoundaryEventInstances = activityInstanceService - .searchFlowNodeInstances(SCatchEventInstance.class, queryOptions); - for (SCatchEventInstance sCatchEventInstance : sBoundaryEventInstances) { - deleteJobsOnFlowNodeInstance(processDefinition, sBoundaryEventDefinition, sCatchEventInstance); - } - } - } - - private void deleteJobsOnFlowNodeInstance(final SProcessDefinition processDefinition, - final SCatchEventDefinition sCatchEventDefinition, - final SCatchEventInstance sCatchEventInstance) { - try { - if (!sCatchEventDefinition.getTimerEventTriggerDefinitions().isEmpty()) { - final String jobName = JobNameBuilder.getTimerEventJobName(processDefinition.getId(), - sCatchEventDefinition, sCatchEventInstance); - final boolean delete = schedulerService.delete(jobName); - try { - eventInstanceService.deleteEventTriggerInstanceOfFlowNode(sCatchEventInstance.getId()); - } catch (SEventTriggerInstanceDeletionException e) { - LOG.warn( - "Unable to delete event trigger of flow node instance {}: {}", sCatchEventInstance, - e.getMessage()); - } - if (!delete && schedulerService.isExistingJob(jobName)) { - LOG.warn( - "No job found with name '{}' when interrupting timer catch event named '{}' and id '{}'. It was probably already triggered.", - jobName, - sCatchEventDefinition.getName(), - sCatchEventInstance.getId()); - - } - } - } catch (final Exception e) { - LOG.error("An error occurred while deleting jobs attached to catch event instance '{}'.", - sCatchEventDefinition, e); - } - } - private void decrementToken(final SActivityInstance sActivityInstance) throws SFlowNodeModificationException { final int tokenCount = sActivityInstance.getTokenCount() - 1; activityInstanceService.setTokenCount(sActivityInstance, tokenCount); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/AbortingBoundaryAndIntermediateCatchEventState.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/AbortingBoundaryAndIntermediateCatchEventState.java index 7b4f65c0b3b..b488eef6d38 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/AbortingBoundaryAndIntermediateCatchEventState.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/AbortingBoundaryAndIntermediateCatchEventState.java @@ -19,7 +19,7 @@ import org.springframework.stereotype.Component; @Component -public class AbortingBoundaryAndIntermediateCatchEventState extends EndingIntermediateCatchEventExceptionState { +public class AbortingBoundaryAndIntermediateCatchEventState extends InterruptingBoundaryAndIntermediateCatchEventState { public AbortingBoundaryAndIntermediateCatchEventState(WaitingEventsInterrupter waitingEventsInterrupter) { super(waitingEventsInterrupter); @@ -47,7 +47,7 @@ public boolean mustAddSystemComment(final SFlowNodeInstance flowNodeInstance) { @Override public String getSystemComment(final SFlowNodeInstance flowNodeInstance) { - return "Aborting intermediate catch event"; + return "Aborting boundary or intermediate catch event"; } } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/CancellingBoundaryAndIntermediateCatchEventState.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/CancellingBoundaryAndIntermediateCatchEventState.java index 1190686fbf3..03d4b80da71 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/CancellingBoundaryAndIntermediateCatchEventState.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/CancellingBoundaryAndIntermediateCatchEventState.java @@ -20,7 +20,7 @@ @Component public class CancellingBoundaryAndIntermediateCatchEventState - extends EndingIntermediateCatchEventExceptionState { + extends InterruptingBoundaryAndIntermediateCatchEventState { public CancellingBoundaryAndIntermediateCatchEventState(WaitingEventsInterrupter waitingEventsInterrupter) { super(waitingEventsInterrupter); @@ -48,7 +48,7 @@ public boolean mustAddSystemComment(final SFlowNodeInstance flowNodeInstance) { @Override public String getSystemComment(final SFlowNodeInstance flowNodeInstance) { - return "Canceling intermediate catch event"; + return "Canceling boundary or intermediate catch event"; } } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/EndingIntermediateCatchEventExceptionState.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/InterruptingBoundaryAndIntermediateCatchEventState.java similarity index 87% rename from bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/EndingIntermediateCatchEventExceptionState.java rename to bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/InterruptingBoundaryAndIntermediateCatchEventState.java index b9e774f0a57..5c08dd4baa4 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/EndingIntermediateCatchEventExceptionState.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/state/InterruptingBoundaryAndIntermediateCatchEventState.java @@ -20,14 +20,14 @@ import org.bonitasoft.engine.core.process.instance.api.states.FlowNodeState; import org.bonitasoft.engine.core.process.instance.api.states.StateCode; import org.bonitasoft.engine.core.process.instance.model.SFlowNodeInstance; -import org.bonitasoft.engine.core.process.instance.model.event.SIntermediateCatchEventInstance; +import org.bonitasoft.engine.core.process.instance.model.event.SCatchEventInstance; import org.bonitasoft.engine.execution.WaitingEventsInterrupter; -public abstract class EndingIntermediateCatchEventExceptionState implements FlowNodeState { +public abstract class InterruptingBoundaryAndIntermediateCatchEventState implements FlowNodeState { private final WaitingEventsInterrupter waitingEventsInterrupter; - public EndingIntermediateCatchEventExceptionState(WaitingEventsInterrupter waitingEventsInterrupter) { + public InterruptingBoundaryAndIntermediateCatchEventState(WaitingEventsInterrupter waitingEventsInterrupter) { super(); this.waitingEventsInterrupter = waitingEventsInterrupter; } @@ -45,8 +45,8 @@ public StateCode execute(final SProcessDefinition processDefinition, final SFlow .getFlowNode( instance.getFlowNodeDefinitionId()); try { - final SIntermediateCatchEventInstance intermediateCatchEventInstance = (SIntermediateCatchEventInstance) instance; - waitingEventsInterrupter.interruptWaitingEvents(processDefinition, intermediateCatchEventInstance, + final SCatchEventInstance catchEventInstance = (SCatchEventInstance) instance; + waitingEventsInterrupter.interruptWaitingEvents(processDefinition, catchEventInstance, catchEventDef); } catch (final SBonitaException e) { throw new SActivityStateExecutionException(e); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/transition/BoundaryEventStates.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/transition/BoundaryEventStates.java index 4b71e67f65f..fee758da9a0 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/transition/BoundaryEventStates.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/transition/BoundaryEventStates.java @@ -14,12 +14,7 @@ package org.bonitasoft.engine.execution.transition; import org.bonitasoft.engine.core.process.definition.model.SFlowNodeType; -import org.bonitasoft.engine.execution.state.AbortedFlowNodeState; -import org.bonitasoft.engine.execution.state.CancelledFlowNodeState; -import org.bonitasoft.engine.execution.state.CompletedActivityState; -import org.bonitasoft.engine.execution.state.ExecutingBoundaryEventState; -import org.bonitasoft.engine.execution.state.InitializingBoundaryEventState; -import org.bonitasoft.engine.execution.state.WaitingFlowNodeState; +import org.bonitasoft.engine.execution.state.*; import org.springframework.stereotype.Component; @Component @@ -30,15 +25,17 @@ public SFlowNodeType getFlowNodeType() { } public BoundaryEventStates(CompletedActivityState completed, + AbortingBoundaryAndIntermediateCatchEventState aborting, AbortedFlowNodeState aborted, + CancellingBoundaryAndIntermediateCatchEventState cancelling, CancelledFlowNodeState cancelled, WaitingFlowNodeState waiting, InitializingBoundaryEventState initializingBoundaryEvent, ExecutingBoundaryEventState executingBoundaryEvent) { defineNormalSequence(initializingBoundaryEvent, waiting, executingBoundaryEvent, completed); - defineAbortSequence(aborted); - defineCancelSequence(cancelled); + defineAbortSequence(aborting, aborted); + defineCancelSequence(cancelling, cancelled); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/FlowNodeExecutorImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/FlowNodeExecutorImplTest.java index f749d84e510..c60ea4deecd 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/FlowNodeExecutorImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/FlowNodeExecutorImplTest.java @@ -20,7 +20,6 @@ import org.bonitasoft.engine.archive.ArchiveService; import org.bonitasoft.engine.core.process.definition.ProcessDefinitionService; import org.bonitasoft.engine.core.process.instance.api.ActivityInstanceService; -import org.bonitasoft.engine.core.process.instance.api.event.EventInstanceService; import org.bonitasoft.engine.core.process.instance.api.exceptions.SFlowNodeNotFoundException; import org.bonitasoft.engine.core.process.instance.api.exceptions.SFlowNodeReadException; import org.bonitasoft.engine.core.process.instance.model.SUserTaskInstance; @@ -28,7 +27,6 @@ import org.bonitasoft.engine.execution.state.FlowNodeStateManager; import org.bonitasoft.engine.execution.state.SkippedFlowNodeState; import org.bonitasoft.engine.execution.work.BPMWorkFactory; -import org.bonitasoft.engine.scheduler.SchedulerService; import org.bonitasoft.engine.work.WorkDescriptor; import org.bonitasoft.engine.work.WorkService; import org.junit.Before; @@ -65,10 +63,6 @@ public class FlowNodeExecutorImplTest { private StateBehaviors stateBehaviors; @Mock BPMArchiverService bpmArchiverService; - @Mock - EventInstanceService eventInstanceService; - @Mock - SchedulerService schedulerService; @Captor private ArgumentCaptor workDescriptorArgumentCaptor; private FlowNodeExecutorImpl flowNodeExecutor; @@ -78,7 +72,7 @@ public class FlowNodeExecutorImplTest { public void before() throws Exception { flowNodeExecutor = new FlowNodeExecutorImpl(flowNodeStateManager, activityInstanceService, containerRegistry, processDefinitionService, null, null, workService, workFactory, - processInstanceInterruptor, bpmArchiverService, eventInstanceService, schedulerService); + processInstanceInterruptor, bpmArchiverService); skippedFlowNodeState = new SkippedFlowNodeState(); doReturn(skippedFlowNodeState).when(flowNodeStateManager).getState(SkippedFlowNodeState.ID); doReturn(stateBehaviors).when(flowNodeStateManager).getStateBehaviors(); diff --git a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/event/impl/EventInstanceServiceImpl.java b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/event/impl/EventInstanceServiceImpl.java index dc024048c04..ad843fdb06f 100644 --- a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/event/impl/EventInstanceServiceImpl.java +++ b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/event/impl/EventInstanceServiceImpl.java @@ -58,7 +58,7 @@ public class EventInstanceServiceImpl implements EventInstanceService { public static final String BONITA_BPMENGINE_MESSAGE_SENT = "bonita.bpmengine.message.sent"; private final Counter messageSentCounter; - private final EventInstanceRepository eventInstanceRepository; + private EventInstanceRepository eventInstanceRepository; public EventInstanceServiceImpl(EventInstanceRepository eventInstanceRepository, DataInstanceService dataInstanceService, MeterRegistry meterRegistry, Long tenantId) { @@ -99,11 +99,12 @@ public void deleteEventTriggerInstance(STimerEventTriggerInstance sTimerEventTri @Override public void deleteEventTriggerInstanceOfFlowNode(long flowNodeInstanceId) throws SBonitaReadException, SEventTriggerInstanceDeletionException { - var timerEventTriggerInstanceOfFlowNode = getTimerEventTriggerInstanceOfFlowNode( - flowNodeInstanceId).orElse(null); - if (timerEventTriggerInstanceOfFlowNode != null) { - deleteEventTriggerInstance(timerEventTriggerInstanceOfFlowNode); + Optional timerEventTriggerInstanceOfFlowNode = getTimerEventTriggerInstanceOfFlowNode( + flowNodeInstanceId); + if (!timerEventTriggerInstanceOfFlowNode.isPresent()) { + return; } + deleteEventTriggerInstance(timerEventTriggerInstanceOfFlowNode.get()); } @Override @@ -113,11 +114,6 @@ public void deleteMessageInstance(SMessageInstance messageInstance) throws SMess @Override public void deleteWaitingEvent(SWaitingEvent sWaitingEvent) throws SWaitingEventModificationException { - try { - deleteEventTriggerInstanceOfFlowNode(sWaitingEvent.getId()); - } catch (SBonitaReadException | SEventTriggerInstanceDeletionException e) { - throw new SWaitingEventModificationException(e); - } this.eventInstanceRepository.deleteWaitingEvent(sWaitingEvent); } @@ -268,7 +264,7 @@ public Integer deleteMessageAndDataInstanceOlderThanCreationDate(long creationDa try { List messageInstanceIdOlderThanCreationDate = eventInstanceRepository .getMessageInstanceIdOlderThanCreationDate(creationDate, queryOptions); - if (!messageInstanceIdOlderThanCreationDate.isEmpty()) { + if (messageInstanceIdOlderThanCreationDate.size() > 0) { eventInstanceRepository.deleteMessageInstanceByIds(messageInstanceIdOlderThanCreationDate); for (Long messageId : messageInstanceIdOlderThanCreationDate) { dataInstanceService.deleteLocalDataInstances(messageId, diff --git a/bpm/bonita-core/bonita-process-instance/src/test/java/org/bonitasoft/engine/core/process/instance/event/impl/EventInstanceServiceImplForWaitingTest.java b/bpm/bonita-core/bonita-process-instance/src/test/java/org/bonitasoft/engine/core/process/instance/event/impl/EventInstanceServiceImplForWaitingTest.java index 6df23f8753c..8c5ff812395 100644 --- a/bpm/bonita-core/bonita-process-instance/src/test/java/org/bonitasoft/engine/core/process/instance/event/impl/EventInstanceServiceImplForWaitingTest.java +++ b/bpm/bonita-core/bonita-process-instance/src/test/java/org/bonitasoft/engine/core/process/instance/event/impl/EventInstanceServiceImplForWaitingTest.java @@ -52,19 +52,20 @@ public void setUp() { } @Test - public final void deleteWaitingEvents_should_delete_waiting_events_and_associated_timers() throws Exception { + public final void deleteWaitingEvents_should_delete_waiting_events() throws Exception { // Given final SIntermediateCatchEventInstance sIntermediateCatchEventInstance = new SIntermediateCatchEventInstance(); final SWaitingMessageEvent waitingMessageEventImpl = new SWaitingMessageEvent(); - doReturn(Collections.singletonList(waitingMessageEventImpl)) + doReturn(Collections.singletonList(waitingMessageEventImpl)).doReturn(Collections.emptyList()) .when(instanceRepository) .getWaitingEventsForFlowNodeId(anyLong()); + doNothing().when(eventInstanceServiceImpl).deleteWaitingEvent(waitingMessageEventImpl); + // When eventInstanceServiceImpl.deleteWaitingEvents(sIntermediateCatchEventInstance); // Then verify(eventInstanceServiceImpl).deleteWaitingEvent(waitingMessageEventImpl); - verify(eventInstanceServiceImpl).deleteEventTriggerInstanceOfFlowNode(waitingMessageEventImpl.getId()); } @Test(expected = SWaitingEventModificationException.class)