NodeDetailsDeriver extends AbstractProcessor<Trace, NodeDetails> { protected long calculateActualTime(Node n) { long childElapsed = 0; if (n.containerNode()) { long startTime=n.getTimestamp() + n.getDuration(); long endTime = n.getTimestamp(); for (int i = 0; i < ((ContainerNode) n).getNodes().size(); i++) { Node child = ((ContainerNode) n).getNodes().get(i); if (child.getTimestamp() < startTime) { startTime = child.getTimestamp(); } if (endTime < (child.getTimestamp() + child.getDuration())) { endTime = child.getTimestamp() + child.getDuration(); } childElapsed += child.getDuration(); } if (childElapsed > n.getDuration()) { childElapsed = endTime - startTime; if (childElapsed < 0 || childElapsed > n.getDuration()) { childElapsed = 0; } } else if (endTime > n.getTimestamp() + n.getDuration()) { childElapsed = 0; } } return n.getDuration() - childElapsed; } NodeDetailsDeriver(); @Override List<NodeDetails> processOneToMany(String tenantId, Trace item);  }
@Test public void testCalculateActualTimeSync() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Consumer consumer = new Consumer(); consumer.setTimestamp(1000); consumer.setDuration(500); Component component1 = new Component(); component1.setTimestamp(1100); component1.setDuration(200); consumer.getNodes().add(component1); Component component2 = new Component(); component2.setTimestamp(1300); component2.setDuration(200); consumer.getNodes().add(component2); assertEquals(100, deriver.calculateActualTime(consumer)); }
@Test public void testCalculateActualTimeForkJoin() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Consumer consumer = new Consumer(); consumer.setTimestamp(1000); consumer.setDuration(500); Component component1 = new Component(); component1.setTimestamp(1100); component1.setDuration(250); consumer.getNodes().add(component1); Component component2 = new Component(); component2.setTimestamp(1100); component2.setDuration(300); consumer.getNodes().add(component2); assertEquals(200, deriver.calculateActualTime(consumer)); }
@Test public void testCalculateActualTimeAsync() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Consumer consumer = new Consumer(); consumer.setTimestamp(1000); consumer.setDuration(500); Component component1 = new Component(); component1.setTimestamp(1100); component1.setDuration(550); consumer.getNodes().add(component1); Component component2 = new Component(); component2.setTimestamp(1100); component2.setDuration(700); consumer.getNodes().add(component2); assertEquals(consumer.getDuration(), deriver.calculateActualTime(consumer)); }
@Test public void testCalculateActualTimeAsync2() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Consumer consumer = new Consumer(); consumer.setTimestamp(1000); consumer.setDuration(500); Component component1 = new Component(); component1.setTimestamp(1200); component1.setDuration(400); consumer.getNodes().add(component1); assertEquals(consumer.getDuration(), deriver.calculateActualTime(consumer)); }