JobBuildService { @Transactional public void reportFailure(Long id, String fullLog) { JobBuild jobBuild = jobBuildDao.findOne(id); log.info("Reporting failure on {}", id); if (jobBuild != null) { if (!jobBuild.getStatus().equals(JobBuild.Status.STOPPED)) { jobBuild.setStatus(JobBuild.Status.FAILED); } clearJob(fullLog, jobBuild); updateBuildStatus(jobBuild.getBuild()); } }  @Transactional void prepareJobs(Build build, Dickfile dickfile); @Transactional void buildStage(Build build, Dickfile dickfile, Stage stage); @Transactional Optional<BuildOrder> peekBuildFor(String workerName); boolean isStopped(Long id); @Transactional void reportProgress(Long id, String partialLog); @Transactional void reportFailure(Long id, String fullLog); @Transactional void reportSuccess(Long id, String fullLog); Build.Status updateBuildStatus(Build build); @Transactional void stop(Build build); @Transactional List<LogChunkModel> getLogChunks(Long id, Date creationDate); @Transactional OutputModel getOutput(Long id); @Transactional void deleteJobBuilds(Build build);  }
@Test public void shouldNotSetFailureStatusBecauseJobNotCompleted() { Worker worker = produceWorker(Worker.Status.BUSY); Build build = produceBuild(); JobBuild jobBuild = produceJobBuild(worker, build, JobBuild.Status.IN_PROGRESS); produceJobBuild(worker, build, JobBuild.Status.IN_PROGRESS); jobBuildService.reportFailure(jobBuild.getId(), "foo"); jobBuild = jobBuildDao.findOne(jobBuild.getId()); worker = workerDao.findByName(jobBuild.getWorkerName()).get(); assertThat(jobBuild.getStatus()).isEqualTo(JobBuild.Status.FAILED); assertThat(jobBuild.getWorker()).isNull(); assertThat(worker.getStatus()).isEqualTo(Worker.Status.READY); assertThat(jobBuild.getBuild().getStatus()).isEqualTo(Build.Status.IN_PROGRESS); }