Search in sources :

Example 1 with OptimisticLockingException

use of org.camunda.bpm.engine.OptimisticLockingException in project camunda-bpm-platform by camunda.

the class ExecuteJobHelper method invokeJobListener.

protected static void invokeJobListener(CommandExecutor commandExecutor, JobFailureCollector jobFailureCollector) {
    if (jobFailureCollector.getJobId() != null) {
        if (jobFailureCollector.getFailure() != null) {
            // the failed job listener is responsible for decrementing the retries and logging the exception to the DB.
            FailedJobListener failedJobListener = createFailedJobListener(commandExecutor, jobFailureCollector.getFailure(), jobFailureCollector.getJobId());
            OptimisticLockingException exception = callFailedJobListenerWithRetries(commandExecutor, failedJobListener);
            if (exception != null) {
                throw exception;
            }
        } else {
            SuccessfulJobListener successListener = createSuccessfulJobListener(commandExecutor);
            commandExecutor.execute(successListener);
        }
    }
}
Also used : OptimisticLockingException(org.camunda.bpm.engine.OptimisticLockingException)

Example 2 with OptimisticLockingException

use of org.camunda.bpm.engine.OptimisticLockingException in project camunda-bpm-platform by camunda.

the class StandaloneTaskTest method testOptimisticLockingThrownOnMultipleUpdates.

public void testOptimisticLockingThrownOnMultipleUpdates() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    String taskId = task.getId();
    // first modification
    Task task1 = taskService.createTaskQuery().taskId(taskId).singleResult();
    Task task2 = taskService.createTaskQuery().taskId(taskId).singleResult();
    task1.setDescription("first modification");
    taskService.saveTask(task1);
    // second modification on the initial instance
    task2.setDescription("second modification");
    try {
        taskService.saveTask(task2);
        fail("should get an exception here as the task was modified by someone else.");
    } catch (OptimisticLockingException expected) {
    // exception was thrown as expected
    }
    taskService.deleteTask(taskId, true);
}
Also used : Task(org.camunda.bpm.engine.task.Task) OptimisticLockingException(org.camunda.bpm.engine.OptimisticLockingException)

Example 3 with OptimisticLockingException

use of org.camunda.bpm.engine.OptimisticLockingException in project camunda-bpm-platform by camunda.

the class CompetingMessageCorrelationTest method testConcurrentMessageCorrelationAndTreeCompaction.

@Deployment
public void testConcurrentMessageCorrelationAndTreeCompaction() {
    runtimeService.startProcessInstanceByKey("process");
    // trigger non-interrupting boundary event and wait before flush
    ThreadControl correlateThread = executeControllableCommand(new ControllableMessageCorrelationCommand("Message", false));
    correlateThread.reportInterrupts();
    // stop correlation right before the flush
    correlateThread.waitForSync();
    correlateThread.makeContinueAndWaitForSync();
    // trigger tree compaction
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task task : tasks) {
        taskService.complete(task.getId());
    }
    // flush correlation
    correlateThread.waitUntilDone();
    // the correlation should not have succeeded
    Throwable exception = correlateThread.getException();
    assertNotNull(exception);
    assertTrue(exception instanceof OptimisticLockingException);
}
Also used : Task(org.camunda.bpm.engine.task.Task) OptimisticLockingException(org.camunda.bpm.engine.OptimisticLockingException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with OptimisticLockingException

use of org.camunda.bpm.engine.OptimisticLockingException in project camunda-bpm-platform by camunda.

the class CompetingMessageCorrelationTest method testConcurrentCorrelationFailsWithOptimisticLockingException.

@Deployment(resources = "org/camunda/bpm/engine/test/concurrency/CompetingMessageCorrelationTest.catchMessageProcess.bpmn20.xml")
public void testConcurrentCorrelationFailsWithOptimisticLockingException() {
    InvocationLogListener.reset();
    // given a process instance
    runtimeService.startProcessInstanceByKey("testProcess");
    // and two threads correlating in parallel
    ThreadControl thread1 = executeControllableCommand(new ControllableMessageCorrelationCommand("Message", false));
    thread1.reportInterrupts();
    ThreadControl thread2 = executeControllableCommand(new ControllableMessageCorrelationCommand("Message", false));
    thread2.reportInterrupts();
    // both threads open a transaction and wait before correlating the message
    thread1.waitForSync();
    thread2.waitForSync();
    // both threads correlate
    thread1.makeContinue();
    thread2.makeContinue();
    thread1.waitForSync();
    thread2.waitForSync();
    // the service task was executed twice
    assertEquals(2, InvocationLogListener.getInvocations());
    // the first thread ends its transcation
    thread1.waitUntilDone();
    assertNull(thread1.getException());
    Task afterMessageTask = taskService.createTaskQuery().singleResult();
    assertEquals(afterMessageTask.getTaskDefinitionKey(), "afterMessageUserTask");
    // the second thread ends its transaction and fails with optimistic locking exception
    thread2.waitUntilDone();
    assertTrue(thread2.getException() != null);
    assertTrue(thread2.getException() instanceof OptimisticLockingException);
}
Also used : Task(org.camunda.bpm.engine.task.Task) OptimisticLockingException(org.camunda.bpm.engine.OptimisticLockingException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with OptimisticLockingException

use of org.camunda.bpm.engine.OptimisticLockingException in project camunda-bpm-platform by camunda.

the class ConcurrentJobExecutorTest method testCompetingJobExecutionDeleteJobDuringExecution.

@Test
public void testCompetingJobExecutionDeleteJobDuringExecution() {
    // given a simple process with a async service task
    testRule.deploy(Bpmn.createExecutableProcess("process").startEvent().serviceTask("task").camundaAsyncBefore().camundaExpression("${true}").endEvent().done());
    runtimeService.startProcessInstanceByKey("process");
    Job currentJob = managementService.createJobQuery().singleResult();
    // when a job is executed
    JobExecutionThread threadOne = new JobExecutionThread(currentJob.getId());
    threadOne.startAndWaitUntilControlIsReturned();
    // and deleted in parallel
    managementService.deleteJob(currentJob.getId());
    // then the job fails with a OLE and the failed job listener throws no NPE
    LOG.debug("test thread notifies thread 1");
    threadOne.proceedAndWaitTillDone();
    assertTrue(threadOne.exception instanceof OptimisticLockingException);
}
Also used : OptimisticLockingException(org.camunda.bpm.engine.OptimisticLockingException) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Aggregations

OptimisticLockingException (org.camunda.bpm.engine.OptimisticLockingException)9 Task (org.camunda.bpm.engine.task.Task)7 Deployment (org.camunda.bpm.engine.test.Deployment)6 Test (org.junit.Test)2 Job (org.camunda.bpm.engine.runtime.Job)1