EvictStaleCachedResponsesJobFactory.java

1
package edu.ucsb.cs156.diningcachingproxy.services;
2
3
import edu.ucsb.cs156.diningcachingproxy.collections.CachedResponseRepository;
4
import edu.ucsb.cs156.diningcachingproxy.jobs.EvictStaleCachedResponsesJob;
5
import edu.ucsb.cs156.jobs.entities.Job;
6
import edu.ucsb.cs156.jobs.services.JobService;
7
import java.time.Clock;
8
import java.time.Duration;
9
import java.time.Instant;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Value;
12
import org.springframework.stereotype.Service;
13
14
/**
15
 * Builds and launches an {@link EvictStaleCachedResponsesJob}. Shared by the nightly scheduled run
16
 * and the admin's manual trigger, so there's exactly one place that turns "max age in days" into a
17
 * cutoff instant.
18
 */
19
@Service
20
public class EvictStaleCachedResponsesJobFactory {
21
22
  @Autowired private CachedResponseRepository cachedResponseRepository;
23
  @Autowired private JobService jobService;
24
  @Autowired private Clock clock;
25
26
  @Value("${app.cache.eviction.max-age-days:30}")
27
  private int defaultMaxAgeDays;
28
29
  /** Launches an eviction run using the configured default max age. */
30
  public Job launch() {
31 1 1. launch : replaced return value with null for edu/ucsb/cs156/diningcachingproxy/services/EvictStaleCachedResponsesJobFactory::launch → KILLED
    return launch(defaultMaxAgeDays);
32
  }
33
34
  /**
35
   * Launches an eviction run that deletes every entry not accessed in the last {@code maxAgeDays}
36
   * days. Zero is allowed and evicts everything not accessed as of right now.
37
   */
38
  public Job launch(int maxAgeDays) {
39 2 1. launch : changed conditional boundary → KILLED
2. launch : negated conditional → KILLED
    if (maxAgeDays < 0) {
40
      throw new IllegalArgumentException("maxAgeDays must be >= 0, was " + maxAgeDays);
41
    }
42
    Instant cutoff = clock.instant().minus(Duration.ofDays(maxAgeDays));
43
    EvictStaleCachedResponsesJob job =
44
        EvictStaleCachedResponsesJob.builder()
45
            .cachedResponseRepository(cachedResponseRepository)
46
            .cutoff(cutoff)
47
            .build();
48 1 1. launch : replaced return value with null for edu/ucsb/cs156/diningcachingproxy/services/EvictStaleCachedResponsesJobFactory::launch → KILLED
    return jobService.runAsJob(job);
49
  }
50
}

Mutations

31

1.1
Location : launch
Killed by : edu.ucsb.cs156.diningcachingproxy.services.EvictStaleCachedResponsesJobFactoryTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.EvictStaleCachedResponsesJobFactoryTests]/[method:launch_with_no_argument_uses_the_configured_default_max_age()]
replaced return value with null for edu/ucsb/cs156/diningcachingproxy/services/EvictStaleCachedResponsesJobFactory::launch → KILLED

39

1.1
Location : launch
Killed by : edu.ucsb.cs156.diningcachingproxy.services.EvictStaleCachedResponsesJobFactoryTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.EvictStaleCachedResponsesJobFactoryTests]/[method:launch_with_zero_max_age_uses_now_as_the_cutoff()]
changed conditional boundary → KILLED

2.2
Location : launch
Killed by : edu.ucsb.cs156.diningcachingproxy.services.EvictStaleCachedResponsesJobFactoryTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.EvictStaleCachedResponsesJobFactoryTests]/[method:launch_with_a_negative_max_age_throws_and_launches_nothing()]
negated conditional → KILLED

48

1.1
Location : launch
Killed by : edu.ucsb.cs156.diningcachingproxy.services.EvictStaleCachedResponsesJobFactoryTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.EvictStaleCachedResponsesJobFactoryTests]/[method:launch_with_an_explicit_max_age_computes_the_cutoff_from_it()]
replaced return value with null for edu/ucsb/cs156/diningcachingproxy/services/EvictStaleCachedResponsesJobFactory::launch → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1