CommunicationDetailsDeriver extends AbstractProcessor<Trace, CommunicationDetails> { protected static long calculateLatency(SourceInfo si, Trace trace, Consumer consumer) { long latency = 0; if (!si.isMultipleConsumers()) { long diff = si.getDuration() - consumer.getDuration(); if (diff > 0) { latency = diff >> 1; } else if (diff < 0) { if (log.isLoggable(Level.FINEST)) { log.finest("WARNING: Negative latency based on source/target duration, consumer trace = " + trace); } latency = calculateTimestampLatency(si, trace); } } else { latency = calculateTimestampLatency(si, trace); } return latency; } CommunicationDetailsDeriver(); SourceInfoCache getSourceInfoCache(); void setSourceInfoCache(SourceInfoCache sourceInfoCache); @Override void initialise(String tenantId, List<Trace> items); @Override CommunicationDetails processOneToOne(String tenantId, Trace item);  }
@Test public void testCalculateP2PLatency() { SourceInfo si = new SourceInfo(); si.setDuration(2000); Trace item = new Trace(); Consumer consumer = new Consumer(); consumer.setDuration(1000); item.getNodes().add(consumer); long latency = (si.getDuration() - consumer.getDuration()) / 2; assertEquals(latency, CommunicationDetailsDeriver.calculateLatency(si, item, consumer)); }
@Test public void testCalculateP2PAsyncLatency() { SourceInfo si = new SourceInfo(); si.setTimestamp(1000); si.setDuration(2000); Trace item = new Trace(); item.setTimestamp(2000); Consumer consumer = new Consumer(); consumer.setDuration(3000); item.getNodes().add(consumer); long latency = item.getTimestamp() - si.getTimestamp(); assertEquals(latency, CommunicationDetailsDeriver.calculateLatency(si, item, consumer)); }
@Test public void testCalculateMultiConsumerLatency() { SourceInfo si = new SourceInfo(); si.setMultipleConsumers(true); si.setTimestamp(1000); Trace item = new Trace(); item.setTimestamp(2000); Consumer consumer = new Consumer(); item.getNodes().add(consumer); long latency = item.getTimestamp() - si.getTimestamp(); assertEquals(latency, CommunicationDetailsDeriver.calculateLatency(si, item, consumer)); }