TraceCompletionInformationInitiator extends
        AbstractProcessor<Trace, TraceCompletionInformation> { @Override public TraceCompletionInformation processOneToOne(String tenantId, Trace item) throws RetryAttemptException { if (!item.getNodes().isEmpty()) { Node n = item.getNodes().get(0); if (item.initialFragment()) { TraceCompletionInformation ci = new TraceCompletionInformation(); CompletionTime ct = new CompletionTime(); ct.setId(item.getTraceId()); EndpointRef ep = EndpointUtil.getSourceEndpoint(item); ct.setUri(ep.getUri()); ct.setOperation(ep.getOperation()); if (n.getClass() == Consumer.class) { ct.setEndpointType(((Consumer) n).getEndpointType()); } ct.setTransaction(item.getTransaction()); ct.setDuration(item.calculateDuration()); ct.setProperties(item.allProperties()); ct.setTimestamp(item.getTimestamp()); ci.setCompletionTime(ct); StringBuilder nodeId = new StringBuilder(item.getFragmentId()); nodeId.append(":0"); TraceCompletionInformationUtil.initialiseLinks(ci, n.getTimestamp(), n, nodeId); if (log.isLoggable(Level.FINEST)) { log.finest("Creating initial completion time information = " + ci); } return ci; } } if (log.isLoggable(Level.FINEST)) { log.finest("No completion information initiated for trace fragment = " + item); } return null; } TraceCompletionInformationInitiator(); @Override TraceCompletionInformation processOneToOne(String tenantId,
            Trace item);  }
@Test public void testProcessSingleEmptyTrace() throws RetryAttemptException { Trace trace = new Trace(); TraceCompletionInformationInitiator initiator = new TraceCompletionInformationInitiator(); assertNull(initiator.processOneToOne(null, trace)); }
@Test public void testProcessSingleNotInitialFragment() throws RetryAttemptException { Trace trace = new Trace().setTraceId("traceId").setFragmentId("anotherId"); Consumer c = new Consumer(); trace.getNodes().add(c); TraceCompletionInformationInitiator initiator = new TraceCompletionInformationInitiator(); assertNull(initiator.processOneToOne(null, trace)); }
@Test public void testProcessSingleInitialFragmentConsumer() throws RetryAttemptException { Trace trace = new Trace(); trace.setTraceId("traceId"); trace.setFragmentId("traceId"); trace.setTransaction("traceName"); trace.setTimestamp(100000); Consumer c = new Consumer(); c.setUri("uri"); c.setTimestamp(1); c.setDuration(200000); c.getProperties().add(new Property(Constants.PROP_FAULT, "myFault")); c.setEndpointType("HTTP"); trace.getNodes().add(c); TraceCompletionInformationInitiator initiator = new TraceCompletionInformationInitiator(); TraceCompletionInformation ci = initiator.processOneToOne(null, trace); assertNotNull(ci); assertEquals(1, ci.getCommunications().size()); assertTrue(ci.getCommunications().get(0).getIds().contains("traceId:0")); assertEquals(trace.getTraceId(), ci.getCompletionTime().getId()); assertEquals(trace.getTransaction(), ci.getCompletionTime().getTransaction()); assertEquals(c.getEndpointType(), ci.getCompletionTime().getEndpointType()); assertFalse(ci.getCompletionTime().isInternal()); assertEquals(trace.getTimestamp(), ci.getCompletionTime().getTimestamp()); assertEquals(c.getUri(), ci.getCompletionTime().getUri()); assertEquals(200000, ci.getCompletionTime().getDuration()); assertEquals(1, ci.getCompletionTime().getProperties(Constants.PROP_FAULT).size()); assertEquals(c.getProperties(Constants.PROP_FAULT), ci.getCompletionTime().getProperties(Constants.PROP_FAULT)); }
@Test public void testProcessSingleInitialFragmentProducer() throws RetryAttemptException { Trace trace = new Trace(); trace.setTraceId("traceId"); trace.setFragmentId(trace.getTraceId()); Producer p = new Producer(); p.setUri("uri"); p.addInteractionCorrelationId("pid"); trace.getNodes().add(p); TraceCompletionInformationInitiator initiator = new TraceCompletionInformationInitiator(); TraceCompletionInformation ci = initiator.processOneToOne(null, trace); assertNotNull(ci); assertEquals(2, ci.getCommunications().size()); assertTrue(ci.getCommunications().get(0).getIds().contains("traceId:0")); assertTrue(ci.getCommunications().get(1).getIds().contains("pid")); assertEquals(EndpointUtil.encodeClientURI(p.getUri()), ci.getCompletionTime().getUri()); }
@Test public void testProcessSingleInitialFragmentComponent() throws RetryAttemptException { Trace trace = new Trace(); trace.setTraceId("traceId"); trace.setFragmentId("traceId"); trace.setTransaction("traceName"); trace.setTimestamp(100000); Component c = new Component(); c.setUri("uri"); c.setTimestamp(1); c.setDuration(200000); c.getProperties().add(new Property(Constants.PROP_FAULT, "myFault")); trace.getNodes().add(c); TraceCompletionInformationInitiator initiator = new TraceCompletionInformationInitiator(); TraceCompletionInformation ci = initiator.processOneToOne(null, trace); assertNotNull(ci); assertEquals(1, ci.getCommunications().size()); assertTrue(ci.getCommunications().get(0).getIds().contains("traceId:0")); assertEquals(trace.getTraceId(), ci.getCompletionTime().getId()); assertEquals(trace.getTransaction(), ci.getCompletionTime().getTransaction()); assertEquals(trace.getTimestamp(), ci.getCompletionTime().getTimestamp()); assertEquals(c.getUri(), ci.getCompletionTime().getUri()); assertEquals(200000, ci.getCompletionTime().getDuration()); assertEquals(c.getProperties(Constants.PROP_FAULT), ci.getCompletionTime().getProperties(Constants.PROP_FAULT)); assertEquals(1, ci.getCompletionTime().getProperties(Constants.PROP_FAULT).size()); }
@Test public void testProcessSingleInitialFragmentConsumerWithProducers() throws RetryAttemptException { Trace trace = new Trace(); trace.setTraceId("traceId"); trace.setFragmentId("traceId"); trace.setTransaction("traceName"); trace.setTimestamp(100); Consumer c = new Consumer(); c.setUri("uri"); trace.getNodes().add(c); Producer p1 = new Producer(); p1.setUri("p1"); p1.addInteractionCorrelationId("p1id"); c.getNodes().add(p1); Producer p2 = new Producer(); p2.setUri("p2"); p2.addInteractionCorrelationId("p2id"); c.getNodes().add(p2); TraceCompletionInformationInitiator initiator = new TraceCompletionInformationInitiator(); TraceCompletionInformation ci = initiator.processOneToOne(null, trace); assertNotNull(ci); assertEquals(5, ci.getCommunications().size()); for (Communication cm : ci.getCommunications()) { assertEquals(1, cm.getIds().size()); } assertEquals("p1id", ci.getCommunications().get(2).getIds().get(0)); assertEquals("p2id", ci.getCommunications().get(4).getIds().get(0)); }