JobRateLimit.java

1
package edu.ucsb.cs156.jobs.services;
2
3
import lombok.Getter;
4
import lombok.extern.slf4j.Slf4j;
5
6
/**
7
 * Configurable delay for rate limiting calls to external APIs from inside jobs. Configured via the
8
 * {@code app.jobs.rate-limit-ms} property; invalid or negative values fall back to a 200 ms default
9
 * with a warning.
10
 */
11
@Slf4j
12
public class JobRateLimit {
13
  public static final int DEFAULT_RATE_LIMIT_MS = 200;
14
15
  @Getter private int rateLimitMs;
16
17
  public JobRateLimit(String rateLimitMsString) {
18
    try {
19
      rateLimitMs = Integer.parseInt(rateLimitMsString);
20 2 1. <init> : negated conditional → KILLED
2. <init> : changed conditional boundary → KILLED
      if (rateLimitMs < 0) {
21
        throw new NumberFormatException("negative value");
22
      }
23
    } catch (NumberFormatException e) {
24
      rateLimitMs = DEFAULT_RATE_LIMIT_MS;
25
      log.warn(
26
          "Invalid app.jobs.rate-limit-ms value: {}; using default of {} ms",
27
          rateLimitMsString,
28
          rateLimitMs);
29
    }
30
  }
31
32
  public void sleep() throws InterruptedException {
33 1 1. sleep : removed call to java/lang/Thread::sleep → KILLED
    Thread.sleep(rateLimitMs);
34
  }
35
}

Mutations

20

1.1
Location : <init>
Killed by : edu.ucsb.cs156.jobs.services.JobRateLimitTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.jobs.services.JobRateLimitTests]/[method:negative_value_falls_back_to_default()]
negated conditional → KILLED

2.2
Location : <init>
Killed by : edu.ucsb.cs156.jobs.services.JobRateLimitTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.jobs.services.JobRateLimitTests]/[method:zero_is_a_valid_value()]
changed conditional boundary → KILLED

33

1.1
Location : sleep
Killed by : edu.ucsb.cs156.jobs.services.JobRateLimitTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.jobs.services.JobRateLimitTests]/[method:sleep_waits_at_least_the_configured_delay()]
removed call to java/lang/Thread::sleep → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0