@Test public void testtraceWhenParentNotNullAndCurrentSpanNull(){ final RequestGlobalTransaction rgt = mock(RequestGlobalTransaction.class); final String traceId = "traceId"; final String spanName = "inParentGlobalTransaction"; final Span span = mock(Span.class); when(rgt.getParent()).thenReturn(null); when(mockTracer.getCurrentSpan()).thenReturn(null); when(mockTracer.createSpan(spanName)).thenReturn(span); when(span.traceIdString()).thenReturn(traceId); String result = businessGlobalTransactionServiceImplUnderTest.trace(rgt); assertEquals(result, traceId); verify(mockTracer, times(1)).createSpan(same(spanName)); verify(mockPublisher, times(1)).publishEvent(any(GtxSpanStarted.class)); }
String trace(RequestGlobalTransaction rgt) { String trace; if (rgt.getParent() != null) { trace = rgt.getTraceId(); } else { if(tracer.getCurrentSpan()==null){ trace = tracer.createSpan("inParentGlobalTransaction").traceIdString(); publisher.publishEvent(new GtxSpanStarted()); } else { trace = tracer.getCurrentSpan().traceIdString(); } } return trace; }
BusinessGlobalTransactionServiceImpl implements BusinessGlobalTransactionService { String trace(RequestGlobalTransaction rgt) { String trace; if (rgt.getParent() != null) { trace = rgt.getTraceId(); } else { if(tracer.getCurrentSpan()==null){ trace = tracer.createSpan("inParentGlobalTransaction").traceIdString(); publisher.publishEvent(new GtxSpanStarted()); } else { trace = tracer.getCurrentSpan().traceIdString(); } } return trace; } }
BusinessGlobalTransactionServiceImpl implements BusinessGlobalTransactionService { String trace(RequestGlobalTransaction rgt) { String trace; if (rgt.getParent() != null) { trace = rgt.getTraceId(); } else { if(tracer.getCurrentSpan()==null){ trace = tracer.createSpan("inParentGlobalTransaction").traceIdString(); publisher.publishEvent(new GtxSpanStarted()); } else { trace = tracer.getCurrentSpan().traceIdString(); } } return trace; } BusinessGlobalTransactionServiceImpl(); @Autowired  BusinessGlobalTransactionServiceImpl(GlobalTransactionRepository globalTransactionRepository,
												Tracer tracer,
												ApplicationEventPublisher publisher); }
BusinessGlobalTransactionServiceImpl implements BusinessGlobalTransactionService { String trace(RequestGlobalTransaction rgt) { String trace; if (rgt.getParent() != null) { trace = rgt.getTraceId(); } else { if(tracer.getCurrentSpan()==null){ trace = tracer.createSpan("inParentGlobalTransaction").traceIdString(); publisher.publishEvent(new GtxSpanStarted()); } else { trace = tracer.getCurrentSpan().traceIdString(); } } return trace; } BusinessGlobalTransactionServiceImpl(); @Autowired  BusinessGlobalTransactionServiceImpl(GlobalTransactionRepository globalTransactionRepository,
												Tracer tracer,
												ApplicationEventPublisher publisher); @Override Optional<GlobalTransaction> findGlobalTransaction(final String id); @Override GlobalTransaction participateToGlobalTransaction(Optional<RequestGlobalTransaction> orgt); @Override Optional<GlobalTransaction> retrieveGlobalTransaction(Optional<RequestGlobalTransaction> orgt); }
BusinessGlobalTransactionServiceImpl implements BusinessGlobalTransactionService { String trace(RequestGlobalTransaction rgt) { String trace; if (rgt.getParent() != null) { trace = rgt.getTraceId(); } else { if(tracer.getCurrentSpan()==null){ trace = tracer.createSpan("inParentGlobalTransaction").traceIdString(); publisher.publishEvent(new GtxSpanStarted()); } else { trace = tracer.getCurrentSpan().traceIdString(); } } return trace; } BusinessGlobalTransactionServiceImpl(); @Autowired  BusinessGlobalTransactionServiceImpl(GlobalTransactionRepository globalTransactionRepository,
												Tracer tracer,
												ApplicationEventPublisher publisher); @Override Optional<GlobalTransaction> findGlobalTransaction(final String id); @Override GlobalTransaction participateToGlobalTransaction(Optional<RequestGlobalTransaction> orgt); @Override Optional<GlobalTransaction> retrieveGlobalTransaction(Optional<RequestGlobalTransaction> orgt);  }