Search in sources :

Example 1 with Option

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);
    }
}
Also used : Option(org.eclipse.californium.core.coap.Option)

Example 2 with Option

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));
}
Also used : CoapExchange(org.eclipse.californium.core.server.resources.CoapExchange) Exchange(org.eclipse.californium.core.network.Exchange) SpanContext(io.opentracing.SpanContext) Request(org.eclipse.californium.core.coap.Request) Option(org.eclipse.californium.core.coap.Option) Binary(io.opentracing.propagation.Binary) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Option (org.eclipse.californium.core.coap.Option)2 SpanContext (io.opentracing.SpanContext)1 Binary (io.opentracing.propagation.Binary)1 Request (org.eclipse.californium.core.coap.Request)1 Exchange (org.eclipse.californium.core.network.Exchange)1 CoapExchange (org.eclipse.californium.core.server.resources.CoapExchange)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1