use of org.eclipse.californium.core.coap.Option in project hono by eclipse.
the class CoapOptionInjectExtractAdapter method injectionBuffer.
/**
* {@inheritDoc}
*/
@Override
public ByteBuffer injectionBuffer(final int length) {
if (options == null) {
throw new IllegalStateException("this carrier is not suitable for injection");
} else {
final byte[] buffer = new byte[length];
options.addOption(new Option(OPTION_TRACE_CONTEXT, buffer));
return ByteBuffer.wrap(buffer);
}
}
use of org.eclipse.californium.core.coap.Option in project hono by eclipse.
the class TracingSupportingHonoResourceTest method testHandleRequestExtractsParentTraceContext.
/**
* Verifies that the resource uses the SpanContext extracted from a CoAP request
* as the parent of the newly created Span.
*/
@Test
public void testHandleRequestExtractsParentTraceContext() {
final SpanContext extractedContext = mock(SpanContext.class);
when(tracer.extract(eq(Format.Builtin.BINARY), any(Binary.class))).thenReturn(extractedContext);
final Request request = new Request(Code.POST);
request.getOptions().addOption(new Option(CoapOptionInjectExtractAdapter.OPTION_TRACE_CONTEXT));
final Exchange exchange = newExchange(request);
resource.handleRequest(exchange);
verify(tracer).buildSpan(eq(Code.POST.toString()));
verify(spanBuilder).withTag(eq(Tags.SPAN_KIND.getKey()), eq(Tags.SPAN_KIND_SERVER.toString()));
verify(spanBuilder).addReference(eq(References.CHILD_OF), eq(extractedContext));
}
Aggregations