JobService.java

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

Mutations

25

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

27

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

37

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

42

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

50

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

53

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

Active mutators

Tests examined


Report generated by PIT 1.17.0