diff --git a/distro/jbossas7/subsystem/src/main/java/org/camunda/bpm/container/impl/jboss/config/ManagedJtaProcessEngineConfiguration.java b/distro/jbossas7/subsystem/src/main/java/org/camunda/bpm/container/impl/jboss/config/ManagedJtaProcessEngineConfiguration.java index ccfea73be42..f8db41b6499 100644 --- a/distro/jbossas7/subsystem/src/main/java/org/camunda/bpm/container/impl/jboss/config/ManagedJtaProcessEngineConfiguration.java +++ b/distro/jbossas7/subsystem/src/main/java/org/camunda/bpm/container/impl/jboss/config/ManagedJtaProcessEngineConfiguration.java @@ -16,9 +16,9 @@ import java.util.List; import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener; -import org.camunda.bpm.engine.impl.bpmn.parser.FoxFailedJobParseListener; +import org.camunda.bpm.engine.impl.bpmn.parser.DefaultFailedJobParseListener; import org.camunda.bpm.engine.impl.cfg.JtaProcessEngineConfiguration; -import org.camunda.bpm.engine.impl.jobexecutor.FoxFailedJobCommandFactory; +import org.camunda.bpm.engine.impl.jobexecutor.DefaultFailedJobCommandFactory; import org.camunda.bpm.engine.impl.persistence.StrongUuidGenerator; /** @@ -47,9 +47,9 @@ protected void initCustomJobRetryStrategy() { customPostBPMNParseListeners = new ArrayList(); setCustomPostBPMNParseListeners(customPostBPMNParseListeners); } - customPostBPMNParseListeners.add(new FoxFailedJobParseListener()); + customPostBPMNParseListeners.add(new DefaultFailedJobParseListener()); - setFailedJobCommandFactory(new FoxFailedJobCommandFactory()); + setFailedJobCommandFactory(new DefaultFailedJobCommandFactory()); } protected void initIdGenerator() { diff --git a/distro/jbossas7/webapp-standalone/src/main/webapp/WEB-INF/applicationContext.xml b/distro/jbossas7/webapp-standalone/src/main/webapp/WEB-INF/applicationContext.xml index 1ff7d32ff82..c39d1251360 100644 --- a/distro/jbossas7/webapp-standalone/src/main/webapp/WEB-INF/applicationContext.xml +++ b/distro/jbossas7/webapp-standalone/src/main/webapp/WEB-INF/applicationContext.xml @@ -29,9 +29,6 @@ - - - diff --git a/distro/tomcat/webapp-standalone/src/main/webapp/WEB-INF/applicationContext.xml b/distro/tomcat/webapp-standalone/src/main/webapp/WEB-INF/applicationContext.xml index 1ff7d32ff82..c39d1251360 100644 --- a/distro/tomcat/webapp-standalone/src/main/webapp/WEB-INF/applicationContext.xml +++ b/distro/tomcat/webapp-standalone/src/main/webapp/WEB-INF/applicationContext.xml @@ -29,9 +29,6 @@ - - - diff --git a/distro/wildfly/subsystem/src/main/java/org/camunda/bpm/container/impl/jboss/config/ManagedJtaProcessEngineConfiguration.java b/distro/wildfly/subsystem/src/main/java/org/camunda/bpm/container/impl/jboss/config/ManagedJtaProcessEngineConfiguration.java index ccfea73be42..f8db41b6499 100644 --- a/distro/wildfly/subsystem/src/main/java/org/camunda/bpm/container/impl/jboss/config/ManagedJtaProcessEngineConfiguration.java +++ b/distro/wildfly/subsystem/src/main/java/org/camunda/bpm/container/impl/jboss/config/ManagedJtaProcessEngineConfiguration.java @@ -16,9 +16,9 @@ import java.util.List; import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener; -import org.camunda.bpm.engine.impl.bpmn.parser.FoxFailedJobParseListener; +import org.camunda.bpm.engine.impl.bpmn.parser.DefaultFailedJobParseListener; import org.camunda.bpm.engine.impl.cfg.JtaProcessEngineConfiguration; -import org.camunda.bpm.engine.impl.jobexecutor.FoxFailedJobCommandFactory; +import org.camunda.bpm.engine.impl.jobexecutor.DefaultFailedJobCommandFactory; import org.camunda.bpm.engine.impl.persistence.StrongUuidGenerator; /** @@ -47,9 +47,9 @@ protected void initCustomJobRetryStrategy() { customPostBPMNParseListeners = new ArrayList(); setCustomPostBPMNParseListeners(customPostBPMNParseListeners); } - customPostBPMNParseListeners.add(new FoxFailedJobParseListener()); + customPostBPMNParseListeners.add(new DefaultFailedJobParseListener()); - setFailedJobCommandFactory(new FoxFailedJobCommandFactory()); + setFailedJobCommandFactory(new DefaultFailedJobCommandFactory()); } protected void initIdGenerator() { diff --git a/engine-plugins/spin-plugin/src/test/resources/camunda.cfg.xml b/engine-plugins/spin-plugin/src/test/resources/camunda.cfg.xml index fd8bea40d07..aee1c41b229 100644 --- a/engine-plugins/spin-plugin/src/test/resources/camunda.cfg.xml +++ b/engine-plugins/spin-plugin/src/test/resources/camunda.cfg.xml @@ -19,15 +19,7 @@ - - - - - - - - @@ -35,8 +27,6 @@ - - diff --git a/engine-spring/src/test/resources/org/camunda/bpm/engine/spring/test/transaction/ProcessInstanceModificationInTransactionTest-applicationContext.xml b/engine-spring/src/test/resources/org/camunda/bpm/engine/spring/test/transaction/ProcessInstanceModificationInTransactionTest-applicationContext.xml index 5a64c3f808c..21e0ef7ad35 100644 --- a/engine-spring/src/test/resources/org/camunda/bpm/engine/spring/test/transaction/ProcessInstanceModificationInTransactionTest-applicationContext.xml +++ b/engine-spring/src/test/resources/org/camunda/bpm/engine/spring/test/transaction/ProcessInstanceModificationInTransactionTest-applicationContext.xml @@ -28,14 +28,6 @@ - - - - - - - - @@ -58,8 +50,6 @@ - - diff --git a/engine-spring/src/test/resources/org/camunda/bpm/engine/spring/test/transaction/SpringTransactionIntegrationTest-context.xml b/engine-spring/src/test/resources/org/camunda/bpm/engine/spring/test/transaction/SpringTransactionIntegrationTest-context.xml index 04762e47289..1bef48b7c62 100644 --- a/engine-spring/src/test/resources/org/camunda/bpm/engine/spring/test/transaction/SpringTransactionIntegrationTest-context.xml +++ b/engine-spring/src/test/resources/org/camunda/bpm/engine/spring/test/transaction/SpringTransactionIntegrationTest-context.xml @@ -27,17 +27,8 @@ - - - - - - - - - diff --git a/engine/src/main/java/org/camunda/bpm/container/impl/deployment/StartProcessEngineStep.java b/engine/src/main/java/org/camunda/bpm/container/impl/deployment/StartProcessEngineStep.java index 3e801b0bcff..a68feccf7a7 100644 --- a/engine/src/main/java/org/camunda/bpm/container/impl/deployment/StartProcessEngineStep.java +++ b/engine/src/main/java/org/camunda/bpm/container/impl/deployment/StartProcessEngineStep.java @@ -12,8 +12,6 @@ */ package org.camunda.bpm.container.impl.deployment; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import org.camunda.bpm.application.AbstractProcessApplication; @@ -28,12 +26,9 @@ import org.camunda.bpm.container.impl.spi.PlatformServiceContainer; import org.camunda.bpm.container.impl.spi.ServiceTypes; import org.camunda.bpm.engine.impl.ProcessEngineLogger; -import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener; -import org.camunda.bpm.engine.impl.bpmn.parser.FoxFailedJobParseListener; import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin; import org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration; -import org.camunda.bpm.engine.impl.jobexecutor.FoxFailedJobCommandFactory; import org.camunda.bpm.engine.impl.jobexecutor.JobExecutor; import org.camunda.bpm.engine.impl.persistence.StrongUuidGenerator; import org.camunda.bpm.engine.impl.util.ReflectUtil; @@ -89,8 +84,6 @@ public void performOperationStep(DeploymentOperation operationContext) { ProcessEngineConfigurationImpl configurationImpl = configuration; configurationImpl.setIdGenerator(new StrongUuidGenerator()); - configureCustomRetryStrategy(configurationImpl); - // set configuration values String name = processEngineXml.getName(); configuration.setProcessEngineName(name); @@ -130,18 +123,6 @@ protected JmxManagedProcessEngineController createProcessEngineControllerInstanc return new JmxManagedProcessEngineController(configuration); } - protected void configureCustomRetryStrategy(ProcessEngineConfigurationImpl configurationImpl) { - // add support for custom Retry strategy - // TODO: decide whether this should be moved to configuration or to plugin - List customPostBPMNParseListeners = configurationImpl.getCustomPostBPMNParseListeners(); - if(customPostBPMNParseListeners==null) { - customPostBPMNParseListeners = new ArrayList(); - configurationImpl.setCustomPostBPMNParseListeners(customPostBPMNParseListeners); - } - customPostBPMNParseListeners.add(new FoxFailedJobParseListener()); - configurationImpl.setFailedJobCommandFactory(new FoxFailedJobCommandFactory()); - } - /** *

Instantiates and applies all {@link ProcessEnginePlugin}s defined in the processEngineXml */ diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/parser/FoxFailedJobParseListener.java b/engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/parser/DefaultFailedJobParseListener.java similarity index 98% rename from engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/parser/FoxFailedJobParseListener.java rename to engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/parser/DefaultFailedJobParseListener.java index a0f1f59350c..46bc5c12d7a 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/parser/FoxFailedJobParseListener.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/parser/DefaultFailedJobParseListener.java @@ -23,7 +23,7 @@ import org.camunda.bpm.engine.impl.util.xml.Element; import org.camunda.bpm.engine.impl.util.xml.Namespace; -public class FoxFailedJobParseListener extends AbstractBpmnParseListener { +public class DefaultFailedJobParseListener extends AbstractBpmnParseListener { protected static final String TYPE = "type"; protected static final String START_TIMER_EVENT = "startTimerEvent"; diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/cfg/ProcessEngineConfigurationImpl.java b/engine/src/main/java/org/camunda/bpm/engine/impl/cfg/ProcessEngineConfigurationImpl.java index 8814af5ca5c..d4f46567d1d 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/cfg/ProcessEngineConfigurationImpl.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/cfg/ProcessEngineConfigurationImpl.java @@ -99,6 +99,7 @@ import org.camunda.bpm.engine.impl.bpmn.deployer.BpmnDeployer; import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener; import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParser; +import org.camunda.bpm.engine.impl.bpmn.parser.DefaultFailedJobParseListener; import org.camunda.bpm.engine.impl.calendar.BusinessCalendarManager; import org.camunda.bpm.engine.impl.calendar.CycleBusinessCalendar; import org.camunda.bpm.engine.impl.calendar.DueDateBusinessCalendar; @@ -187,10 +188,10 @@ import org.camunda.bpm.engine.impl.interceptor.DelegateInterceptor; import org.camunda.bpm.engine.impl.interceptor.SessionFactory; import org.camunda.bpm.engine.impl.jobexecutor.AsyncContinuationJobHandler; -import org.camunda.bpm.engine.impl.jobexecutor.DefaultFailedJobCommandFactory; import org.camunda.bpm.engine.impl.jobexecutor.DefaultJobExecutor; import org.camunda.bpm.engine.impl.jobexecutor.DefaultJobPriorityProvider; import org.camunda.bpm.engine.impl.jobexecutor.FailedJobCommandFactory; +import org.camunda.bpm.engine.impl.jobexecutor.DefaultFailedJobCommandFactory; import org.camunda.bpm.engine.impl.jobexecutor.JobDeclaration; import org.camunda.bpm.engine.impl.jobexecutor.JobExecutor; import org.camunda.bpm.engine.impl.jobexecutor.JobHandler; @@ -709,6 +710,8 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig private int failedJobListenerMaxRetries = DEFAULT_FAILED_JOB_LISTENER_MAX_RETRIES; + private String failedJobRetryTimeCycle; + // buildProcessEngine /////////////////////////////////////////////////////// @Override @@ -743,6 +746,7 @@ protected void init() { initCommandExecutors(); initServices(); initIdGenerator(); + initFailedJobCommandFactory(); initDeployers(); initJobProvider(); initExternalTaskPriorityProvider(); @@ -758,7 +762,6 @@ protected void init() { initJpa(); initDelegateInterceptor(); initEventHandlers(); - initFailedJobCommandFactory(); initProcessApplicationManager(); initCorrelationHandler(); initIncidentHandlers(); @@ -872,6 +875,10 @@ protected void initFailedJobCommandFactory() { if (failedJobCommandFactory == null) { failedJobCommandFactory = new DefaultFailedJobCommandFactory(); } + if (postParseListeners == null) { + postParseListeners = new ArrayList(); + } + postParseListeners.add(new DefaultFailedJobParseListener()); } // incident handlers ///////////////////////////////////////////////////////////// @@ -3797,4 +3804,12 @@ public int getFailedJobListenerMaxRetries() { public void setFailedJobListenerMaxRetries(int failedJobListenerMaxRetries) { this.failedJobListenerMaxRetries = failedJobListenerMaxRetries; } + + public String getFailedJobRetryTimeCycle() { + return failedJobRetryTimeCycle; + } + + public void setFailedJobRetryTimeCycle(String failedJobRetryTimeCycle) { + this.failedJobRetryTimeCycle = failedJobRetryTimeCycle; + } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/FoxJobRetryCmd.java b/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/DefaultJobRetryCmd.java similarity index 83% rename from engine/src/main/java/org/camunda/bpm/engine/impl/cmd/FoxJobRetryCmd.java rename to engine/src/main/java/org/camunda/bpm/engine/impl/cmd/DefaultJobRetryCmd.java index 44ea88ba031..13ab9526487 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/FoxJobRetryCmd.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/DefaultJobRetryCmd.java @@ -13,7 +13,7 @@ package org.camunda.bpm.engine.impl.cmd; import org.camunda.bpm.engine.impl.ProcessEngineLogger; -import org.camunda.bpm.engine.impl.bpmn.parser.FoxFailedJobParseListener; +import org.camunda.bpm.engine.impl.bpmn.parser.DefaultFailedJobParseListener; import org.camunda.bpm.engine.impl.calendar.DurationHelper; import org.camunda.bpm.engine.impl.context.Context; import org.camunda.bpm.engine.impl.el.Expression; @@ -31,7 +31,7 @@ /** * @author Roman Smirnov */ -public class FoxJobRetryCmd extends JobRetryCmd { +public class DefaultJobRetryCmd extends JobRetryCmd { public static final List SUPPORTED_TYPES = Arrays.asList( TimerExecuteNestedActivityJobHandler.TYPE, @@ -42,7 +42,7 @@ public class FoxJobRetryCmd extends JobRetryCmd { ); private final static JobExecutorLogger LOG = ProcessEngineLogger.JOB_EXECUTOR_LOGGER; - public FoxJobRetryCmd(String jobId, Throwable exception) { + public DefaultJobRetryCmd(String jobId, Throwable exception) { super(jobId, exception); } @@ -50,14 +50,15 @@ public Object execute(CommandContext commandContext) { JobEntity job = getJob(); ActivityImpl activity = getCurrentActivity(commandContext, job); + String globalFailedJobRetryTimeCycle = commandContext.getProcessEngineConfiguration().getFailedJobRetryTimeCycle(); - if (activity == null) { + if (activity == null && globalFailedJobRetryTimeCycle == null) { LOG.debugFallbackToDefaultRetryStrategy(); executeStandardStrategy(commandContext); } else { try { - executeCustomStrategy(commandContext, job, activity); + executeCustomStrategy(commandContext, job, activity, globalFailedJobRetryTimeCycle); } catch (Exception e) { LOG.debugFallbackToDefaultRetryStrategy(); @@ -73,10 +74,17 @@ protected void executeStandardStrategy(CommandContext commandContext) { decrementCmd.execute(commandContext); } - protected void executeCustomStrategy(CommandContext commandContext, JobEntity job, ActivityImpl activity) throws Exception { - String failedJobRetryTimeCycle = getFailedJobRetryTimeCycle(job, activity); + protected void executeCustomStrategy(CommandContext commandContext, JobEntity job, ActivityImpl activity, String globalFailedJobRetryTimeCycle) throws Exception { + String failedJobRetryTimeCycle = null; + if (activity != null) { + failedJobRetryTimeCycle = getFailedJobRetryTimeCycle(job, activity); + } + + if (failedJobRetryTimeCycle == null && globalFailedJobRetryTimeCycle != null) { + failedJobRetryTimeCycle = globalFailedJobRetryTimeCycle; + } - if(failedJobRetryTimeCycle == null) { + if (failedJobRetryTimeCycle == null) { executeStandardStrategy(commandContext); } else { @@ -123,7 +131,7 @@ protected ExecutionEntity fetchExecutionEntity(String executionId) { protected String getFailedJobRetryTimeCycle(JobEntity job, ActivityImpl activity) { - Expression expression = activity.getProperties().get(FoxFailedJobParseListener.FOX_FAILED_JOB_CONFIGURATION); + Expression expression = activity.getProperties().get(DefaultFailedJobParseListener.FOX_FAILED_JOB_CONFIGURATION); String executionId = job.getExecutionId(); ExecutionEntity execution = null; @@ -134,6 +142,10 @@ protected String getFailedJobRetryTimeCycle(JobEntity job, ActivityImpl activity Object value = null; + if (expression == null) { + return null; + } + try { value = expression.getValue(execution); } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/DefaultFailedJobCommandFactory.java b/engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/DefaultFailedJobCommandFactory.java index 197d1029346..c63b143c665 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/DefaultFailedJobCommandFactory.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/DefaultFailedJobCommandFactory.java @@ -12,14 +12,14 @@ */ package org.camunda.bpm.engine.impl.jobexecutor; -import org.camunda.bpm.engine.impl.cmd.DecrementJobRetriesCmd; +import org.camunda.bpm.engine.impl.cmd.DefaultJobRetryCmd; import org.camunda.bpm.engine.impl.interceptor.Command; public class DefaultFailedJobCommandFactory implements FailedJobCommandFactory { public Command getCommand(String jobId, Throwable exception) { - return new DecrementJobRetriesCmd(jobId, exception); + return new DefaultJobRetryCmd(jobId, exception); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/FoxFailedJobCommandFactory.java b/engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/FoxFailedJobCommandFactory.java deleted file mode 100644 index 2ce8e779e7c..00000000000 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/FoxFailedJobCommandFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -/* Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.camunda.bpm.engine.impl.jobexecutor; - -import org.camunda.bpm.engine.impl.cmd.FoxJobRetryCmd; -import org.camunda.bpm.engine.impl.interceptor.Command; - - -public class FoxFailedJobCommandFactory implements FailedJobCommandFactory { - - public Command getCommand(String jobId, Throwable exception) { - return new FoxJobRetryCmd(jobId, exception); - } - -} diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/bpmn/parse/FoxFailedJobParseListenerTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/bpmn/parse/FoxFailedJobParseListenerTest.java index 3a6709594f5..74d22aa0cf0 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/bpmn/parse/FoxFailedJobParseListenerTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/bpmn/parse/FoxFailedJobParseListenerTest.java @@ -9,7 +9,7 @@ import org.camunda.bpm.engine.runtime.ProcessInstance; import org.camunda.bpm.engine.test.Deployment; -import static org.camunda.bpm.engine.impl.bpmn.parser.FoxFailedJobParseListener.FOX_FAILED_JOB_CONFIGURATION; +import static org.camunda.bpm.engine.impl.bpmn.parser.DefaultFailedJobParseListener.FOX_FAILED_JOB_CONFIGURATION; public class FoxFailedJobParseListenerTest extends PluggableProcessEngineTestCase { diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/bpmn/parse/GlobalRetryConfigurationTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/bpmn/parse/GlobalRetryConfigurationTest.java new file mode 100644 index 00000000000..598309b668b --- /dev/null +++ b/engine/src/test/java/org/camunda/bpm/engine/test/bpmn/parse/GlobalRetryConfigurationTest.java @@ -0,0 +1,264 @@ +/* Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.camunda.bpm.engine.test.bpmn.parse; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import org.camunda.bpm.engine.ManagementService; +import org.camunda.bpm.engine.ProcessEngineConfiguration; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; +import org.camunda.bpm.engine.repository.Deployment; +import org.camunda.bpm.engine.runtime.Job; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.camunda.bpm.engine.test.util.ProcessEngineBootstrapRule; +import org.camunda.bpm.engine.test.util.ProcessEngineTestRule; +import org.camunda.bpm.engine.test.util.ProvidedProcessEngineRule; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.RuleChain; + +public class GlobalRetryConfigurationTest { + + private static final String PROCESS_ID = "process"; + private static final String FAILING_CLASS = "this.class.does.not.Exist"; + private static final String FAILING_EVENT = "failingEvent"; + private static final String SCHEDULE = "R5/PT5M"; + private static final int JOB_RETRIES = 4; + + public ProcessEngineBootstrapRule bootstrapRule = new ProcessEngineBootstrapRule() { + public ProcessEngineConfiguration configureEngine(ProcessEngineConfigurationImpl configuration) { + configuration.setFailedJobRetryTimeCycle(SCHEDULE); + return configuration; + } + }; + + public ProvidedProcessEngineRule engineRule = new ProvidedProcessEngineRule(bootstrapRule); + public ProcessEngineTestRule testRule = new ProcessEngineTestRule(engineRule); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Rule + public RuleChain ruleChain = RuleChain.outerRule(bootstrapRule).around(engineRule).around(testRule); + + private Deployment currentDeployment; + private RuntimeService runtimeService; + private ManagementService managementService; + + @Before + public void setUp() { + BpmnModelInstance instance = prepareSignalEventProcessWithoutRetry(); + currentDeployment = testRule.deploy(instance); + runtimeService = engineRule.getRuntimeService(); + managementService = engineRule.getManagementService(); + } + + @After + public void tearDown() { + engineRule.getRepositoryService().deleteDeployment(currentDeployment.getId(), true, true); + } + + @Test + public void testFailedIntermediateThrowingSignalEventAsync() { + BpmnModelInstance bpmnModelInstance = prepareSignalEventProcessWithoutRetry(); + + currentDeployment = testRule.deploy(bpmnModelInstance); + ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); + assertJobRetries(pi, 4); + } + + @Test + public void testFailedServiceTask() { + BpmnModelInstance bpmnModelInstance = prepareFailingServiceTask(); + + currentDeployment = testRule.deploy(bpmnModelInstance); + + ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); + + assertJobRetries(pi, 4); + } + + @Test + public void testFailedServiceTaskMixConfiguration() { + BpmnModelInstance bpmnModelInstance = prepareFailingServiceTaskWithRetryCycle(); + + currentDeployment = testRule.deploy(bpmnModelInstance); + + ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); + + assertJobRetries(pi, 9); + } + + @Test + public void testFailedBusinessRuleTask() { + BpmnModelInstance bpmnModelInstance = prepareFailingBusinessRuleTask(); + + currentDeployment = testRule.deploy(bpmnModelInstance); + + ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); + + assertJobRetries(pi, JOB_RETRIES); + } + + @Test + public void testFailedCallActivity() { + + currentDeployment = testRule.deploy( + Bpmn.createExecutableProcess(PROCESS_ID) + .startEvent() + .callActivity() + .calledElement("testProcess2") + .endEvent() + .done(), + Bpmn.createExecutableProcess("testProcess2") + .startEvent() + .serviceTask() + .camundaClass(FAILING_CLASS) + .camundaAsyncBefore() + .endEvent() + .done()); + + ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess2"); + + assertJobRetries(pi, 4); + } + + @Test + public void testFailingScriptTask() { + BpmnModelInstance bpmnModelInstance = prepareFailingScriptTask(); + + currentDeployment = testRule.deploy(bpmnModelInstance); + + ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); + + assertJobRetries(pi, 4); + } + + @Test + public void testFailingSubProcess() { + BpmnModelInstance bpmnModelInstance = prepareFailingSubProcess(); + + currentDeployment = testRule.deploy(bpmnModelInstance); + + ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); + + assertJobRetries(pi, 4); + } + + + private void assertJobRetries(ProcessInstance pi, int expectedJobRetries) { + assertThat(pi, is(notNullValue())); + + Job job = fetchJob(pi.getProcessInstanceId()); + + try { + + managementService.executeJob(job.getId()); + } catch (Exception e) { + } + + // update job + job = fetchJob(pi.getProcessInstanceId()); + assertEquals(expectedJobRetries, job.getRetries()); + } + + private Job fetchJob(String processInstanceId) { + return managementService.createJobQuery().processInstanceId(processInstanceId).singleResult(); + } + + private BpmnModelInstance prepareSignalEventProcessWithoutRetry() { + BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) + .startEvent() + .intermediateThrowEvent(FAILING_EVENT) + .camundaAsyncBefore(true) + .signal("start") + .serviceTask() + .camundaClass(FAILING_CLASS) + .endEvent() + .done(); + return modelInstance; + } + + private BpmnModelInstance prepareFailingServiceTask() { + BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) + .startEvent() + .serviceTask() + .camundaClass(FAILING_CLASS) + .camundaAsyncBefore() + .endEvent() + .done(); + return modelInstance; + } + + private BpmnModelInstance prepareFailingServiceTaskWithRetryCycle() { + BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) + .startEvent() + .serviceTask() + .camundaClass(FAILING_CLASS) + .camundaAsyncBefore() + .camundaFailedJobRetryTimeCycle("R10/PT5M") + .endEvent() + .done(); + return modelInstance; + } + + private BpmnModelInstance prepareFailingBusinessRuleTask() { + BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) + .startEvent() + .businessRuleTask() + .camundaClass(FAILING_CLASS) + .camundaAsyncBefore() + .endEvent() + .done(); + return modelInstance; + } + + private BpmnModelInstance prepareFailingScriptTask() { + BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess(PROCESS_ID) + .startEvent() + .scriptTask() + .scriptFormat("groovy") + .scriptText("x = 5 / 0") + .camundaAsyncBefore() + .userTask() + .endEvent() + .done(); + return bpmnModelInstance; + } + + private BpmnModelInstance prepareFailingSubProcess() { + BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess(PROCESS_ID) + .startEvent() + .subProcess() + .embeddedSubProcess() + .startEvent() + .serviceTask() + .camundaClass(FAILING_CLASS) + .camundaAsyncBefore() + .endEvent() + .subProcessDone() + .endEvent() + .done(); + return bpmnModelInstance; + } +} \ No newline at end of file diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/jobexecutor/FailedJobListenerWithRetriesTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/jobexecutor/FailedJobListenerWithRetriesTest.java index bbcdd41316f..fa373c62dbe 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/jobexecutor/FailedJobListenerWithRetriesTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/jobexecutor/FailedJobListenerWithRetriesTest.java @@ -21,14 +21,11 @@ import org.camunda.bpm.engine.OptimisticLockingException; import org.camunda.bpm.engine.ProcessEngineConfiguration; import org.camunda.bpm.engine.RuntimeService; -import org.camunda.bpm.engine.impl.ProcessEngineImpl; import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; -import org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd; -import org.camunda.bpm.engine.impl.cmd.FoxJobRetryCmd; +import org.camunda.bpm.engine.impl.cmd.DefaultJobRetryCmd; import org.camunda.bpm.engine.impl.interceptor.Command; import org.camunda.bpm.engine.impl.interceptor.CommandContext; -import org.camunda.bpm.engine.impl.jobexecutor.FailedJobCommandFactory; -import org.camunda.bpm.engine.impl.jobexecutor.JobExecutor; +import org.camunda.bpm.engine.impl.jobexecutor.DefaultFailedJobCommandFactory; import org.camunda.bpm.engine.impl.persistence.entity.JobEntity; import org.camunda.bpm.engine.impl.util.ClockUtil; import org.camunda.bpm.engine.runtime.Job; @@ -134,11 +131,10 @@ private Job getJob() { return jobs.get(0); } - private class OLEFailedJobCommandFactory implements FailedJobCommandFactory { + private class OLEFailedJobCommandFactory extends DefaultFailedJobCommandFactory { private Map oleFoxJobRetryCmds = new HashMap(); - @Override public Command getCommand(String jobId, Throwable exception) { return getOleFoxJobRetryCmds(jobId, exception); } @@ -151,7 +147,7 @@ public OLEFoxJobRetryCmd getOleFoxJobRetryCmds(String jobId, Throwable exception } } - private class OLEFoxJobRetryCmd extends FoxJobRetryCmd { + private class OLEFoxJobRetryCmd extends DefaultJobRetryCmd { private int countRuns = 0; diff --git a/engine/src/test/resources/camunda.cfg.plugins.xml b/engine/src/test/resources/camunda.cfg.plugins.xml index 2e7274df15c..f29efef645c 100644 --- a/engine/src/test/resources/camunda.cfg.plugins.xml +++ b/engine/src/test/resources/camunda.cfg.plugins.xml @@ -29,14 +29,6 @@ - - - - - - - - @@ -50,8 +42,6 @@ - - diff --git a/engine/src/test/resources/camunda.cfg.prefix.xml b/engine/src/test/resources/camunda.cfg.prefix.xml index f6e360db64b..6d1500d0006 100644 --- a/engine/src/test/resources/camunda.cfg.prefix.xml +++ b/engine/src/test/resources/camunda.cfg.prefix.xml @@ -31,14 +31,6 @@ - - - - - - - - @@ -47,8 +39,6 @@ - - diff --git a/engine/src/test/resources/camunda.cfg.prefix_extended.xml b/engine/src/test/resources/camunda.cfg.prefix_extended.xml index 7c919a5f309..9b2cba3a482 100644 --- a/engine/src/test/resources/camunda.cfg.prefix_extended.xml +++ b/engine/src/test/resources/camunda.cfg.prefix_extended.xml @@ -27,20 +27,10 @@ - - - - - - - - - - diff --git a/engine/src/test/resources/camunda.cfg.xml b/engine/src/test/resources/camunda.cfg.xml index d1820b2c404..a382bdd66a2 100644 --- a/engine/src/test/resources/camunda.cfg.xml +++ b/engine/src/test/resources/camunda.cfg.xml @@ -31,22 +31,12 @@ - - - - - - - - - - diff --git a/engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/default.job.retry.property.camunda.cfg.xml b/engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/default.job.retry.property.camunda.cfg.xml index dda45ad2549..816fc04b307 100644 --- a/engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/default.job.retry.property.camunda.cfg.xml +++ b/engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/default.job.retry.property.camunda.cfg.xml @@ -27,20 +27,10 @@ - - - - - - - - - - diff --git a/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/customdefaultretries.camunda.cfg.xml b/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/customdefaultretries.camunda.cfg.xml index 6dd7184eca9..1873f693be2 100644 --- a/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/customdefaultretries.camunda.cfg.xml +++ b/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/customdefaultretries.camunda.cfg.xml @@ -24,19 +24,10 @@ - - - - - - - - - diff --git a/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/defaultretries.camunda.cfg.xml b/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/defaultretries.camunda.cfg.xml index 7333a53fa56..debe1b77a0c 100644 --- a/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/defaultretries.camunda.cfg.xml +++ b/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/defaultretries.camunda.cfg.xml @@ -21,19 +21,9 @@ - - - - - - - - - - diff --git a/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/globalretries.camunda.cfg.xml b/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/globalretries.camunda.cfg.xml new file mode 100644 index 00000000000..efe2854d45f --- /dev/null +++ b/engine/src/test/resources/org/camunda/bpm/engine/test/standalone/initialization/globalretries.camunda.cfg.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qa/test-db-upgrade/config/camunda.cfg.xml b/qa/test-db-upgrade/config/camunda.cfg.xml index 03077612bfb..0e8e1cf2a75 100644 --- a/qa/test-db-upgrade/config/camunda.cfg.xml +++ b/qa/test-db-upgrade/config/camunda.cfg.xml @@ -29,16 +29,6 @@ - - - - - - - - - - diff --git a/qa/test-old-engine/config/camunda.cfg.xml b/qa/test-old-engine/config/camunda.cfg.xml index 03077612bfb..0e8e1cf2a75 100644 --- a/qa/test-old-engine/config/camunda.cfg.xml +++ b/qa/test-old-engine/config/camunda.cfg.xml @@ -29,16 +29,6 @@ - - - - - - - - - -