@Deployment(resources = {"org/camunda/bpm/engine/test/jobexecutor/simpleAsyncProcess.bpmn20.xml"}) public void testSuspendJobDuringAcquisition() { runtimeService.startProcessInstanceByKey("simpleAsyncProcess"); // given a waiting acquisition and a waiting suspension JobAcquisitionThread acquisitionThread = new JobAcquisitionThread(); acquisitionThread.startAndWaitUntilControlIsReturned(); JobSuspensionThread jobSuspensionThread = new JobSuspensionThread("simpleAsyncProcess"); jobSuspensionThread.startAndWaitUntilControlIsReturned(); // first complete suspension: jobSuspensionThread.proceedAndWaitTillDone(); acquisitionThread.proceedAndWaitTillDone(); // then the acquisition will not fail with optimistic locking assertNull(jobSuspensionThread.exception); assertNull(acquisitionThread.exception); // but the job will also not be acquired assertEquals(0, acquisitionThread.acquiredJobs.size()); // -------------------------------------------- // given a waiting acquisition and a waiting suspension acquisitionThread = new JobAcquisitionThread(); acquisitionThread.startAndWaitUntilControlIsReturned(); jobSuspensionThread = new JobSuspensionThread("simpleAsyncProcess"); jobSuspensionThread.startAndWaitUntilControlIsReturned(); // first complete acquisition: acquisitionThread.proceedAndWaitTillDone(); jobSuspensionThread.proceedAndWaitTillDone(); // then there are no optimistic locking exceptions assertNull(jobSuspensionThread.exception); assertNull(acquisitionThread.exception); // clean up log TestHelper.clearOpLog(processEngineConfiguration); }
@Deployment public void testCompetingJobAcquisitions() throws Exception { runtimeService.startProcessInstanceByKey("CompetingJobAcquisitionProcess"); log.debug("test thread starts thread one"); JobAcquisitionThread threadOne = new JobAcquisitionThread(); threadOne.startAndWaitUntilControlIsReturned(); log.debug("test thread continues to start thread two"); JobAcquisitionThread threadTwo = new JobAcquisitionThread(); threadTwo.startAndWaitUntilControlIsReturned(); log.debug("test thread notifies thread 1"); threadOne.proceedAndWaitTillDone(); assertNull(threadOne.exception); log.debug("test thread notifies thread 2"); threadTwo.proceedAndWaitTillDone(); assertNotNull(threadTwo.exception); assertTextPresent( "was updated by another transaction concurrently", threadTwo.exception.getMessage()); }