Search in sources :

Example 56 with CommandContext

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());
}
Also used : MessageEntity(org.activiti.engine.impl.persistence.entity.MessageEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) Job(org.activiti.engine.runtime.Job)

Example 57 with CommandContext

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());
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ExecuteAsyncJobCmd(org.activiti.engine.impl.cmd.ExecuteAsyncJobCmd) Date(java.util.Date) AcquireTimerJobsCmd(org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)

Example 58 with CommandContext

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());
}
Also used : MessageEntity(org.activiti.engine.impl.persistence.entity.MessageEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) Job(org.activiti.engine.runtime.Job)

Example 59 with CommandContext

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));
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 60 with CommandContext

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);
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) CommandContext(org.activiti.engine.impl.interceptor.CommandContext)

Aggregations

CommandContext (org.activiti.engine.impl.interceptor.CommandContext)72 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)18 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)13 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)8 Date (java.util.Date)7 ActivitiException (org.activiti.engine.ActivitiException)7 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)6 HashMap (java.util.HashMap)4 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)4 Job (org.activiti.engine.runtime.Job)4 Deployment (org.activiti.engine.test.Deployment)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 List (java.util.List)3 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)3