JobService.java

1
package edu.ucsb.cs156.organic.services.jobs;
2
3
import edu.ucsb.cs156.organic.entities.jobs.Job;
4
import edu.ucsb.cs156.organic.repositories.jobs.JobsRepository;
5
import edu.ucsb.cs156.organic.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, long id) {
24
    Job job = Job.builder()
25
      .createdBy(currentUserService.getUser())
26
      .status("running")
27
      .id(id)
28
      .build();
29
30
    jobsRepository.save(job);
31 1 1. runAsJob : removed call to edu/ucsb/cs156/organic/services/jobs/JobService::runJobAsync → TIMED_OUT
    self.runJobAsync(job, jobFunction);
32 1 1. runAsJob : replaced return value with null for edu/ucsb/cs156/organic/services/jobs/JobService::runAsJob → KILLED
    return job;
33
  }
34
35
  @Async
36
  public void runJobAsync(Job job, JobContextConsumer jobFunction) {
37
    JobContext context = new JobContext(jobsRepository, job);
38
39
    try {
40 1 1. runJobAsync : removed call to edu/ucsb/cs156/organic/services/jobs/JobContextConsumer::accept → TIMED_OUT
      jobFunction.accept(context);
41
    } catch (Exception e) {
42
      e.printStackTrace();
43 1 1. runJobAsync : removed call to edu/ucsb/cs156/organic/entities/jobs/Job::setStatus → TIMED_OUT
      job.setStatus("error");
44
      context.log(e.getMessage());
45
      return;
46
    }
47
48 1 1. runJobAsync : removed call to edu/ucsb/cs156/organic/entities/jobs/Job::setStatus → KILLED
    job.setStatus("complete");
49
    jobsRepository.save(job);
50
  }
51
}

Mutations

31

1.1
Location : runAsJob
Killed by : none
removed call to edu/ucsb/cs156/organic/services/jobs/JobService::runJobAsync → TIMED_OUT

32

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

40

1.1
Location : runJobAsync
Killed by : none
removed call to edu/ucsb/cs156/organic/services/jobs/JobContextConsumer::accept → TIMED_OUT

43

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

48

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

Active mutators

Tests examined


Report generated by PIT 1.7.3