@Test public void delegatesToAllProviderIfRequestingMoreThanMaxCached() { assertThat(provider.getJobExecutions(Optional.of(Fixtures.JOB_NAME_1), Optional.of(COMPLETED.getExitCode()), MAX_CACHED_RESULTS_PER_JOB_NAME + 1)).isEmpty(); verify(allProvider).getJobExecutions(any(), any(), anyInt()); }
@Override public Collection<JobExecution> getJobExecutions(Optional<String> jobNameRegexp, Optional<String> exitCode, int limitPerJob) { if (limitPerJob > this.cacheSize) return allJobExecutionProvider.getJobExecutions(jobNameRegexp, exitCode, limitPerJob); else { log.debug("Getting job executions from cache for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob); Optional<Pattern> maybeJobNamePattern = jobNameRegexp.map(Pattern::compile); TreeSet<JobExecution> result = new TreeSet(byDescendingTime()); jobExecutionsByJobName.entrySet().stream() .filter(e -> maybeJobNamePattern.map(p -> p.matcher(e.getKey()).matches()).orElse(true)) .map(Map.Entry::getValue) .flatMap(je -> je.getJobExecutions(exitCode).stream().sorted(byDescendingTime()).limit(limitPerJob)) .forEach(result::add); log.debug("Found {} job execution(s) for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob, result.size()); return result; } }
CachedJobExecutionProvider implements Consumer<JobExecution>, JobExecutionProvider { @Override public Collection<JobExecution> getJobExecutions(Optional<String> jobNameRegexp, Optional<String> exitCode, int limitPerJob) { if (limitPerJob > this.cacheSize) return allJobExecutionProvider.getJobExecutions(jobNameRegexp, exitCode, limitPerJob); else { log.debug("Getting job executions from cache for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob); Optional<Pattern> maybeJobNamePattern = jobNameRegexp.map(Pattern::compile); TreeSet<JobExecution> result = new TreeSet(byDescendingTime()); jobExecutionsByJobName.entrySet().stream() .filter(e -> maybeJobNamePattern.map(p -> p.matcher(e.getKey()).matches()).orElse(true)) .map(Map.Entry::getValue) .flatMap(je -> je.getJobExecutions(exitCode).stream().sorted(byDescendingTime()).limit(limitPerJob)) .forEach(result::add); log.debug("Found {} job execution(s) for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob, result.size()); return result; } } }
CachedJobExecutionProvider implements Consumer<JobExecution>, JobExecutionProvider { @Override public Collection<JobExecution> getJobExecutions(Optional<String> jobNameRegexp, Optional<String> exitCode, int limitPerJob) { if (limitPerJob > this.cacheSize) return allJobExecutionProvider.getJobExecutions(jobNameRegexp, exitCode, limitPerJob); else { log.debug("Getting job executions from cache for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob); Optional<Pattern> maybeJobNamePattern = jobNameRegexp.map(Pattern::compile); TreeSet<JobExecution> result = new TreeSet(byDescendingTime()); jobExecutionsByJobName.entrySet().stream() .filter(e -> maybeJobNamePattern.map(p -> p.matcher(e.getKey()).matches()).orElse(true)) .map(Map.Entry::getValue) .flatMap(je -> je.getJobExecutions(exitCode).stream().sorted(byDescendingTime()).limit(limitPerJob)) .forEach(result::add); log.debug("Found {} job execution(s) for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob, result.size()); return result; } } CachedJobExecutionProvider(JobExecutionAspect executionAspect, AllJobExecutionProvider allJobExecutionProvider,
                                      @Value("${com.github.chrisgleissner.springbatchrest.jobExecutionCacheSize:100}") int jobExecutionCacheSize); }
CachedJobExecutionProvider implements Consumer<JobExecution>, JobExecutionProvider { @Override public Collection<JobExecution> getJobExecutions(Optional<String> jobNameRegexp, Optional<String> exitCode, int limitPerJob) { if (limitPerJob > this.cacheSize) return allJobExecutionProvider.getJobExecutions(jobNameRegexp, exitCode, limitPerJob); else { log.debug("Getting job executions from cache for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob); Optional<Pattern> maybeJobNamePattern = jobNameRegexp.map(Pattern::compile); TreeSet<JobExecution> result = new TreeSet(byDescendingTime()); jobExecutionsByJobName.entrySet().stream() .filter(e -> maybeJobNamePattern.map(p -> p.matcher(e.getKey()).matches()).orElse(true)) .map(Map.Entry::getValue) .flatMap(je -> je.getJobExecutions(exitCode).stream().sorted(byDescendingTime()).limit(limitPerJob)) .forEach(result::add); log.debug("Found {} job execution(s) for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob, result.size()); return result; } } CachedJobExecutionProvider(JobExecutionAspect executionAspect, AllJobExecutionProvider allJobExecutionProvider,
                                      @Value("${com.github.chrisgleissner.springbatchrest.jobExecutionCacheSize:100}") int jobExecutionCacheSize); @Override Collection<JobExecution> getJobExecutions(Optional<String> jobNameRegexp, Optional<String> exitCode, int limitPerJob); @Override void accept(JobExecution je); }
CachedJobExecutionProvider implements Consumer<JobExecution>, JobExecutionProvider { @Override public Collection<JobExecution> getJobExecutions(Optional<String> jobNameRegexp, Optional<String> exitCode, int limitPerJob) { if (limitPerJob > this.cacheSize) return allJobExecutionProvider.getJobExecutions(jobNameRegexp, exitCode, limitPerJob); else { log.debug("Getting job executions from cache for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob); Optional<Pattern> maybeJobNamePattern = jobNameRegexp.map(Pattern::compile); TreeSet<JobExecution> result = new TreeSet(byDescendingTime()); jobExecutionsByJobName.entrySet().stream() .filter(e -> maybeJobNamePattern.map(p -> p.matcher(e.getKey()).matches()).orElse(true)) .map(Map.Entry::getValue) .flatMap(je -> je.getJobExecutions(exitCode).stream().sorted(byDescendingTime()).limit(limitPerJob)) .forEach(result::add); log.debug("Found {} job execution(s) for jobNameRegexp={}, exitCode={}, limitPerJob={}", jobNameRegexp, exitCode, limitPerJob, result.size()); return result; } } CachedJobExecutionProvider(JobExecutionAspect executionAspect, AllJobExecutionProvider allJobExecutionProvider,
                                      @Value("${com.github.chrisgleissner.springbatchrest.jobExecutionCacheSize:100}") int jobExecutionCacheSize); @Override Collection<JobExecution> getJobExecutions(Optional<String> jobNameRegexp, Optional<String> exitCode, int limitPerJob); @Override void accept(JobExecution je);  }