### Question:
NetworkLatency implements ModelRunner { public static Map<Name, Set<Double>> calculate(Graph graph) { Map<Name, Set<Double>> results = new LinkedHashMap<>(); TraceTraversal<Vertex, Vertex> clientSpans = graph.traversal(TraceTraversalSource.class) .hasTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); clientSpans.forEachRemaining(client -> { String clientService = (String)client.property(Keys.SERVICE_NAME).value(); for (Vertex child : Util.children(client)) { if (child.property(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).isPresent()) { String serverService = (String)child.property(Keys.SERVICE_NAME).value(); Long clientStartTime = (Long)client.property(Keys.START_TIME).value(); Long serverStartTime = (Long)child.property(Keys.START_TIME).value(); Long latency = serverStartTime - clientStartTime; Name name = new Name(clientService, serverService); Set<Double> latencies = results.get(name); if (latencies == null) { latencies = new LinkedHashSet<>(); results.put(name, latencies); } latencies.add(latency/(1000.0*1000.0)); } } }); return results; }  void runWithMetrics(Graph graph); static Map<Name, Set<Double>> calculate(Graph graph);  }### Answer:
@Test public void calculate() { Span root = Util.newTrace("root", "root"); Span child = Util.newChild("gandalf", "child", root); child.startTimeMicros = 10000000; child.tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); Span childChild = Util.newChild("frodo", "childChild", child); childChild.startTimeMicros = 15000000; childChild.tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); Span childChild2 = Util.newChild("frodo2", "childChild2", child); childChild2.startTimeMicros = 20000000; childChild2.tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); Span child2 = Util.newChild("gandalf", "child2", root); child2.tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); child2.startTimeMicros = 20000000; Span child3 = Util.newChild("gandalf", "child3", root); child3.tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); child3.startTimeMicros = 25000000; Span childChild3 = Util.newChild("faramir", "childChild3", child3); childChild3.startTimeMicros = 50000000; childChild3.tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); Trace trace = new Trace(); trace.spans = Arrays.asList(root, child, child2, child3, childChild, childChild2 ,childChild3); Graph graph = GraphCreator.create(trace); Map<Name, Set<Double>> results = NetworkLatency.calculate(graph); Assert.assertEquals(3, results.size()); Set<Double> latencies = results.get(new Name("gandalf", "frodo")); Assert.assertEquals(1, latencies.size()); Assert.assertEquals(5, latencies.iterator().next(), 0.0); latencies = results.get(new Name("gandalf", "frodo2")); Assert.assertEquals(1, latencies.size()); Assert.assertEquals(10, latencies.iterator().next(), 0.0); latencies = results.get(new Name ("gandalf", "faramir")); Assert.assertEquals(1, latencies.size()); Assert.assertEquals(25, latencies.iterator().next(), 0.0); }