use of net.nemerosa.ontrack.job.orchestrator.JobOrchestratorSupplier in project ontrack by nemerosa.
the class JobScatteringTest method scatteringInSameType.
@Test
public void scatteringInSameType() {
// Scheduler
DefaultJobScheduler scheduler = new DefaultJobScheduler(NOPJobDecorator.INSTANCE, new SynchronousScheduledExecutorService(), NOPJobListener.INSTANCE, false, true, 1.0);
// Creates a list of jobs with a weak key
List<TestJob> jobs = TestUtils.range(1, 100).stream().map(i -> TestJob.of(String.format("%d", i))).collect(Collectors.toList());
// Orchestration of all those jobs every 6 hours
Collection<JobOrchestratorSupplier> jobOrchestratorSupplier = Collections.singletonList(() -> jobs.stream().map(j -> JobRegistration.of(j).everyMinutes(6 * 60)));
// Orchestrator
JobOrchestrator orchestrator = new JobOrchestrator(scheduler, "Orchestrator", jobOrchestratorSupplier);
// Scheduling the orchestrator (manual mode)
scheduler.schedule(orchestrator, Schedule.NONE);
// Launching the orchestrator (manually)
orchestrator.orchestrate(JobRunListener.out());
// Getting the actual schedules of the jobs
List<Schedule> actualSchedules = jobs.stream().map(job -> scheduler.getJobStatus(job.getKey())).filter(Optional::isPresent).map(Optional::get).map(JobStatus::getActualSchedule).collect(Collectors.toList());
List<Long> initialPeriods = actualSchedules.stream().map(Schedule::getInitialPeriod).collect(Collectors.toList());
initialPeriods.forEach(l -> System.out.format("--> %d%n", l));
// Checks that all jobs have been scheduled
assertEquals("All jobs have been scheduled", jobs.size(), initialPeriods.size());
// Checks that all schedules more or less different
DescriptiveStatistics stats = new DescriptiveStatistics();
initialPeriods.forEach(stats::addValue);
// Gets the std deviation
double standardDeviation = stats.getStandardDeviation();
double max = stats.getMax();
// Gets this in minutes (this was returned in ms)
double stdDevMinutes = TimeUnit.MINUTES.convert((long) standardDeviation, TimeUnit.MILLISECONDS);
double maxMinutes = TimeUnit.MINUTES.convert((long) max, TimeUnit.MILLISECONDS);
// It must be >> 0
assertTrue("Std deviation must be >> 0", stdDevMinutes > 60.0);
System.out.println("Max = " + maxMinutes);
assertTrue("Max is <= period", maxMinutes <= 6 * 60.0);
}
Aggregations