NodeDetailsDeriver extends AbstractProcessor<Trace, NodeDetails> { @Override public List<NodeDetails> processOneToMany(String tenantId, Trace item) throws RetryAttemptException { List<NodeDetails> ret = new ArrayList<NodeDetails>(); Set<Property> commonProperties = obtainCommonProperties(item); deriveNodeDetails(item, item.getNodes(), ret, true, commonProperties); if (log.isLoggable(Level.FINEST)) { log.finest("NodeDetailsDeriver [" + ret.size() + "] ret=" + ret); } return ret; } NodeDetailsDeriver(); @Override List<NodeDetails> processOneToMany(String tenantId, Trace item);  }
@Test public void testProcessMultipleNotInternalConsumer() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Trace trace = new Trace(); Consumer consumer = new Consumer(); consumer.setUri(INTERNAL_URI); trace.getNodes().add(consumer); Producer producer = new Producer(); producer.setEndpointType("HTTP"); producer.setUri(TEST_URI); consumer.getNodes().add(producer); List<NodeDetails> details = deriver.processOneToMany(null, trace); assertNotNull(details); assertEquals(1, details.size()); assertEquals(TEST_URI, details.get(0).getUri()); }
@Test public void testProcessMultipleNotInternalProducer() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Trace trace = new Trace(); Consumer consumer = new Consumer(); consumer.setEndpointType("HTTP"); consumer.setUri(TEST_URI); trace.getNodes().add(consumer); Producer producer = new Producer(); producer.setUri(INTERNAL_URI); consumer.getNodes().add(producer); List<NodeDetails> details = deriver.processOneToMany(null, trace); assertNotNull(details); assertEquals(1, details.size()); assertEquals(TEST_URI, details.get(0).getUri()); assertTrue(details.get(0).isInitial()); }
@Test public void testProcessCommonProperties() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Trace trace = new Trace(); Property p1 = new Property(Constants.PROP_BUILD_STAMP, "myBuild"); Property p2 = new Property(Constants.PROP_PRINCIPAL, "admin"); Property p3 = new Property(Constants.PROP_SERVICE_NAME, "myService"); Property p4 = new Property("LocalProp", "LocalValue"); Consumer consumer = new Consumer(); consumer.setEndpointType("HTTP"); consumer.getProperties().add(p1); consumer.getProperties().add(p2); trace.getNodes().add(consumer); Component component1 = new Component(); component1.getProperties().add(p3); consumer.getNodes().add(component1); Component component2 = new Component(); component2.getProperties().add(p4); component1.getNodes().add(component2); List<NodeDetails> details = deriver.processOneToMany(null, trace); assertEquals(3, details.size()); assertEquals(new HashSet<>(Arrays.asList(p1,p2,p3,p4)), details.get(0).getProperties()); assertEquals(new HashSet<>(Arrays.asList(p1,p2,p3)), details.get(1).getProperties()); assertEquals(new HashSet<>(Arrays.asList(p1,p2,p3,p4)), details.get(2).getProperties()); }
@Test public void testNotInitial() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Trace trace = new Trace(); Consumer consumer = new Consumer(); trace.getNodes().add(consumer); Producer producer = new Producer(); producer.setEndpointType("HTTP"); consumer.getNodes().add(producer); List<NodeDetails> details = deriver.processOneToMany(null, trace); assertNotNull(details); assertEquals(1, details.size()); assertFalse(details.get(0).isInitial()); }
@Test public void testInitial() throws RetryAttemptException { NodeDetailsDeriver deriver = new NodeDetailsDeriver(); Trace trace = new Trace(); Consumer consumer = new Consumer(); consumer.setEndpointType("HTTP"); trace.getNodes().add(consumer); Component component = new Component(); consumer.getNodes().add(component); List<NodeDetails> details = deriver.processOneToMany(null, trace); assertNotNull(details); assertEquals(2, details.size()); assertTrue(details.get(0).isInitial()); assertFalse(details.get(1).isInitial()); }