io.opentracing.mock.MockSpan.MockContext Java Examples
The following examples show how to use
io.opentracing.mock.MockSpan.MockContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProxyMockTracer.java From java-specialagent with Apache License 2.0 | 4 votes |
@Override public <C>ProxyMockSpanContext extract(final Format<C> format, final C carrier) { final SpanContext mockSpanContext = super.extract(format, carrier); final SpanContext realSpanContext = realTracer.extract(format, carrier); return mockSpanContext == null ? null : new ProxyMockSpanContext((MockContext)mockSpanContext, realSpanContext); }
Example #2
Source File: ProxyMockSpanContext.java From java-specialagent with Apache License 2.0 | 4 votes |
ProxyMockSpanContext(final MockContext mockSpanContext, final SpanContext realSpanContext) { super(-1, -1, null); this.mockSpanContext = Objects.requireNonNull(mockSpanContext); this.realSpanContext = Objects.requireNonNull(realSpanContext); }
Example #3
Source File: OpenTracingIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout = 20000) public void testSend() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnectionFactory factory = new JmsConnectionFactory(createPeerURI(testPeer)); MockTracer mockTracer = new MockTracer(); JmsTracer tracer = OpenTracingTracerFactory.create(mockTracer); factory.setTracer(tracer); testPeer.expectSaslAnonymous(); testPeer.expectOpen(); testPeer.expectBegin(); Connection connection = factory.createConnection(); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = "myQueue"; Queue queue = session.createQueue(queueName); testPeer.expectSenderAttach(); MessageProducer producer = session.createProducer(queue); // Expect a message with the trace info annotation set String msgContent = "myTracedMessageContent"; TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(new MessageHeaderSectionMatcher(true)); MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); msgAnnotationsMatcher.withEntry(Symbol.valueOf(ANNOTATION_KEY), Matchers.any(Map.class)); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); messageMatcher.setPropertiesMatcher(new MessagePropertiesSectionMatcher(true)); messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(msgContent)); testPeer.expectTransfer(messageMatcher); TextMessage message = session.createTextMessage(msgContent); producer.send(message); testPeer.waitForAllHandlersToComplete(2000); List<MockSpan> finishedSpans = mockTracer.finishedSpans(); assertEquals("Expected 1 finished span: " + finishedSpans, 1, finishedSpans.size()); Span sendSpan = finishedSpans.get(0); assertEquals("Unexpected span class", MockSpan.class, sendSpan.getClass()); MockSpan sendMockSpan = (MockSpan) sendSpan; assertEquals("Expected span to have no parent", 0, sendMockSpan.parentId()); assertEquals("Unexpected span operation name", SEND_SPAN_NAME, sendMockSpan.operationName()); // Verify tags set on the completed span Map<String, Object> spanTags = sendMockSpan.tags(); assertFalse("Expected some tags", spanTags.isEmpty()); assertFalse("Expected error tag not to be set", spanTags.containsKey(Tags.ERROR.getKey())); assertEquals(Tags.SPAN_KIND_PRODUCER, spanTags.get(Tags.SPAN_KIND.getKey())); assertEquals(queueName, spanTags.get(Tags.MESSAGE_BUS_DESTINATION.getKey())); assertEquals(COMPONENT, spanTags.get(Tags.COMPONENT.getKey())); // Verify log set on the completed span List<LogEntry> entries = sendMockSpan.logEntries(); assertEquals("Expected 1 log entry: " + entries, 1, entries.size()); Map<String, ?> entryFields = entries.get(0).fields(); assertFalse("Expected some log entry fields", entryFields.isEmpty()); assertNotNull("Expected a state description", entryFields.get(STATE)); assertEquals(DELIVERY_SETTLED, entryFields.get(Fields.EVENT)); // Verify the context sent on the wire matches the original span Object obj = msgAnnotationsMatcher.getReceivedAnnotation(Symbol.valueOf(ANNOTATION_KEY)); assertTrue("annotation was not a map", obj instanceof Map); @SuppressWarnings("unchecked") Map<String, String> traceInfo = (Map<String, String>) obj; assertFalse("Expected some content in map", traceInfo.isEmpty()); SpanContext extractedContext = mockTracer.extract(Format.Builtin.TEXT_MAP, new TextMapAdapter(traceInfo)); assertEquals("Unexpected context class", MockContext.class, extractedContext.getClass()); assertEquals("Extracted context spanId did not match original", sendMockSpan.context().spanId(), ((MockContext) extractedContext).spanId()); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(2000); } }