WorkerService { public WorkerModel getWorker(String name) throws NotFoundException { return workerDao.findByName(name) .map(WorkerMapper::mapWorker) .orElseThrow(NotFoundException::new); }  String registerWorker(); @Transactional void onHeartbeat(String name); void scheduleJobBuild(Build build, String stageName, Job job); @Transactional void assignJobBuildToWorker(JobBuild jobBuild); List<WorkerModel> getWorkers(int page, int size); WorkerModel getWorker(String name); @Transactional void deleteWorker(String name); @Transactional void readyWorker(Optional<Worker> workerOptional);  }
@Test public void shouldAssignWorker() { JobBuild jobBuild = new JobBuild(); Build build = buildDao.save(new Build()); jobBuild.setBuild(build); jobBuild = jobBuildDao.save(jobBuild); Worker worker = workerDao.save(new Worker()); sleep(2, TimeUnit.SECONDS); jobBuild = jobBuildDao.findOne(jobBuild.getId()); worker = workerDao.findOne(worker.getId()); assertThat(jobBuild.getWorker()).isNotNull(); assertThat(jobBuild.getWorker().getId()).isEqualTo(worker.getId()); assertThat(worker.getStatus()).isEqualTo(Worker.Status.BUSY); }