JobService { public void appendMessage(final String jobId, final JobMessage jobMessage) { writeMessageAndStatus(jobId, jobMessage.getLevel(), jobMessage.getMessage(), jobMessage.getLevel() == Level.ERROR ? ERROR : null, jobMessage.getTimestamp()); } JobService();   JobService(final JobRepository jobRepository,
               final JobMetaService jobMetaService,
               final List<JobRunnable> jobRunnables,
               final ScheduledExecutorService executor,
               final ApplicationEventPublisher applicationEventPublisher,
               final Clock clock,
               final SystemInfo systemInfo,
               final UuidProvider uuidProvider); @PostConstruct void postConstruct(); Optional<String> startAsyncJob(String jobType); Optional<JobInfo> findJob(final String id); List<JobInfo> findJobs(final Optional<String> type, final int count); List<JobInfo> findJobsDistinct(); void deleteJobs(final Optional<String> type); void stopJob(final String jobId); void killJobsDeadSince(final int seconds); void killJob(final String jobId); void appendMessage(final String jobId,
                              final JobMessage jobMessage); void keepAlive(final String jobId); void markSkipped(final String jobId); void markRestarted(final String jobId); void handleTooBigJobLogs();  }
@Test public void shouldAppendNonErrorMessage() { JobMessage message = JobMessage.jobMessage(Level.INFO, "This is an interesting message", OffsetDateTime.now()); jobService.appendMessage(JOB_ID, message); verify(jobRepository).appendMessage(JOB_ID, message); verify(jobRepository, never()).createOrUpdate(any(JobInfo.class)); }
@Test public void shouldAppendErrorMessageAndSetErrorStatus() { OffsetDateTime now = OffsetDateTime.now(clock); OffsetDateTime earlier = now.minus(10, MINUTES); JobMessage message = JobMessage.jobMessage(Level.ERROR, "Error: Out of hunk", now); JobInfo jobInfo = defaultJobInfo() .setLastUpdated(earlier) .build(); when(jobRepository.findOne(JOB_ID)).thenReturn(Optional.of(jobInfo)); jobService.appendMessage(JOB_ID, message); verify(jobRepository).appendMessage(JOB_ID, message); verify(jobRepository).setJobStatus(JOB_ID, JobInfo.JobStatus.ERROR); }
@Test public void shouldNotChangeStatusToOKWhenOnlyAppendingAMessage() { OffsetDateTime now = OffsetDateTime.now(clock); OffsetDateTime earlier = now.minus(10, MINUTES); JobMessage message = JobMessage.jobMessage(Level.INFO, "Some info message", now); JobInfo jobInfo = defaultJobInfo() .setLastUpdated(earlier) .setStatus(JobInfo.JobStatus.SKIPPED) .build(); when(jobRepository.findOne(JOB_ID)).thenReturn(Optional.of(jobInfo)); jobService.appendMessage(JOB_ID, message); verify(jobRepository).appendMessage(JOB_ID, message); verifyNoMoreInteractions(jobRepository); }