JobService.java

1
package edu.ucsb.cs156.happiercows.services.jobs;
2
3
import edu.ucsb.cs156.happiercows.entities.jobs.Job;
4
import edu.ucsb.cs156.happiercows.repositories.jobs.JobsRepository;
5
import edu.ucsb.cs156.happiercows.services.CurrentUserService;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.context.annotation.Lazy;
8
import org.springframework.scheduling.annotation.Async;
9
import org.springframework.stereotype.Service;
10
11
@Service
12
public class JobService {
13
  @Autowired
14
  private JobsRepository jobsRepository;
15
16
  @Autowired
17
  private CurrentUserService currentUserService;
18
19
  @Lazy
20
  @Autowired
21
  private JobService self;
22
23
  public Job runAsJob(JobContextConsumer jobFunction) {
24
    Job job = Job.builder()
25
      .createdBy(currentUserService.getUser())
26
      .status("running")
27
      .build();
28
29
    jobsRepository.save(job);
30 1 1. runAsJob : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobService::runJobAsync → KILLED
    self.runJobAsync(job, jobFunction);
31 1 1. runAsJob : replaced return value with null for edu/ucsb/cs156/happiercows/services/jobs/JobService::runAsJob → KILLED
    return job;
32
  }
33
34
  @Async
35
  public void runJobAsync(Job job, JobContextConsumer jobFunction) {
36
    JobContext context = new JobContext(jobsRepository, job);
37
38
    try {
39 1 1. runJobAsync : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContextConsumer::accept → KILLED
      jobFunction.accept(context);
40
    } catch (Exception e) {
41
      e.printStackTrace();
42 1 1. runJobAsync : removed call to edu/ucsb/cs156/happiercows/entities/jobs/Job::setStatus → KILLED
      job.setStatus("error");
43
      context.log(e.getMessage());
44
      return;
45
    }
46
47 1 1. runJobAsync : removed call to edu/ucsb/cs156/happiercows/entities/jobs/Job::setStatus → KILLED
    job.setStatus("complete");
48
    jobsRepository.save(job);
49
  }
50
}

Mutations

30

1.1
Location : runAsJob
Killed by : edu.ucsb.cs156.happiercows.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.JobsControllerTests]/[method:admin_can_launch_test_job()]
removed call to edu/ucsb/cs156/happiercows/services/jobs/JobService::runJobAsync → KILLED

31

1.1
Location : runAsJob
Killed by : edu.ucsb.cs156.happiercows.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.JobsControllerTests]/[method:admin_can_launch_milk_the_cows_job()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/jobs/JobService::runAsJob → KILLED

39

1.1
Location : runJobAsync
Killed by : edu.ucsb.cs156.happiercows.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.JobsControllerTests]/[method:admin_can_launch_test_job()]
removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContextConsumer::accept → KILLED

42

1.1
Location : runJobAsync
Killed by : edu.ucsb.cs156.happiercows.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.JobsControllerTests]/[method:admin_can_launch_test_job_that_fails()]
removed call to edu/ucsb/cs156/happiercows/entities/jobs/Job::setStatus → KILLED

47

1.1
Location : runJobAsync
Killed by : edu.ucsb.cs156.happiercows.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.JobsControllerTests]/[method:admin_can_launch_test_job()]
removed call to edu/ucsb/cs156/happiercows/entities/jobs/Job::setStatus → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3