StatsService.java

1
package edu.ucsb.cs156.diningcachingproxy.services;
2
3
import java.util.concurrent.atomic.AtomicLong;
4
import org.springframework.stereotype.Service;
5
6
/**
7
 * In-memory counters tracking cache performance since the proxy was started up. Reset on restart —
8
 * durable persistence of these stats may come later.
9
 */
10
@Service
11
public class StatsService {
12
13
  private final AtomicLong totalRequests = new AtomicLong(0);
14
  private final AtomicLong cacheHits = new AtomicLong(0);
15
  private final AtomicLong cacheMisses = new AtomicLong(0);
16
17
  public void recordHit() {
18
    totalRequests.incrementAndGet();
19
    cacheHits.incrementAndGet();
20
  }
21
22
  public void recordMiss() {
23
    totalRequests.incrementAndGet();
24
    cacheMisses.incrementAndGet();
25
  }
26
27
  public long getTotalRequests() {
28 1 1. getTotalRequests : replaced long return with 0 for edu/ucsb/cs156/diningcachingproxy/services/StatsService::getTotalRequests → KILLED
    return totalRequests.get();
29
  }
30
31
  public long getCacheHits() {
32 1 1. getCacheHits : replaced long return with 0 for edu/ucsb/cs156/diningcachingproxy/services/StatsService::getCacheHits → KILLED
    return cacheHits.get();
33
  }
34
35
  public long getCacheMisses() {
36 1 1. getCacheMisses : replaced long return with 0 for edu/ucsb/cs156/diningcachingproxy/services/StatsService::getCacheMisses → KILLED
    return cacheMisses.get();
37
  }
38
39
  public double getHitRatePercentage() {
40
    long total = totalRequests.get();
41 1 1. getHitRatePercentage : negated conditional → KILLED
    if (total == 0) {
42
      return 0.0;
43
    }
44 3 1. getHitRatePercentage : replaced double return with 0.0d for edu/ucsb/cs156/diningcachingproxy/services/StatsService::getHitRatePercentage → KILLED
2. getHitRatePercentage : Replaced double multiplication with division → KILLED
3. getHitRatePercentage : Replaced double division with multiplication → KILLED
    return 100.0 * cacheHits.get() / total;
45
  }
46
}

Mutations

28

1.1
Location : getTotalRequests
Killed by : edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests]/[method:recordMiss_increments_total_and_misses()]
replaced long return with 0 for edu/ucsb/cs156/diningcachingproxy/services/StatsService::getTotalRequests → KILLED

32

1.1
Location : getCacheHits
Killed by : edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests]/[method:recordHit_increments_total_and_hits()]
replaced long return with 0 for edu/ucsb/cs156/diningcachingproxy/services/StatsService::getCacheHits → KILLED

36

1.1
Location : getCacheMisses
Killed by : edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests]/[method:recordMiss_increments_total_and_misses()]
replaced long return with 0 for edu/ucsb/cs156/diningcachingproxy/services/StatsService::getCacheMisses → KILLED

41

1.1
Location : getHitRatePercentage
Killed by : edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests]/[method:starts_at_zero_with_zero_hit_rate()]
negated conditional → KILLED

44

1.1
Location : getHitRatePercentage
Killed by : edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests]/[method:hit_rate_percentage_is_computed_correctly()]
replaced double return with 0.0d for edu/ucsb/cs156/diningcachingproxy/services/StatsService::getHitRatePercentage → KILLED

2.2
Location : getHitRatePercentage
Killed by : edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests]/[method:hit_rate_percentage_is_computed_correctly()]
Replaced double multiplication with division → KILLED

3.3
Location : getHitRatePercentage
Killed by : edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.services.StatsServiceTests]/[method:hit_rate_percentage_is_computed_correctly()]
Replaced double division with multiplication → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1