use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class JobEventsTest method checkEventContext.
protected void checkEventContext(ActivitiEvent event, Job entity, boolean scopeExecutionExpected) {
assertEquals(entity.getProcessInstanceId(), event.getProcessInstanceId());
assertEquals(entity.getProcessDefinitionId(), event.getProcessDefinitionId());
if (scopeExecutionExpected) {
assertEquals(entity.getExecutionId(), event.getExecutionId());
} else {
assertEquals(entity.getProcessInstanceId(), event.getExecutionId());
}
assertTrue(event instanceof ActivitiEntityEvent);
ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event;
assertTrue(entityEvent.getEntity() instanceof Job);
assertEquals(entity.getId(), ((Job) entityEvent.getEntity()).getId());
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class SignalsResourceTest method testSignalEventReceivedAsync.
@Deployment(resources = { "org/activiti/rest/service/api/runtime/SignalsResourceTest.process-signal-start.bpmn20.xml" })
public void testSignalEventReceivedAsync() throws Exception {
org.activiti.engine.repository.Deployment tenantDeployment = repositoryService.createDeployment().addClasspathResource("org/activiti/rest/service/api/runtime/SignalsResourceTest.process-signal-start.bpmn20.xml").tenantId("my tenant").deploy();
try {
// Signal without vars, without tenant
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("signalName", "The Signal");
requestNode.put("async", true);
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_SIGNALS));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_ACCEPTED));
// Check if job is queued as a result of the signal without tenant ID set
assertEquals(1, managementService.createJobQuery().jobWithoutTenantId().count());
// Signal with tenant
requestNode.put("tenantId", "my tenant");
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_ACCEPTED));
// Check if job is queued as a result of the signal, in the right tenant
assertEquals(1, managementService.createJobQuery().jobTenantId("my tenant").count());
// Signal with variables and async, should fail as it's not supported
ArrayNode vars = requestNode.putArray("variables");
ObjectNode var = vars.addObject();
var.put("name", "testVar");
var.put("value", "test");
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
} finally {
// Clean up tenant-specific deployment
if (tenantDeployment != null) {
repositoryService.deleteDeployment(tenantDeployment.getId(), true);
}
// Clear jobs
List<Job> jobs = managementService.createJobQuery().list();
for (Job job : jobs) {
managementService.deleteJob(job.getId());
}
}
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class BoundaryTimerNonInterruptingEventTest method testTimerOnConcurrentSubprocess.
@Deployment
public void testTimerOnConcurrentSubprocess() {
String procId = runtimeService.startProcessInstanceByKey("testTimerOnConcurrentSubprocess").getId();
assertEquals(4, taskService.createTaskQuery().count());
Job timer = managementService.createJobQuery().singleResult();
managementService.executeJob(timer.getId());
assertEquals(5, taskService.createTaskQuery().count());
// Complete 4 tasks that will trigger the join
Task task = taskService.createTaskQuery().taskDefinitionKey("sub1task1").singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().taskDefinitionKey("sub1task2").singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().taskDefinitionKey("sub2task1").singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().taskDefinitionKey("sub2task2").singleResult();
taskService.complete(task.getId());
assertEquals(1, taskService.createTaskQuery().count());
// Finally, complete the task that was created due to the timer
task = taskService.createTaskQuery().taskDefinitionKey("timerFiredTask").singleResult();
taskService.complete(task.getId());
assertProcessEnded(procId);
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class BoundaryTimerNonInterruptingEventTest method testTimerOnConcurrentSubprocess2.
@Deployment(resources = "org/activiti/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.testTimerOnConcurrentSubprocess.bpmn20.xml")
public void testTimerOnConcurrentSubprocess2() {
String procId = runtimeService.startProcessInstanceByKey("testTimerOnConcurrentSubprocess").getId();
assertEquals(4, taskService.createTaskQuery().count());
Job timer = managementService.createJobQuery().singleResult();
managementService.executeJob(timer.getId());
assertEquals(5, taskService.createTaskQuery().count());
Task task = taskService.createTaskQuery().taskDefinitionKey("sub1task1").singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().taskDefinitionKey("sub1task2").singleResult();
taskService.complete(task.getId());
// complete the task that was created due to the timer
task = taskService.createTaskQuery().taskDefinitionKey("timerFiredTask").singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().taskDefinitionKey("sub2task1").singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().taskDefinitionKey("sub2task2").singleResult();
taskService.complete(task.getId());
assertEquals(0, taskService.createTaskQuery().count());
assertProcessEnded(procId);
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class BoundaryTimerNonInterruptingEventTest method testReceiveTaskWithBoundaryTimer.
@Deployment
public /**
* see https://activiti.atlassian.net/browse/ACT-1106
*/
void testReceiveTaskWithBoundaryTimer() {
// Set the clock fixed
HashMap<String, Object> variables = new HashMap<String, Object>();
variables.put("timeCycle", "R/PT1H");
// After process start, there should be a timer created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("nonInterruptingCycle", variables);
JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertEquals(1, jobs.size());
// The Execution Query should work normally and find executions in state "task"
List<Execution> executions = runtimeService.createExecutionQuery().activityId("task").list();
assertEquals(1, executions.size());
List<String> activeActivityIds = runtimeService.getActiveActivityIds(executions.get(0).getId());
assertEquals(1, activeActivityIds.size());
assertEquals("task", activeActivityIds.get(0));
runtimeService.signal(executions.get(0).getId());
// // After setting the clock to time '1 hour and 5 seconds', the second timer should fire
// processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
// waitForJobExecutorToProcessAllJobs(5000L, 25L);
// assertEquals(0L, jobQuery.count());
// which means the process has ended
assertProcessEnded(pi.getId());
}
Aggregations