ResolveHostnameJob.java

1
package edu.ucsb.cs156.diningcachingproxy.jobs;
2
3
import edu.ucsb.cs156.diningcachingproxy.services.HostTrackingService;
4
import edu.ucsb.cs156.jobs.services.JobContext;
5
import edu.ucsb.cs156.jobs.services.JobContextConsumer;
6
import java.net.InetAddress;
7
import java.net.UnknownHostException;
8
import lombok.Builder;
9
10
/**
11
 * Attempts a reverse DNS lookup for one IP address, updating {@link HostTrackingService} with the
12
 * result (the resolved hostname, or the address itself if resolution fails). Runs asynchronously
13
 * via {@code JobService} - reverse DNS is a blocking network call with no built-in timeout, so it
14
 * must never run inline in the proxy's request path.
15
 */
16
@Builder
17
public class ResolveHostnameJob implements JobContextConsumer {
18
19
  private String ipAddress;
20
  private HostTrackingService hostTrackingService;
21
22
  @Override
23
  public void accept(JobContext ctx) throws Exception {
24 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
    ctx.log("Resolving hostname for " + ipAddress);
25
    String hostname = resolveHostname(ipAddress);
26 1 1. accept : removed call to edu/ucsb/cs156/diningcachingproxy/services/HostTrackingService::resolveHostname → KILLED
    hostTrackingService.resolveHostname(ipAddress, hostname);
27 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
    ctx.log("Resolved " + ipAddress + " to " + hostname);
28
  }
29
30
  private String resolveHostname(String remoteAddress) {
31
    try {
32
      String hostname = InetAddress.getByName(remoteAddress).getCanonicalHostName();
33
      // getCanonicalHostName() doesn't throw when reverse DNS fails - it falls back to
34
      // returning the address's own textual form, which we detect here.
35 2 1. resolveHostname : negated conditional → KILLED
2. resolveHostname : replaced return value with "" for edu/ucsb/cs156/diningcachingproxy/jobs/ResolveHostnameJob::resolveHostname → KILLED
      return hostname.equals(remoteAddress) ? remoteAddress : hostname;
36
    } catch (UnknownHostException e) {
37 1 1. resolveHostname : replaced return value with "" for edu/ucsb/cs156/diningcachingproxy/jobs/ResolveHostnameJob::resolveHostname → KILLED
      return remoteAddress;
38
    }
39
  }
40
}

Mutations

24

1.1
Location : accept
Killed by : edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests]/[method:resolves_a_loopback_address_and_updates_the_host_tracking_service()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

26

1.1
Location : accept
Killed by : edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests]/[method:falls_back_to_the_raw_address_when_reverse_dns_resolution_fails()]
removed call to edu/ucsb/cs156/diningcachingproxy/services/HostTrackingService::resolveHostname → KILLED

27

1.1
Location : accept
Killed by : edu.ucsb.cs156.diningcachingproxy.DiningProxyIntegrationTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.DiningProxyIntegrationTests]/[method:a_cache_miss_is_stored_and_a_repeat_request_is_served_from_the_cache()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

35

1.1
Location : resolveHostname
Killed by : edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests]/[method:resolves_a_loopback_address_and_updates_the_host_tracking_service()]
negated conditional → KILLED

2.2
Location : resolveHostname
Killed by : edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests]/[method:resolves_a_loopback_address_and_updates_the_host_tracking_service()]
replaced return value with "" for edu/ucsb/cs156/diningcachingproxy/jobs/ResolveHostnameJob::resolveHostname → KILLED

37

1.1
Location : resolveHostname
Killed by : edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.jobs.ResolveHostnameJobTests]/[method:falls_back_to_the_raw_address_when_reverse_dns_resolution_fails()]
replaced return value with "" for edu/ucsb/cs156/diningcachingproxy/jobs/ResolveHostnameJob::resolveHostname → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1