public virtual void testCompletingUpdateJobDefinitionPriorityDuringExecution()
        {
            testRule.Deploy(SIMPLE_ASYNC_PROCESS);

            // given
            // two running instances
            runtimeService.StartProcessInstanceByKey("simpleAsyncProcess");
            runtimeService.StartProcessInstanceByKey("simpleAsyncProcess");

            // and a job definition
            IJobDefinition jobDefinition = managementService.CreateJobDefinitionQuery().First();

            // and two jobs
            IList <IJob> jobs = managementService.CreateJobQuery().ToList();

            // when the first job is executed but has not yet committed
            JobExecutionThread executionThread = new JobExecutionThread(this, jobs[0].Id);

            executionThread.startAndWaitUntilControlIsReturned();

            // and the job priority is updated
            JobDefinitionPriorityThread priorityThread = new JobDefinitionPriorityThread(this, jobDefinition.Id, 42L, true);

            priorityThread.startAndWaitUntilControlIsReturned();

            // and the priority threads commits first
            priorityThread.proceedAndWaitTillDone();

            // then both jobs priority has changed
            IList <IJob> currentJobs = managementService.CreateJobQuery().ToList();

            foreach (IJob job in currentJobs)
            {
                Assert.AreEqual(42, job.Priority);
            }

            // and the execution thread can nevertheless successfully finish job execution
            executionThread.proceedAndWaitTillDone();

            Assert.IsNull(executionThread.exception);

            // and ultimately only one job with an updated priority is left
            IJob remainingJob = managementService.CreateJobQuery().First();

            Assert.NotNull(remainingJob);
        }
        public virtual void testCompletingSuspensionJobDuringPriorityUpdate()
        {
            testRule.Deploy(SIMPLE_ASYNC_PROCESS);

            // given
            // two running instances (ie two jobs)
            runtimeService.StartProcessInstanceByKey("simpleAsyncProcess");
            runtimeService.StartProcessInstanceByKey("simpleAsyncProcess");

            // a job definition
            IJobDefinition jobDefinition = managementService.CreateJobDefinitionQuery().First();

            // when suspending the jobs is attempted
            JobSuspensionByJobDefinitionThread suspensionThread = new JobSuspensionByJobDefinitionThread(this, jobDefinition.Id);

            suspensionThread.startAndWaitUntilControlIsReturned();

            // and updating the priority is attempted
            JobDefinitionPriorityThread priorityUpdateThread = new JobDefinitionPriorityThread(this, jobDefinition.Id, 42L, true);

            priorityUpdateThread.startAndWaitUntilControlIsReturned();

            // and both commands overlap each other
            suspensionThread.proceedAndWaitTillDone();
            priorityUpdateThread.proceedAndWaitTillDone();

            // then both updates have been performed
            IList <IJob> updatedJobs = managementService.CreateJobQuery().ToList();

            Assert.AreEqual(2, updatedJobs.Count);
            foreach (IJob job in updatedJobs)
            {
                Assert.AreEqual(42, job.Priority);
                Assert.True(job.Suspended);
            }
        }