Search in sources :

Example 26 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class AsyncExecutorTest method testAsyncFailingScript.

@Test
public void testAsyncFailingScript() {
    ProcessEngine processEngine = null;
    try {
        // Deploy
        processEngine = createProcessEngine(true);
        processEngine.getProcessEngineConfiguration().getClock().reset();
        deploy(processEngine, "AsyncExecutorTest.testAsyncFailingScript.bpmn20.xml");
        // Start process instance. Wait for all jobs to be done.
        processEngine.getRuntimeService().startProcessInstanceByKey("asyncScript");
        // There is a back off mechanism for the retry, so need a bit of time
        // But to be sure, we make the wait time small 
        processEngine.getProcessEngineConfiguration().setAsyncFailedJobWaitTime(1);
        final ProcessEngine processEngineCopy = processEngine;
        JobTestHelper.waitForJobExecutorOnCondition(processEngine.getProcessEngineConfiguration(), 10000L, 2000L, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return processEngineCopy.getManagementService().createJobQuery().withRetriesLeft().count() == 0;
            }
        });
        // Verify if all is as expected
        Assert.assertEquals(0, processEngine.getTaskService().createTaskQuery().taskName("Task after script").count());
        Assert.assertEquals(1, processEngine.getManagementService().createJobQuery().count());
        Assert.assertEquals(0, processEngine.getManagementService().createJobQuery().withRetriesLeft().count());
        Assert.assertEquals(1, processEngine.getManagementService().createJobQuery().noRetriesLeft().count());
        Assert.assertEquals(1, processEngine.getManagementService().createJobQuery().withException().count());
        Assert.assertEquals(3, getAsyncExecutorJobCount(processEngine));
    } finally {
        // Clean up
        cleanup(processEngine);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 27 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class AsyncExecutorTest method testAsyncExecutorDisabledOnOneEngine.

@Test
public void testAsyncExecutorDisabledOnOneEngine() {
    ProcessEngine firstProcessEngine = null;
    ProcessEngine secondProcessEngine = null;
    try {
        // Deploy on one engine, where the async executor is disabled
        firstProcessEngine = createProcessEngine(false);
        Date now = setClockToCurrentTime(firstProcessEngine);
        deploy(firstProcessEngine, "AsyncExecutorTest.testRegularAsyncExecution.bpmn20.xml");
        // Start process instance on first engine
        firstProcessEngine.getRuntimeService().startProcessInstanceByKey("asyncExecutor");
        //	Move clock 5 minutes and 1 second. Triggers the timer normally, but not now since async execution is disabled
        // 301 = 5m01s
        addSecondsToCurrentTime(firstProcessEngine, 301);
        Assert.assertEquals(1, firstProcessEngine.getTaskService().createTaskQuery().taskName("The Task").count());
        Assert.assertEquals(0, firstProcessEngine.getTaskService().createTaskQuery().taskName("Task after timer").count());
        Assert.assertEquals(1, firstProcessEngine.getManagementService().createJobQuery().count());
        // Create second engine, with async executor enabled. Same time as the first engine to start, then add 301 seconds
        secondProcessEngine = createProcessEngine(true, now);
        addSecondsToCurrentTime(secondProcessEngine, 361);
        waitForAllJobsBeingExecuted(secondProcessEngine);
        // Verify if all is as expected
        Assert.assertEquals(0, firstProcessEngine.getTaskService().createTaskQuery().taskName("The Task").count());
        Assert.assertEquals(1, firstProcessEngine.getTaskService().createTaskQuery().taskName("Task after timer").count());
        Assert.assertEquals(0, firstProcessEngine.getManagementService().createJobQuery().count());
        Assert.assertEquals(0, getAsyncExecutorJobCount(firstProcessEngine));
        Assert.assertEquals(1, getAsyncExecutorJobCount(secondProcessEngine));
    } finally {
        // Clean up
        cleanup(firstProcessEngine);
        cleanup(secondProcessEngine);
    }
}
Also used : Date(java.util.Date) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 28 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class AsyncExecutorTest method testAsyncScriptExecution.

@Test
public void testAsyncScriptExecution() {
    ProcessEngine processEngine = null;
    try {
        // Deploy
        processEngine = createProcessEngine(true);
        setClockToCurrentTime(processEngine);
        deploy(processEngine, "AsyncExecutorTest.testAsyncScriptExecution.bpmn20.xml");
        // Start process instance. Wait for all jobs to be done
        processEngine.getRuntimeService().startProcessInstanceByKey("asyncScript");
        waitForAllJobsBeingExecuted(processEngine);
        // Verify if all is as expected
        Assert.assertEquals(1, processEngine.getTaskService().createTaskQuery().taskName("Task after script").count());
        Assert.assertEquals(0, processEngine.getManagementService().createJobQuery().count());
        Assert.assertEquals(1, getAsyncExecutorJobCount(processEngine));
    } finally {
        // Clean up
        cleanup(processEngine);
    }
}
Also used : ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 29 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class ProcessEnginesTest method testProcessEngineInfo.

public void testProcessEngineInfo() {
    List<ProcessEngineInfo> processEngineInfos = ProcessEngines.getProcessEngineInfos();
    assertEquals(1, processEngineInfos.size());
    ProcessEngineInfo processEngineInfo = processEngineInfos.get(0);
    assertNull(processEngineInfo.getException());
    assertNotNull(processEngineInfo.getName());
    assertNotNull(processEngineInfo.getResourceUrl());
    ProcessEngine processEngine = ProcessEngines.getProcessEngine(ProcessEngines.NAME_DEFAULT);
    assertNotNull(processEngine);
}
Also used : ProcessEngineInfo(org.activiti.engine.ProcessEngineInfo) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 30 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class MuleHttpBasicAuthTest method httpWithBasicAuth.

@Test
public void httpWithBasicAuth() throws Exception {
    Assert.assertTrue(muleContext.isStarted());
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    Deployment deployment = processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/mule/testHttpBasicAuth.bpmn20.xml").deploy();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(10, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    processEngine.getRepositoryService().deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Aggregations

ProcessEngine (org.activiti.engine.ProcessEngine)31 Test (org.junit.Test)13 RepositoryService (org.activiti.engine.RepositoryService)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 ActivitiException (org.activiti.engine.ActivitiException)6 RuntimeService (org.activiti.engine.RuntimeService)6 TaskService (org.activiti.engine.TaskService)4 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)4 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 Task (org.activiti.engine.task.Task)4 StandaloneInMemProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)3 Deployment (org.activiti.engine.repository.Deployment)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1