コード例 #1
0
        protected internal virtual void waitForExecutedJobWithRetriesLeft(int retriesLeft, string jobId)
        {
            JobQuery jobQuery = managementService.createJobQuery();

            if (!string.ReferenceEquals(jobId, null))
            {
                jobQuery.jobId(jobId);
            }

            Job job = jobQuery.singleResult();

            try
            {
                managementService.executeJob(job.Id);
            }
            catch (Exception)
            {
            }

            // update job
            job = jobQuery.singleResult();

            if (job.Retries != retriesLeft)
            {
                waitForExecutedJobWithRetriesLeft(retriesLeft, jobId);
            }
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Deployment public void testFailingTimeCycle()
        public virtual void testFailingTimeCycle()
        {
            // given
            runtimeService.startProcessInstanceByKey("process");

            JobQuery failedJobQuery = managementService.createJobQuery();
            JobQuery jobQuery       = managementService.createJobQuery();

            assertEquals(1, jobQuery.count());

            string jobId = jobQuery.singleResult().Id;

            failedJobQuery.jobId(jobId);

            // when (1)
            try
            {
                managementService.executeJob(jobId);
                fail();
            }
            catch (Exception)
            {
                // expected
            }

            // then (1)
            Job failedJob = failedJobQuery.singleResult();

            assertEquals(2, failedJob.Retries);

            // a new timer job has been created
            assertEquals(2, jobQuery.count());

            assertEquals(1, managementService.createJobQuery().withException().count());
            assertEquals(0, managementService.createJobQuery().noRetriesLeft().count());
            assertEquals(2, managementService.createJobQuery().withRetriesLeft().count());

            // when (2)
            try
            {
                managementService.executeJob(jobId);
            }
            catch (Exception)
            {
                // expected
            }

            // then (2)
            failedJob = failedJobQuery.singleResult();
            assertEquals(1, failedJob.Retries);

            // there are still two jobs
            assertEquals(2, jobQuery.count());

            assertEquals(1, managementService.createJobQuery().withException().count());
            assertEquals(0, managementService.createJobQuery().noRetriesLeft().count());
            assertEquals(2, managementService.createJobQuery().withRetriesLeft().count());
        }
コード例 #3
0
        public virtual void testSuspensionByProcessDefinitionKey_shouldSuspendJob()
        {
            // given
            // a deployed process definition
            ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

            // a running process instance with a failed job
            IDictionary <string, object> @params = new Dictionary <string, object>();

            @params["fail"] = true;
            runtimeService.startProcessInstanceByKey("suspensionProcess", @params);

            // the failed job
            JobQuery jobQuery = managementService.createJobQuery();
            Job      job      = jobQuery.singleResult();

            assertFalse(job.Suspended);

            // when
            // the job will be suspended
            managementService.suspendJobByProcessDefinitionKey(processDefinition.Key);

            // then
            // the job should be suspended
            assertEquals(0, jobQuery.active().count());
            assertEquals(1, jobQuery.suspended().count());

            Job suspendedJob = jobQuery.suspended().singleResult();

            assertEquals(job.Id, suspendedJob.Id);
            assertTrue(suspendedJob.Suspended);
        }
コード例 #4
0
        public virtual void testIdlingWithHint(JobCreationInCycle jobCreationInCycle)
        {
            initAcquisitionAndIdleToMaxTime();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Date startTime = new java.util.Date();
            DateTime        startTime    = DateTime.Now;
            ProcessInstance procInstance = jobCreationInCycle.createJobAndContinueCycle();

            // After process start, there should be 1 timer created
            Task task1 = engineRule.TaskService.createTaskQuery().singleResult();

            assertEquals("Timer Task", task1.Name);
            //and one job
            JobQuery jobQuery = engineRule.ManagementService.createJobQuery().processInstanceId(procInstance.Id);
            Job      job      = jobQuery.singleResult();

            assertNotNull(job);

            // the hint of the added job resets the idle time
            // => 0 jobs are acquired so we had to wait BASE IDLE TIME
            //after this time we can acquire the timer
            triggerReconfigurationAndNextCycle();
            assertJobExecutorWaitEvent(BASE_IDLE_WAIT_TIME);

            //time is increased so timer is found
            ClockUtil.CurrentTime = new DateTime(startTime.Ticks + BASE_IDLE_WAIT_TIME);
            //now we are able to acquire the job
            cycleAcquisitionAndAssertAfterJobExecution(jobQuery);
        }
コード例 #5
0
        public virtual void testTimeCycle()
        {
            // given
            runtimeService.startProcessInstanceByKey("nonInterruptingCycle");

            JobQuery jobQuery = managementService.createJobQuery();

            assertEquals(1, jobQuery.count());
            string jobId = jobQuery.singleResult().Id;

            // when
            managementService.executeJob(jobId);

            // then
            assertEquals(1, jobQuery.count());

            string anotherJobId = jobQuery.singleResult().Id;

            assertFalse(jobId.Equals(anotherJobId));
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testTimerRecalculationBasedOnProcessVariable()
        public virtual void testTimerRecalculationBasedOnProcessVariable()
        {
            // given
            IDictionary <string, object> variables = new Dictionary <string, object>();

            variables["timerExpression"] = "PT10S";
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("TimerRecalculationProcess", variables);

            ProcessInstanceQuery instancesQuery = runtimeService.createProcessInstanceQuery().processInstanceId(instance.Id);
            JobQuery             jobQuery       = managementService.createJobQuery();

            assertEquals(1, instancesQuery.count());
            assertEquals(1, jobQuery.count());

            Job      job        = jobQuery.singleResult();
            DateTime oldDueDate = job.Duedate;

            // when
            runtimeService.setVariable(instance.Id, "timerExpression", "PT1S");
            managementService.recalculateJobDuedate(job.Id, true);

            // then
            assertEquals(1, jobQuery.count());
            Job jobRecalculated = jobQuery.singleResult();

            assertNotEquals(oldDueDate, jobRecalculated.Duedate);

            DateTime calendar = new DateTime();

            calendar = new DateTime(jobRecalculated.CreateTime);
            calendar.AddSeconds(1);
            DateTime expectedDate = calendar;

            assertEquals(expectedDate, jobRecalculated.Duedate);

            waitForJobExecutorToProcessAllJobs();

            assertEquals(0, instancesQuery.count());
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Deployment public void testRecalculateUnchangedExpressionOnTimerCurrentDateBased()
        public virtual void testRecalculateUnchangedExpressionOnTimerCurrentDateBased()
        {
            // Set the clock fixed
            DateTime startTime = DateTime.Now;

            Dictionary <string, object> variables = new Dictionary <string, object>();

            variables["duedate"] = "PT1H";

            // After process start, there should be a timer created
            ProcessInstance pi = runtimeService.startProcessInstanceByKey("testExpressionOnTimer", variables);

            JobQuery    jobQuery = managementService.createJobQuery().processInstanceId(pi.Id);
            IList <Job> jobs     = jobQuery.list();

            assertEquals(1, jobs.Count);
            Job      job     = jobs[0];
            DateTime oldDate = job.Duedate;

            // After recalculation of the timer, the job's duedate should be changed
            DateTime currentTime = new DateTime(startTime.Ticks + TimeUnit.MINUTES.toMillis(5));

            ClockUtil.CurrentTime = currentTime;
            managementService.recalculateJobDuedate(job.Id, false);
            Job jobUpdated = jobQuery.singleResult();

            assertEquals(job.Id, jobUpdated.Id);
            assertNotEquals(oldDate, jobUpdated.Duedate);
            assertTrue(oldDate < jobUpdated.Duedate);
            DateTime expectedDate = LocalDateTime.fromDateFields(currentTime).plusHours(1).toDate();

            assertThat(jobUpdated.Duedate).isCloseTo(expectedDate, 1000l);

            // After setting the clock to time '1 hour and 6 min', the second timer should fire
            ClockUtil.CurrentTime = new DateTime(startTime.Ticks + TimeUnit.HOURS.toMillis(1L) + TimeUnit.MINUTES.toMillis(6L));
            waitForJobExecutorToProcessAllJobs(5000L);
            assertEquals(0L, jobQuery.count());

            // which means the process has ended
            assertProcessEnded(pi.Id);
        }
コード例 #8
0
        public virtual void testRecalculateChangedExpressionOnTimerCreationDateBased()
        {
            // Set the clock fixed
            DateTime startTime = DateTime.Now;

            Dictionary <string, object> variables = new Dictionary <string, object>();

            variables["duedate"] = "PT1H";

            // After process start, there should be a timer created
            ProcessInstance pi = runtimeService.startProcessInstanceByKey("testExpressionOnTimer", variables);

            JobQuery    jobQuery = managementService.createJobQuery().processInstanceId(pi.Id);
            IList <Job> jobs     = jobQuery.list();

            assertEquals(1, jobs.Count);
            Job      job     = jobs[0];
            DateTime oldDate = job.Duedate;

            // After recalculation of the timer, the job's duedate should be the same
            runtimeService.setVariable(pi.Id, "duedate", "PT15M");
            managementService.recalculateJobDuedate(job.Id, true);
            Job jobUpdated = jobQuery.singleResult();

            assertEquals(job.Id, jobUpdated.Id);
            assertNotEquals(oldDate, jobUpdated.Duedate);
            assertEquals(LocalDateTime.fromDateFields(jobUpdated.CreateTime).plusMinutes(15).toDate(), jobUpdated.Duedate);

            // After setting the clock to time '16 minutes', the timer should fire
            ClockUtil.CurrentTime = new DateTime(startTime.Ticks + TimeUnit.MINUTES.toMillis(16L));
            waitForJobExecutorToProcessAllJobs(5000L);
            assertEquals(0L, jobQuery.count());

            // which means the process has ended
            assertProcessEnded(pi.Id);
        }