Exemplo n.º 1
0
        protected internal override IList <string> collectJobIds(CommandContext commandContext)
        {
            ISet <string> collectedJobIds = new HashSet <string>();

            IList <string> jobIds = this.JobIds;

            if (jobIds != null)
            {
                collectedJobIds.addAll(jobIds);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.runtime.JobQuery jobQuery = this.jobQuery;
            JobQuery jobQuery = this.jobQuery;

            if (jobQuery != null)
            {
                foreach (Job job in jobQuery.list())
                {
                    collectedJobIds.Add(job.Id);
                }
            }

            return(new List <string>(collectedJobIds));
        }
Exemplo n.º 2
0
        public virtual IList <JobDto> queryJobs(JobQueryDto queryDto, int?firstResult, int?maxResults)
        {
            ProcessEngine engine = ProcessEngine;

            queryDto.ObjectMapper = ObjectMapper;
            JobQuery query = queryDto.toQuery(engine);

            IList <Job> matchingJobs;

            if (firstResult != null || maxResults != null)
            {
                matchingJobs = executePaginatedQuery(query, firstResult, maxResults);
            }
            else
            {
                matchingJobs = query.list();
            }

            IList <JobDto> jobResults = new List <JobDto>();

            foreach (Job job in matchingJobs)
            {
                JobDto resultJob = JobDto.fromJob(job);
                jobResults.Add(resultJob);
            }
            return(jobResults);
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Deployment public void testExpressionOnTimer()
        public virtual void testExpressionOnTimer()
        {
            // Set the clock fixed
            DateTime startTime = DateTime.Now;

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

            variables["duration"] = "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);

            // After setting the clock to time '1 hour and 5 seconds', the second timer should fire
            ClockUtil.CurrentTime = new DateTime(startTime.Ticks + ((60 * 60 * 1000) + 5000));
            waitForJobExecutorToProcessAllJobs(5000L);
            assertEquals(0L, jobQuery.count());

            // which means the process has ended
            assertProcessEnded(pi.Id);
        }
Exemplo n.º 4
0
        private JobQuery setUpMockJobQuery(IList <Job> mockedJobs)
        {
            JobQuery sampleJobQuery = mock(typeof(JobQuery));

            when(sampleJobQuery.list()).thenReturn(mockedJobs);
            when(sampleJobQuery.count()).thenReturn((long)mockedJobs.Count);

            when(processEngine.ManagementService.createJobQuery()).thenReturn(sampleJobQuery);

            return(sampleJobQuery);
        }
Exemplo n.º 5
0
        private void verifyQueryResults(JobQuery query, int countExpected)
        {
            assertEquals(countExpected, query.list().size());
            assertEquals(countExpected, query.count());

            if (countExpected == 1)
            {
                assertNotNull(query.singleResult());
            }
            else if (countExpected > 1)
            {
                verifySingleResultFails(query);
            }
            else if (countExpected == 0)
            {
                assertNull(query.singleResult());
            }
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testQueryByCreateTimeCombinations()
        public virtual void testQueryByCreateTimeCombinations()
        {
            JobQuery    query = managementService.createJobQuery().processInstanceId(processInstanceIdOne);
            IList <Job> jobs  = query.list();

            assertEquals(1, jobs.Count);
            DateTime jobCreateTime = jobs[0].CreateTime;

            query = managementService.createJobQuery().processInstanceId(processInstanceIdOne).createdAfter(new DateTime(jobCreateTime.Ticks - 1));
            verifyQueryResults(query, 1);

            query = managementService.createJobQuery().processInstanceId(processInstanceIdOne).createdAfter(jobCreateTime);
            verifyQueryResults(query, 0);

            query = managementService.createJobQuery().processInstanceId(processInstanceIdOne).createdBefore(jobCreateTime);
            verifyQueryResults(query, 1);

            query = managementService.createJobQuery().processInstanceId(processInstanceIdOne).createdBefore(new DateTime(jobCreateTime.Ticks - 1));
            verifyQueryResults(query, 0);
        }
Exemplo n.º 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);
        }
Exemplo n.º 8
0
        /*
         * Test for when multiple boundary timer events are defined on the same user
         * task
         *
         * Configuration: - timer 1 -> 2 hours -> secondTask - timer 2 -> 1 hour ->
         * thirdTask - timer 3 -> 3 hours -> fourthTask
         *
         * See process image next to the process xml resource
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Deployment public void testMultipleTimersOnUserTask()
        public virtual void testMultipleTimersOnUserTask()
        {
            // Set the clock fixed
            DateTime startTime = DateTime.Now;

            // After process start, there should be 3 timers created
            ProcessInstance pi       = runtimeService.startProcessInstanceByKey("multipleTimersOnUserTask");
            JobQuery        jobQuery = managementService.createJobQuery().processInstanceId(pi.Id);
            IList <Job>     jobs     = jobQuery.list();

            assertEquals(3, jobs.Count);

            // After setting the clock to time '1 hour and 5 seconds', the second timer should fire
            ClockUtil.CurrentTime = new DateTime(startTime.Ticks + ((60 * 60 * 1000) + 5000));
            waitForJobExecutorToProcessAllJobs(5000L);
            assertEquals(0L, jobQuery.count());

            // which means that the third task is reached
            Task task = taskService.createTaskQuery().singleResult();

            assertEquals("Third Task", task.Name);
        }
Exemplo n.º 9
0
        //sorting //////////////////////////////////////////

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testQuerySorting()
        public virtual void testQuerySorting()
        {
            // asc
            assertEquals(4, managementService.createJobQuery().orderByJobId().asc().count());
            assertEquals(4, managementService.createJobQuery().orderByJobDuedate().asc().count());
            assertEquals(4, managementService.createJobQuery().orderByExecutionId().asc().count());
            assertEquals(4, managementService.createJobQuery().orderByProcessInstanceId().asc().count());
            assertEquals(4, managementService.createJobQuery().orderByJobRetries().asc().count());
            assertEquals(4, managementService.createJobQuery().orderByProcessDefinitionId().asc().count());
            assertEquals(4, managementService.createJobQuery().orderByProcessDefinitionKey().asc().count());

            // desc
            assertEquals(4, managementService.createJobQuery().orderByJobId().desc().count());
            assertEquals(4, managementService.createJobQuery().orderByJobDuedate().desc().count());
            assertEquals(4, managementService.createJobQuery().orderByExecutionId().desc().count());
            assertEquals(4, managementService.createJobQuery().orderByProcessInstanceId().desc().count());
            assertEquals(4, managementService.createJobQuery().orderByJobRetries().desc().count());
            assertEquals(4, managementService.createJobQuery().orderByProcessDefinitionId().desc().count());
            assertEquals(4, managementService.createJobQuery().orderByProcessDefinitionKey().desc().count());

            // sorting on multiple fields
            setRetries(processInstanceIdTwo, 2);
            ClockUtil.CurrentTime = new DateTime(timerThreeFireTime.Ticks + ONE_SECOND);     // make sure all timers can fire

            JobQuery query = managementService.createJobQuery().timers().executable().orderByJobRetries().asc().orderByJobDuedate().desc();

            IList <Job> jobs = query.list();

            assertEquals(3, jobs.Count);

            assertEquals(2, jobs[0].Retries);
            assertEquals(3, jobs[1].Retries);
            assertEquals(3, jobs[2].Retries);

            assertEquals(processInstanceIdTwo, jobs[0].ProcessInstanceId);
            assertEquals(processInstanceIdThree, jobs[1].ProcessInstanceId);
            assertEquals(processInstanceIdOne, jobs[2].ProcessInstanceId);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Deployment public void testReceiveTaskWithBoundaryTimer()
        public virtual void testReceiveTaskWithBoundaryTimer()
        {
            // Set the clock fixed
            DateTime startTime = DateTime.Now;

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

            variables["timeCycle"] = "R/PT1H";

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

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

            assertEquals(1, jobs.Count);

            // The Execution Query should work normally and find executions in state "task"
            IList <Execution> executions = runtimeService.createExecutionQuery().activityId("task").list();

            assertEquals(1, executions.Count);
            IList <string> activeActivityIds = runtimeService.getActiveActivityIds(executions[0].Id);

            assertEquals(1, activeActivityIds.Count);
            assertEquals("task", activeActivityIds[0]);

            runtimeService.signal(executions[0].Id);

            //    // After setting the clock to time '1 hour and 5 seconds', the second timer should fire
            //    ClockUtil.setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
            //    waitForJobExecutorToProcessAllJobs(5000L);
            //    assertEquals(0L, jobQuery.count());

            // which means the process has ended
            assertProcessEnded(pi.Id);
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Deployment public void testMultipleTimersOnUserTask()
        public virtual void testMultipleTimersOnUserTask()
        {
            // Set the clock fixed
            DateTime startTime = DateTime.Now;

            // After process start, there should be 3 timers created
            ProcessInstance pi    = runtimeService.startProcessInstanceByKey("nonInterruptingTimersOnUserTask");
            Task            task1 = taskService.createTaskQuery().singleResult();

            assertEquals("First Task", task1.Name);

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

            assertEquals(2, jobs.Count);

            // After setting the clock to time '1 hour and 5 seconds', the first timer should fire
            ClockUtil.CurrentTime = new DateTime(startTime.Ticks + ((60 * 60 * 1000) + 5000));
            waitForJobExecutorToProcessAllJobs(5000L);

            // we still have one timer more to fire
            assertEquals(1L, jobQuery.count());

            // and we are still in the first state, but in the second state as well!
            assertEquals(2L, taskService.createTaskQuery().count());
            IList <Task> taskList = taskService.createTaskQuery().orderByTaskName().desc().list();

            assertEquals("First Task", taskList[0].Name);
            assertEquals("Escalation Task 1", taskList[1].Name);

            // complete the task and end the forked execution
            taskService.complete(taskList[1].Id);

            // but we still have the original executions
            assertEquals(1L, taskService.createTaskQuery().count());
            assertEquals("First Task", taskService.createTaskQuery().singleResult().Name);

            // After setting the clock to time '2 hour and 5 seconds', the second timer should fire
            ClockUtil.CurrentTime = new DateTime(startTime.Ticks + ((2 * 60 * 60 * 1000) + 5000));
            waitForJobExecutorToProcessAllJobs(5000L);

            // no more timers to fire
            assertEquals(0L, jobQuery.count());

            // and we are still in the first state, but in the next escalation state as well
            assertEquals(2L, taskService.createTaskQuery().count());
            taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
            assertEquals("First Task", taskList[0].Name);
            assertEquals("Escalation Task 2", taskList[1].Name);

            // This time we end the main task
            taskService.complete(taskList[0].Id);

            // but we still have the escalation task
            assertEquals(1L, taskService.createTaskQuery().count());
            Task escalationTask = taskService.createTaskQuery().singleResult();

            assertEquals("Escalation Task 2", escalationTask.Name);

            taskService.complete(escalationTask.Id);

            // now we are really done :-)
            assertProcessEnded(pi.Id);
        }