Trace { public long calculateDuration() { if (!nodes.isEmpty()) { long endTime = 0; for (int i = 0; i < getNodes().size(); i++) { Node node = getNodes().get(i); long nodeEndTime = node.overallEndTime(); if (nodeEndTime > endTime) { endTime = nodeEndTime; } } return endTime - getNodes().get(0).getTimestamp(); } return 0L; } Trace(); String getTraceId(); Trace setTraceId(String traceId); String getFragmentId(); Trace setFragmentId(String fragmentId); long getTimestamp(); Trace setTimestamp(long timestamp); String getTransaction(); Trace setTransaction(String name); String getHostName(); Trace setHostName(String hostName); String getHostAddress(); Trace setHostAddress(String hostAddress); List<Node> getNodes(); Trace setNodes(List<Node> nodes); Set<Property> allProperties(); boolean hasProperty(String name); Set<Property> getProperties(String name); boolean initialFragment(); long endTime(); long calculateDuration(); Set<Node> getCorrelatedNodes(CorrelationIdentifier cid); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testCalculateDuration() { long baseTime = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); Trace trace1 = new Trace(); trace1.setFragmentId("1"); trace1.setTransaction("testapp"); trace1.setTimestamp(baseTime); Consumer c1 = new Consumer(); c1.setUri("originuri"); c1.setDuration(1000000); c1.setTimestamp(100000); Producer p1 = new Producer(); p1.setUri("testuri"); p1.setDuration(1000000); p1.setTimestamp(500000); p1.addInteractionCorrelationId("interaction1"); c1.getNodes().add(p1); trace1.getNodes().add(c1); long duration = trace1.calculateDuration(); assertEquals(1400000, duration); }