JobService.java

1
package edu.ucsb.cs156.courses.services.jobs;
2
3
import edu.ucsb.cs156.courses.entities.Job;
4
import edu.ucsb.cs156.courses.repositories.JobsRepository;
5
import edu.ucsb.cs156.courses.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 private JobsRepository jobsRepository;
14
15
  @Autowired private CurrentUserService currentUserService;
16
17
  @Lazy @Autowired private JobService self;
18
19
  public Job runAsJob(JobContextConsumer jobFunction) {
20
    Job job = Job.builder().createdBy(currentUserService.getUser()).status("running").build();
21
22
    jobsRepository.save(job);
23 1 1. runAsJob : removed call to edu/ucsb/cs156/courses/services/jobs/JobService::runJobAsync → KILLED
    self.runJobAsync(job, jobFunction);
24
25 1 1. runAsJob : replaced return value with null for edu/ucsb/cs156/courses/services/jobs/JobService::runAsJob → KILLED
    return job;
26
  }
27
28
  @Async
29
  public void runJobAsync(Job job, JobContextConsumer jobFunction) {
30
    JobContext context = new JobContext(jobsRepository, job);
31
32
    try {
33 1 1. runJobAsync : removed call to edu/ucsb/cs156/courses/services/jobs/JobContextConsumer::accept → KILLED
      jobFunction.accept(context);
34
    } catch (Exception e) {
35 1 1. runJobAsync : removed call to edu/ucsb/cs156/courses/entities/Job::setStatus → TIMED_OUT
      job.setStatus("error");
36 1 1. runJobAsync : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → TIMED_OUT
      context.log(e.getMessage());
37
      return;
38
    }
39
40 1 1. runJobAsync : removed call to edu/ucsb/cs156/courses/entities/Job::setStatus → TIMED_OUT
    job.setStatus("complete");
41
    jobsRepository.save(job);
42
  }
43
}

Mutations

23

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

25

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

33

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

35

1.1
Location : runJobAsync
Killed by : none
removed call to edu/ucsb/cs156/courses/entities/Job::setStatus → TIMED_OUT

36

1.1
Location : runJobAsync
Killed by : none
removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → TIMED_OUT

40

1.1
Location : runJobAsync
Killed by : none
removed call to edu/ucsb/cs156/courses/entities/Job::setStatus → TIMED_OUT

Active mutators

Tests examined


Report generated by PIT 1.17.0