use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class JobExecutorCmdExceptionTest method testJobCommandsWith2Exceptions.
public void testJobCommandsWith2Exceptions() {
commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
MessageEntity message = createTweetExceptionMessage();
commandContext.getJobEntityManager().send(message);
return message.getId();
}
});
Job job = managementService.createJobQuery().singleResult();
assertEquals(3, job.getRetries());
try {
managementService.executeJob(job.getId());
fail("exception expected");
} catch (Exception e) {
// exception expected;
}
job = managementService.createJobQuery().singleResult();
assertEquals(2, job.getRetries());
try {
managementService.executeJob(job.getId());
fail("exception expected");
} catch (Exception e) {
// exception expected;
}
job = managementService.createJobQuery().singleResult();
assertEquals(1, job.getRetries());
managementService.executeJob(job.getId());
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class JobExecutorCmdHappyTest method testJobCommandsWithTimer.
public void testJobCommandsWithTimer() {
// clock gets automatically reset in LogTestCase.runTest
processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME));
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
String jobId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
TimerEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
commandContext.getJobEntityManager().schedule(timer);
return timer.getId();
}
});
AcquiredJobEntities acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd("testLockOwner", 10000, 5));
assertEquals(0, acquiredJobs.size());
processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd("testLockOwner", 10000, 5));
assertEquals(1, acquiredJobs.size());
JobEntity job = acquiredJobs.getJobs().iterator().next();
assertEquals(jobId, job.getId());
assertEquals(0, tweetHandler.getMessages().size());
commandExecutor.execute(new ExecuteAsyncJobCmd(job));
assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
assertEquals(1, tweetHandler.getMessages().size());
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class JobExecutorCmdHappyTest method testJobCommandsWithMessage.
public void testJobCommandsWithMessage() {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
String jobId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
MessageEntity message = createTweetMessage("i'm coding a test");
commandContext.getJobEntityManager().send(message);
return message.getId();
}
});
Job job = managementService.createJobQuery().singleResult();
assertNotNull(job);
assertEquals(jobId, job.getId());
assertEquals(0, tweetHandler.getMessages().size());
managementService.executeJob(job.getId());
assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
assertEquals(1, tweetHandler.getMessages().size());
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class UserEntityManager method updateUser.
public void updateUser(User updatedUser) {
CommandContext commandContext = Context.getCommandContext();
DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
dbSqlSession.update((PersistentObject) updatedUser);
if (getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, updatedUser));
}
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class VariableScopeImpl method ensureVariableInstancesInitialized.
protected void ensureVariableInstancesInitialized() {
if (variableInstances == null) {
variableInstances = new HashMap<String, VariableInstanceEntity>();
CommandContext commandContext = Context.getCommandContext();
if (commandContext == null) {
throw new ActivitiException("lazy loading outside command context");
}
List<VariableInstanceEntity> variableInstancesList = loadVariableInstances();
for (VariableInstanceEntity variableInstance : variableInstancesList) {
variableInstances.put(variableInstance.getName(), variableInstance);
}
}
}
Aggregations