Search in sources :

Example 6 with OptimisticLockingException

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

the class CompetingMessageCorrelationTest method testConcurrentMixedCorrelation.

@Deployment(resources = "org/camunda/bpm/engine/test/concurrency/CompetingMessageCorrelationTest.catchMessageProcess.bpmn20.xml")
public void testConcurrentMixedCorrelation() throws InterruptedException {
    InvocationLogListener.reset();
    // given a process instance
    runtimeService.startProcessInstanceByKey("testProcess");
    // and two threads correlating in parallel (one exclusive, one non-exclusive)
    ThreadControl thread1 = executeControllableCommand(new ControllableMessageCorrelationCommand("Message", true));
    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();
    // thread one correlates and acquires the exclusive lock
    thread1.makeContinue();
    thread1.waitForSync();
    // thread two correlates since it does not need a pessimistic lock
    thread2.makeContinue();
    thread2.waitForSync();
    // the service task was executed twice
    assertEquals(2, InvocationLogListener.getInvocations());
    // the first thread ends its transaction and releases the lock; the event subscription is now gone
    thread1.waitUntilDone();
    assertNull(thread1.getException());
    Task afterMessageTask = taskService.createTaskQuery().singleResult();
    assertEquals(afterMessageTask.getTaskDefinitionKey(), "afterMessageUserTask");
    // thread two attempts to end its transaction and fails with optimistic locking
    thread2.makeContinue();
    thread2.waitForSync();
    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 7 with OptimisticLockingException

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

the class CompetingMessageCorrelationTest method FAILING_testConcurrentMixedCorrelationCase2.

/**
 * <p>
 *   At least on MySQL, this test case fails with deadlock exceptions.
 *   The reason is the combination of our flush with the locking of the event
 *   subscription documented in the ticket CAM-3636.
 * </p>
 * @throws InterruptedException
 */
@Deployment(resources = "org/camunda/bpm/engine/test/concurrency/CompetingMessageCorrelationTest.catchMessageProcess.bpmn20.xml")
public void FAILING_testConcurrentMixedCorrelationCase2() throws InterruptedException {
    InvocationLogListener.reset();
    // given a process instance
    runtimeService.startProcessInstanceByKey("testProcess");
    // and two threads correlating in parallel (one exclusive, one non-exclusive)
    ThreadControl thread1 = executeControllableCommand(new ControllableMessageCorrelationCommand("Message", false));
    thread1.reportInterrupts();
    ThreadControl thread2 = executeControllableCommand(new ControllableMessageCorrelationCommand("Message", true));
    thread2.reportInterrupts();
    // both threads open a transaction and wait before correlating the message
    thread1.waitForSync();
    thread2.waitForSync();
    // thread one correlates and acquires no lock
    thread1.makeContinue();
    thread1.waitForSync();
    // thread two acquires a lock and succeeds because thread one hasn't acquired one
    thread2.makeContinue();
    thread2.waitForSync();
    // the service task was executed twice
    assertEquals(2, InvocationLogListener.getInvocations());
    // thread one ends its transaction and blocks on flush when it attempts to delete the event subscription
    thread1.makeContinue();
    Thread.sleep(5000);
    assertNull(thread1.getException());
    assertEquals(0, taskService.createTaskQuery().count());
    // thread 2 flushes successfully and releases the lock
    thread2.waitUntilDone();
    assertNull(thread2.getException());
    Task afterMessageTask = taskService.createTaskQuery().singleResult();
    assertNotNull(afterMessageTask);
    assertEquals(afterMessageTask.getTaskDefinitionKey(), "afterMessageUserTask");
    // thread 1 flush fails with optimistic locking
    thread1.join();
    assertTrue(thread1.getException() != null);
    assertTrue(thread1.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 8 with OptimisticLockingException

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

the class CompetingMessageCorrelationTest method testConcurrentMessageCorrelationTwiceAndTreeCompaction.

@Deployment
public void testConcurrentMessageCorrelationTwiceAndTreeCompaction() {
    runtimeService.startProcessInstanceByKey("process");
    // trigger non-interrupting boundary event 1 that ends in a none end event immediately
    runtimeService.correlateMessage("Message2");
    // trigger non-interrupting boundary event 2 and wait before flush
    ThreadControl correlateThread = executeControllableCommand(new ControllableMessageCorrelationCommand("Message1", 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 9 with OptimisticLockingException

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

the class TaskServiceTest method testUserTaskOptimisticLocking.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
@Test
public void testUserTaskOptimisticLocking() {
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task1 = taskService.createTaskQuery().singleResult();
    Task task2 = taskService.createTaskQuery().singleResult();
    task1.setDescription("test description one");
    taskService.saveTask(task1);
    try {
        task2.setDescription("test description two");
        taskService.saveTask(task2);
        fail("Expecting exception");
    } catch (OptimisticLockingException e) {
    // Expected exception
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) OptimisticLockingException(org.camunda.bpm.engine.OptimisticLockingException) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

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