@Override public List<JobEntity> execute(CommandContext commandContext) { return commandContext .getJobManager() .findNextJobsToExecute(new Page(0, 100)); } });
@Test public void nonExclusiveDifferentInstance() { // given: two non-exclusive jobs for the same process instance JobEntity job1 = createNonExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1); JobEntity job2 = createNonExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_2); // when the job executor acquire new jobs when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2)); // then the job executor should acquire job1 and job 2 in different batches checkThatAcquiredJobsInDifferentBatches(); }
@Override public List<JobEntity> execute(CommandContext commandContext) { return commandContext .getJobManager() .findNextJobsToExecute(new Page(0, 100)); } });
@Override public List<JobEntity> execute(CommandContext commandContext) { return commandContext .getJobManager() .findNextJobsToExecute(new Page(0, 100)); } });
@Test public void nonExclusiveJobsSameInstance() { // given: two non-exclusive jobs for a different process instance JobEntity job1 = createNonExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1); JobEntity job2 = createNonExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_1); // when the job executor acquire new jobs when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2)); // then the job executor should acquire job1 and job 2 in different batches checkThatAcquiredJobsInDifferentBatches(); }
@Test public void exclusiveJobsDifferentInstance() { // given: two exclusive jobs for a different process instance JobEntity job1 = createExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1); JobEntity job2 = createExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_2); // when the job executor acquire new jobs when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2)); // then the job executor should acquire job1 and job 2 in different batches checkThatAcquiredJobsInDifferentBatches(); }
public AcquiredJobs execute(CommandContext commandContext) { acquiredJobs = new AcquiredJobs(numJobsToAcquire); List<JobEntity> jobs = commandContext .getJobManager() .findNextJobsToExecute(new Page(0, numJobsToAcquire)); Map<String, List<String>> exclusiveJobsByProcessInstance = new HashMap<String, List<String>>(); for (JobEntity job : jobs) { lockJob(job); if(job.isExclusive()) { List<String> list = exclusiveJobsByProcessInstance.get(job.getProcessInstanceId()); if (list == null) { list = new ArrayList<String>(); exclusiveJobsByProcessInstance.put(job.getProcessInstanceId(), list); } list.add(job.getId()); } else { acquiredJobs.addJobIdBatch(job.getId()); } } for (List<String> jobIds : exclusiveJobsByProcessInstance.values()) { acquiredJobs.addJobIdBatch(jobIds); } // register an OptimisticLockingListener which is notified about jobs which cannot be acquired. // the listener removes them from the list of acquired jobs. commandContext .getDbEntityManager() .registerOptimisticLockingListener(this); return acquiredJobs; }
@Test public void exclusiveJobsSameInstance() { // given: two exclusive jobs for the same process instance JobEntity job1 = createExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1); JobEntity job2 = createExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_1); // when the job executor acquire new jobs when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2)); // then the job executor should acquire job1 and job 2 in one batch AcquiredJobs acquiredJobs = acquireJobsCmd.execute(commandContext); List<List<String>> jobIdBatches = acquiredJobs.getJobIdBatches(); assertThat(jobIdBatches.size(), is(1)); assertThat(jobIdBatches.get(0).size(), is(2)); assertThat(jobIdBatches.get(0), hasItems(JOB_ID_1, JOB_ID_2)); }
public AcquiredJobs execute(CommandContext commandContext) { acquiredJobs = new AcquiredJobs(numJobsToAcquire); List<JobEntity> jobs = commandContext .getJobManager() .findNextJobsToExecute(new Page(0, numJobsToAcquire)); Map<String, List<String>> exclusiveJobsByProcessInstance = new HashMap<String, List<String>>(); for (JobEntity job : jobs) { lockJob(job); if(job.isExclusive()) { List<String> list = exclusiveJobsByProcessInstance.get(job.getProcessInstanceId()); if (list == null) { list = new ArrayList<String>(); exclusiveJobsByProcessInstance.put(job.getProcessInstanceId(), list); } list.add(job.getId()); } else { acquiredJobs.addJobIdBatch(job.getId()); } } for (List<String> jobIds : exclusiveJobsByProcessInstance.values()) { acquiredJobs.addJobIdBatch(jobIds); } // register an OptimisticLockingListener which is notified about jobs which cannot be acquired. // the listener removes them from the list of acquired jobs. commandContext .getDbEntityManager() .registerOptimisticLockingListener(this); return acquiredJobs; }
@Override public List<JobEntity> execute(CommandContext commandContext) { List<JobEntity> jobs = commandContext.getJobManager().findNextJobsToExecute(new Page(0, 100)); for (JobEntity job : jobs) { job.setLockOwner("test"); } return jobs; } });
@Test public void nonExclusiveJobsSameInstance() { // given: two non-exclusive jobs for a different process instance JobEntity job1 = createNonExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1); JobEntity job2 = createNonExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_1); // when the job executor acquire new jobs when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2)); // then the job executor should acquire job1 and job 2 in different batches checkThatAcquiredJobsInDifferentBatches(); }
@Test public void nonExclusiveDifferentInstance() { // given: two non-exclusive jobs for the same process instance JobEntity job1 = createNonExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1); JobEntity job2 = createNonExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_2); // when the job executor acquire new jobs when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2)); // then the job executor should acquire job1 and job 2 in different batches checkThatAcquiredJobsInDifferentBatches(); }
@Override public List<JobEntity> execute(CommandContext commandContext) { return commandContext .getJobManager() .findNextJobsToExecute(new Page(0, 100)); } });
@Override public List<JobEntity> execute(CommandContext commandContext) { return commandContext .getJobManager() .findNextJobsToExecute(new Page(0, 100)); } });
@Test public void exclusiveJobsDifferentInstance() { // given: two exclusive jobs for a different process instance JobEntity job1 = createExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1); JobEntity job2 = createExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_2); // when the job executor acquire new jobs when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2)); // then the job executor should acquire job1 and job 2 in different batches checkThatAcquiredJobsInDifferentBatches(); }
@Override public List<JobEntity> execute(CommandContext commandContext) { return commandContext .getJobManager() .findNextJobsToExecute(new Page(0, 100)); } });
public Void execute(CommandContext commandContext) { JobManager jobManager = commandContext.getJobManager(); List<JobEntity> executableJobs = jobManager.findNextJobsToExecute(new Page(0, 1)); assertEquals(1, executableJobs.size()); assertEquals(myCustomTimerEntity, executableJobs.get(0).getJobHandlerConfigurationRaw()); assertEquals(SuspensionState.ACTIVE.getStateCode(), executableJobs.get(0).getSuspensionState()); executableJobs = jobManager.findJobsByProcessInstanceId(processInstanceId); assertEquals(1, executableJobs.size()); assertEquals(myCustomTimerEntity, executableJobs.get(0).getJobHandlerConfigurationRaw()); assertEquals(SuspensionState.ACTIVE.getStateCode(), executableJobs.get(0).getSuspensionState()); return null; } });
@Test public void exclusiveJobsSameInstance() { // given: two exclusive jobs for the same process instance JobEntity job1 = createExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1); JobEntity job2 = createExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_1); // when the job executor acquire new jobs when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2)); // then the job executor should acquire job1 and job 2 in one batch AcquiredJobs acquiredJobs = acquireJobsCmd.execute(commandContext); List<List<String>> jobIdBatches = acquiredJobs.getJobIdBatches(); assertThat(jobIdBatches.size(), is(1)); assertThat(jobIdBatches.get(0).size(), is(2)); assertThat(jobIdBatches.get(0), hasItems(JOB_ID_1, JOB_ID_2)); }
public AcquiredJobs execute(CommandContext commandContext) { acquiredJobs = new AcquiredJobs(numJobsToAcquire); List<JobEntity> jobs = commandContext .getJobManager() .findNextJobsToExecute(new Page(0, numJobsToAcquire)); Map<String, List<String>> exclusiveJobsByProcessInstance = new HashMap<String, List<String>>(); for (JobEntity job : jobs) { lockJob(job); if(job.isExclusive()) { List<String> list = exclusiveJobsByProcessInstance.get(job.getProcessInstanceId()); if (list == null) { list = new ArrayList<String>(); exclusiveJobsByProcessInstance.put(job.getProcessInstanceId(), list); } list.add(job.getId()); } else { acquiredJobs.addJobIdBatch(job.getId()); } } for (List<String> jobIds : exclusiveJobsByProcessInstance.values()) { acquiredJobs.addJobIdBatch(jobIds); } // register an OptimisticLockingListener which is notified about jobs which cannot be acquired. // the listener removes them from the list of acquired jobs. commandContext .getDbEntityManager() .registerOptimisticLockingListener(this); return acquiredJobs; }
@Override public List<JobEntity> execute(CommandContext commandContext) { List<JobEntity> jobs = commandContext.getJobManager().findNextJobsToExecute(new Page(0, 100)); for (JobEntity job : jobs) { job.setLockOwner("test"); } return jobs; } });