Search in sources :

Example 1 with RetryInterceptor

use of org.activiti.engine.impl.interceptor.RetryInterceptor in project Activiti by Activiti.

the class RetryInterceptorTest method testRetryInterceptor.

public void testRetryInterceptor() {
    RetryInterceptor retryInterceptor = new RetryInterceptor();
    retryInterceptor.setNext(new CommandInvoker());
    try {
        retryInterceptor.execute(new CommandConfig(), new CommandThrowingOptimisticLockingException());
        fail("ActivitiException expected.");
    } catch (ActivitiException e) {
        assertTrue(e.getMessage().contains(retryInterceptor.getNumOfRetries() + " retries failed"));
    }
}
Also used : CommandInvoker(org.activiti.engine.impl.interceptor.CommandInvoker) ActivitiException(org.activiti.engine.ActivitiException) CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) RetryInterceptor(org.activiti.engine.impl.interceptor.RetryInterceptor)

Example 2 with RetryInterceptor

use of org.activiti.engine.impl.interceptor.RetryInterceptor in project Activiti by Activiti.

the class CompetingSignalsTest method testCompetingSignalsWithRetry.

@Deployment(resources = { "org/activiti/engine/test/concurrency/CompetingSignalsTest.testCompetingSignals.bpmn20.xml" })
public void testCompetingSignalsWithRetry() throws Exception {
    RuntimeServiceImpl runtimeServiceImpl = (RuntimeServiceImpl) runtimeService;
    CommandExecutorImpl before = (CommandExecutorImpl) runtimeServiceImpl.getCommandExecutor();
    try {
        CommandInterceptor retryInterceptor = new RetryInterceptor();
        retryInterceptor.setNext(before.getFirst());
        runtimeServiceImpl.setCommandExecutor(new CommandExecutorImpl(before.getDefaultConfig(), retryInterceptor));
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CompetingSignalsProcess");
        String processInstanceId = processInstance.getId();
        log.debug("test thread starts thread one");
        SignalThread threadOne = new SignalThread(processInstanceId);
        threadOne.startAndWaitUntilControlIsReturned();
        log.debug("test thread continues to start thread two");
        SignalThread threadTwo = new SignalThread(processInstanceId);
        threadTwo.startAndWaitUntilControlIsReturned();
        log.debug("test thread notifies thread 1");
        threadOne.proceedAndWaitTillDone();
        assertNull(threadOne.exception);
        log.debug("test thread notifies thread 2");
        threadTwo.proceedAndWaitTillDone();
        assertNull(threadTwo.exception);
    } finally {
        // restore the command executor
        runtimeServiceImpl.setCommandExecutor(before);
    }
}
Also used : CommandExecutorImpl(org.activiti.engine.impl.cfg.CommandExecutorImpl) CommandInterceptor(org.activiti.engine.impl.interceptor.CommandInterceptor) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RuntimeServiceImpl(org.activiti.engine.impl.RuntimeServiceImpl) RetryInterceptor(org.activiti.engine.impl.interceptor.RetryInterceptor) Deployment(org.activiti.engine.test.Deployment)

Example 3 with RetryInterceptor

use of org.activiti.engine.impl.interceptor.RetryInterceptor in project Activiti by Activiti.

the class RetryInterceptorTest method setupProcessEngine.

@Before
public void setupProcessEngine() {
    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) new StandaloneInMemProcessEngineConfiguration();
    processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:retryInterceptorTest");
    List<CommandInterceptor> interceptors = new ArrayList<CommandInterceptor>();
    retryInterceptor = new RetryInterceptor();
    interceptors.add(retryInterceptor);
    processEngineConfiguration.setCustomPreCommandInterceptors(interceptors);
    processEngine = processEngineConfiguration.buildProcessEngine();
}
Also used : ArrayList(java.util.ArrayList) CommandInterceptor(org.activiti.engine.impl.interceptor.CommandInterceptor) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) StandaloneInMemProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration) RetryInterceptor(org.activiti.engine.impl.interceptor.RetryInterceptor) Before(org.junit.Before)

Aggregations

RetryInterceptor (org.activiti.engine.impl.interceptor.RetryInterceptor)3 CommandInterceptor (org.activiti.engine.impl.interceptor.CommandInterceptor)2 ArrayList (java.util.ArrayList)1 ActivitiException (org.activiti.engine.ActivitiException)1 RuntimeServiceImpl (org.activiti.engine.impl.RuntimeServiceImpl)1 CommandExecutorImpl (org.activiti.engine.impl.cfg.CommandExecutorImpl)1 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)1 StandaloneInMemProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)1 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)1 CommandInvoker (org.activiti.engine.impl.interceptor.CommandInvoker)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Deployment (org.activiti.engine.test.Deployment)1 Before (org.junit.Before)1