JobService.java

1
package edu.ucsb.cs156.example.services.jobs;
2
3
import edu.ucsb.cs156.example.entities.Job;
4
import edu.ucsb.cs156.example.repositories.JobsRepository;
5
import edu.ucsb.cs156.example.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
  @Autowired private JobContextFactory jobContextFactory;
19
20
  public Job runAsJob(JobContextConsumer jobFunction) {
21
    Job job = Job.builder().createdBy(currentUserService.getUser()).status("running").build();
22
23
    jobsRepository.save(job);
24 1 1. runAsJob : removed call to edu/ucsb/cs156/example/services/jobs/JobService::runJobAsync → KILLED
    self.runJobAsync(job, jobFunction);
25
26 1 1. runAsJob : replaced return value with null for edu/ucsb/cs156/example/services/jobs/JobService::runAsJob → KILLED
    return job;
27
  }
28
29
  @Async
30
  public void runJobAsync(Job job, JobContextConsumer jobFunction) {
31
    JobContext context = jobContextFactory.createContext(job);
32
33
    try {
34 1 1. runJobAsync : removed call to edu/ucsb/cs156/example/services/jobs/JobContextConsumer::accept → KILLED
      jobFunction.accept(context);
35
    } catch (Exception e) {
36 1 1. runJobAsync : removed call to edu/ucsb/cs156/example/entities/Job::setStatus → KILLED
      job.setStatus("error");
37
      context.log(e.getMessage());
38
      return;
39
    }
40
41 1 1. runJobAsync : removed call to edu/ucsb/cs156/example/entities/Job::setStatus → KILLED
    job.setStatus("complete");
42
    jobsRepository.save(job);
43
  }
44
45
  public String getJobLogs(Long jobId) {
46
    Job job =
47
        jobsRepository
48
            .findById(jobId)
49 1 1. lambda$getJobLogs$0 : replaced return value with null for edu/ucsb/cs156/example/services/jobs/JobService::lambda$getJobLogs$0 → KILLED
            .orElseThrow(() -> new IllegalArgumentException("Job not found"));
50
51
    String log = job.getLog();
52 1 1. getJobLogs : negated conditional → KILLED
    return log != null ? log : "";
53
  }
54
}

Mutations

24

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

26

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

34

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

36

1.1
Location : runJobAsync
Killed by : edu.ucsb.cs156.example.services.JobServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.services.JobServiceTests]/[method:runAsyncJob_handles_error()]
removed call to edu/ucsb/cs156/example/entities/Job::setStatus → KILLED

41

1.1
Location : runJobAsync
Killed by : edu.ucsb.cs156.example.services.JobServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.services.JobServiceTests]/[method:runAsyncJob_fires_correctly()]
removed call to edu/ucsb/cs156/example/entities/Job::setStatus → KILLED

49

1.1
Location : lambda$getJobLogs$0
Killed by : edu.ucsb.cs156.example.services.JobServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.services.JobServiceTests]/[method:test_getJobLogs_job_not_found()]
replaced return value with null for edu/ucsb/cs156/example/services/jobs/JobService::lambda$getJobLogs$0 → KILLED

52

1.1
Location : getJobLogs
Killed by : edu.ucsb.cs156.example.services.JobServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.services.JobServiceTests]/[method:test_getJobLogs_with_null_log()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0