Search in sources :

Example 6 with MessageEntity

use of org.activiti.engine.impl.persistence.entity.MessageEntity in project Activiti by Activiti.

the class JobExecutorCmdExceptionTest method testJobCommandsWith3Exceptions.

public void testJobCommandsWith3Exceptions() {
    tweetExceptionHandler.setExceptionsRemaining(3);
    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());
    try {
        managementService.executeJob(job.getId());
        fail("exception expected");
    } catch (Exception e) {
    // exception expected;
    }
    job = managementService.createJobQuery().singleResult();
    assertEquals(0, job.getRetries());
    managementService.deleteJob(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 7 with MessageEntity

use of org.activiti.engine.impl.persistence.entity.MessageEntity 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 8 with MessageEntity

use of org.activiti.engine.impl.persistence.entity.MessageEntity 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)

Aggregations

MessageEntity (org.activiti.engine.impl.persistence.entity.MessageEntity)8 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4 Job (org.activiti.engine.runtime.Job)4 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Page (org.activiti.engine.impl.Page)1 Command (org.activiti.engine.impl.interceptor.Command)1 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)1 AcquiredJobs (org.activiti.engine.impl.jobexecutor.AcquiredJobs)1 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)1 Execution (org.activiti.engine.runtime.Execution)1 Deployment (org.activiti.engine.test.Deployment)1