Search in sources :

Example 96 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class MultiInstanceTest method testMultiInstanceSequentialReceiveTask.

@Deployment
public void testMultiInstanceSequentialReceiveTask() {
    runtimeService.startProcessInstanceByKey("multi-instance-receive");
    Execution execution = runtimeService.createExecutionQuery().activityId("theReceiveTask").singleResult();
    assertNotNull(execution);
    // Complete all four of the executions
    while (execution != null) {
        runtimeService.signal(execution.getId());
        execution = runtimeService.createExecutionQuery().activityId("theReceiveTask").singleResult();
    }
    // There is one task after the task
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createExecutionQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) Execution(org.activiti.engine.runtime.Execution) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Deployment(org.activiti.engine.test.Deployment)

Example 97 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class MultiInstanceTest method testSequentialScriptTasks.

@Deployment
public void testSequentialScriptTasks() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("sum", 0);
    vars.put("nrOfLoops", 5);
    runtimeService.startProcessInstanceByKey("miSequentialScriptTask", vars);
    Execution waitStateExecution = runtimeService.createExecutionQuery().singleResult();
    int sum = (Integer) runtimeService.getVariable(waitStateExecution.getId(), "sum");
    assertEquals(10, sum);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Execution(org.activiti.engine.runtime.Execution) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) HashMap(java.util.HashMap) Deployment(org.activiti.engine.test.Deployment)

Example 98 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class RestResponseFactory method createExecutionResponseList.

public List<ExecutionResponse> createExecutionResponseList(List<Execution> executions) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    List<ExecutionResponse> responseList = new ArrayList<ExecutionResponse>();
    for (Execution instance : executions) {
        responseList.add(createExecutionResponse(instance, urlBuilder));
    }
    return responseList;
}
Also used : Execution(org.activiti.engine.runtime.Execution) ExecutionResponse(org.activiti.rest.service.api.runtime.process.ExecutionResponse) ArrayList(java.util.ArrayList)

Example 99 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class AsyncTaskTest method testFailingAsyncServiceTimer.

@Deployment
public void testFailingAsyncServiceTimer() {
    // start process 
    runtimeService.startProcessInstanceByKey("asyncService");
    // now there should be one job in the database, and it is a message
    assertEquals(1, managementService.createJobQuery().count());
    Job job = managementService.createJobQuery().singleResult();
    if (!(job instanceof MessageEntity)) {
        fail("the job must be a message");
    }
    try {
        managementService.executeJob(job.getId());
        fail();
    } catch (Exception e) {
    // exception expected
    }
    // the service failed: the execution is still sitting in the service task:
    Execution execution = runtimeService.createExecutionQuery().singleResult();
    assertNotNull(execution);
    assertEquals("service", runtimeService.getActiveActivityIds(execution.getId()).get(0));
    // there is still a single job because the timer was created in the same transaction as the 
    // service was executed (which rolled back)
    assertEquals(1, managementService.createJobQuery().count());
    runtimeService.deleteProcessInstance(execution.getId(), "dead");
}
Also used : MessageEntity(org.activiti.engine.impl.persistence.entity.MessageEntity) Execution(org.activiti.engine.runtime.Execution) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 100 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class AsyncTaskTest method FAILING_testFailingAsycServiceTimer.

// TODO: Think about this: 
@Deployment
public void FAILING_testFailingAsycServiceTimer() {
    // start process 
    runtimeService.startProcessInstanceByKey("asyncService");
    // now there are two jobs the message and a timer:
    assertEquals(2, managementService.createJobQuery().count());
    // let 'max-retires' on the message be reached
    waitForJobExecutorToProcessAllJobs(10000L, 100L);
    // the service failed: the execution is still sitting in the service task:
    Execution execution = runtimeService.createExecutionQuery().singleResult();
    assertNotNull(execution);
    assertEquals("service", runtimeService.getActiveActivityIds(execution.getId()).get(0));
    // there are tow jobs, the message and the timer (the message will not be retried anymore, max retires is reached.)
    assertEquals(2, managementService.createJobQuery().count());
    // now the timer triggers:
    Context.getProcessEngineConfiguration().getClock().setCurrentTime(new Date(System.currentTimeMillis() + 10000));
    waitForJobExecutorToProcessAllJobs(10000L, 100L);
    // and we are done:
    assertNull(runtimeService.createExecutionQuery().singleResult());
    // and there are no more jobs left:
    assertEquals(0, managementService.createJobQuery().count());
}
Also used : Execution(org.activiti.engine.runtime.Execution) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Execution (org.activiti.engine.runtime.Execution)131 Deployment (org.activiti.engine.test.Deployment)105 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)75 Task (org.activiti.engine.task.Task)33 HashMap (java.util.HashMap)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)10 HttpPut (org.apache.http.client.methods.HttpPut)10 StringEntity (org.apache.http.entity.StringEntity)9 ArrayList (java.util.ArrayList)8 ActivitiException (org.activiti.engine.ActivitiException)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Date (java.util.Date)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5