Search in sources :

Example 6 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class JobExecutorCmdHappyTest method testJobCommandsWithMessage.

public void testJobCommandsWithMessage() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    String jobId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            MessageEntity message = createTweetMessage("i'm coding a test");
            commandContext.getJobManager().send(message);
            return message.getId();
        }
    });
    AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
    List<List<String>> jobIdsList = acquiredJobs.getJobIdBatches();
    assertEquals(1, jobIdsList.size());
    List<String> jobIds = jobIdsList.get(0);
    List<String> expectedJobIds = new ArrayList<String>();
    expectedJobIds.add(jobId);
    assertEquals(expectedJobIds, new ArrayList<String>(jobIds));
    assertEquals(0, tweetHandler.getMessages().size());
    ExecuteJobHelper.executeJob(jobId, commandExecutor);
    assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
    assertEquals(1, tweetHandler.getMessages().size());
    clearDatabase();
}
Also used : AcquireJobsCmd(org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ArrayList(java.util.ArrayList) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class DeploymentAwareJobExecutorTest method testJobsWithoutDeploymentIdAreAlwaysProcessed.

public void testJobsWithoutDeploymentIdAreAlwaysProcessed() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    String messageId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            MessageEntity message = new MessageEntity();
            commandContext.getJobManager().send(message);
            return message.getId();
        }
    });
    AcquiredJobs acquiredJobs = getExecutableJobs(processEngineConfiguration.getJobExecutor());
    Assert.assertEquals(1, acquiredJobs.size());
    Assert.assertTrue(acquiredJobs.contains(messageId));
    commandExecutor.execute(new DeleteJobsCmd(messageId, true));
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) DeleteJobsCmd(org.camunda.bpm.engine.impl.cmd.DeleteJobsCmd)

Example 8 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class JobEntityTest method testInsertJobWithExceptionMessage.

/**
 * Note: This does not test a message with 4-byte Unicode supplementary
 * characters for two reasons:
 * - MySQL 5.1 does not support 4-byte supplementary characters (support from 5.5.3 onwards)
 * - {@link String#length()} counts these characters twice (since they are represented by two
 * chars), so essentially the cutoff would be half the actual cutoff for such a string
 */
public void testInsertJobWithExceptionMessage() {
    String fittingThreeByteMessage = repeatCharacter("\u9faf", JobEntity.MAX_EXCEPTION_MESSAGE_LENGTH);
    JobEntity threeByteJobEntity = new MessageEntity();
    threeByteJobEntity.setExceptionMessage(fittingThreeByteMessage);
    // should not fail
    insertJob(threeByteJobEntity);
    deleteJob(threeByteJobEntity);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)

Example 9 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class ManagementServiceTest method testSetJobRetriesByDefinitionUnlocksInconsistentJobs.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testSetJobRetriesByDefinitionUnlocksInconsistentJobs() {
    // given a job definition
    final JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
    // and an inconsistent job that is never again picked up by a job executor
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            MessageEntity job = new MessageEntity();
            job.setJobDefinitionId(jobDefinition.getId());
            job.setJobHandlerType("any");
            job.setLockOwner("owner");
            job.setLockExpirationTime(ClockUtil.getCurrentTime());
            job.setRetries(0);
            jobManager.send(job);
            return null;
        }
    });
    // when the job retries are reset
    managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 3);
    // then the job can be picked up again
    JobEntity job = (JobEntity) managementService.createJobQuery().singleResult();
    assertNotNull(job);
    assertNull(job.getLockOwner());
    assertNull(job.getLockExpirationTime());
    assertEquals(3, job.getRetries());
    deleteJobAndIncidents(job);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class JobEntityTest method testJobExceptionMessageCutoff.

public void testJobExceptionMessageCutoff() {
    JobEntity threeByteJobEntity = new MessageEntity();
    String message = repeatCharacter("a", JobEntity.MAX_EXCEPTION_MESSAGE_LENGTH * 2);
    threeByteJobEntity.setExceptionMessage(message);
    assertEquals(JobEntity.MAX_EXCEPTION_MESSAGE_LENGTH, threeByteJobEntity.getExceptionMessage().length());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)

Aggregations

MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)12 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)5 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)4 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)3 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)2 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 List (java.util.List)1 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)1 DeleteJobsCmd (org.camunda.bpm.engine.impl.cmd.DeleteJobsCmd)1 Command (org.camunda.bpm.engine.impl.interceptor.Command)1 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)1 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)1 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)1 Execution (org.camunda.bpm.engine.runtime.Execution)1 Job (org.camunda.bpm.engine.runtime.Job)1