Search in sources :

Example 41 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecResiliencyTest method shouldFallbackWhenMaliciousInput.

@Test
@UseDataProvider("maliciousInputs")
public void shouldFallbackWhenMaliciousInput(String headerName, String maliciousInput) {
    TextMap maliciousCarrier = validHeaders();
    maliciousCarrier.put(headerName, maliciousInput);
    // when
    JaegerSpanContext extract = sut.extract(maliciousCarrier);
    // then
    assertNull(extract);
}
Also used : TextMap(io.opentracing.propagation.TextMap) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 42 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class BinaryCodecTest method testBaggage.

/**
 * Tests that the codec will return non-null SpanContext even if the only header
 * present is "jaeger-baggage".
 */
@Test
public void testBaggage() {
    Map<String, String> baggage = new HashMap<String, String>();
    for (int i = 0; i < 200; i++) {
        baggage.put("k" + i, "v" + i);
    }
    BinaryCodec codec = new BinaryCodec();
    JaegerSpanContext inContext = new JaegerSpanContext(0L, 42L, 1L, 1L, (byte) 1).withBaggage(baggage);
    TestBinaryCarrier carrier = new TestBinaryCarrier();
    codec.inject(inContext, carrier);
    // check with a new carrier just to make sure testing is accurate.
    byte[] raw = new byte[carrier.buffer.capacity()];
    carrier.buffer.rewind();
    carrier.buffer.get(raw);
    TestBinaryCarrier carrier2 = new TestBinaryCarrier(ByteBuffer.wrap(raw));
    JaegerSpanContext outContext = codec.extract(carrier2);
    assertTrue(carrier2.buffer.remaining() == 0);
    for (int i = 0; i < 200; i++) {
        assertEquals("v" + i, outContext.getBaggageItem("k" + i));
    }
}
Also used : HashMap(java.util.HashMap) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 43 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class BinaryCodecTest method testBaggageWithLargeValues.

@Test
public void testBaggageWithLargeValues() {
    String key1 = "";
    String val1 = "";
    for (int i = 0; i < 256; i++) {
        key1 += "A";
        val1 += "B";
    }
    String key2 = "";
    String val2 = "";
    for (int i = 0; i < 1024; i++) {
        key2 += "C";
        val2 += "D";
    }
    Map<String, String> baggage = new HashMap<String, String>();
    baggage.put(key1, val1);
    baggage.put(key2, val2);
    JaegerSpanContext inContext = new JaegerSpanContext(0L, 1L, 1L, 1L, (byte) 1).withBaggage(baggage);
    BinaryCodec codec = new BinaryCodec();
    TestBinaryCarrier carrier = new TestBinaryCarrier();
    codec.inject(inContext, carrier);
    JaegerSpanContext outContext = codec.extract(carrier);
    assertEquals(val1, outContext.getBaggageItem(key1));
    assertEquals(val2, outContext.getBaggageItem(key2));
}
Also used : HashMap(java.util.HashMap) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 44 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class BinaryCodecTest method testInvalidByteOrder.

@Test
public void testInvalidByteOrder() {
    BinaryCodec codec = new BinaryCodec();
    ByteBuffer buf = ByteBuffer.allocate(128);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    TestBinaryCarrier carrier = new TestBinaryCarrier(buf);
    try {
        codec.inject(new JaegerSpanContext(0L, 0L, 0L, 0L, (byte) 0), carrier);
        fail("Exception not thrown.");
    } catch (IllegalStateException expected) {
        assertEquals("Carrier byte order must be big endian.", expected.getMessage());
    }
    try {
        codec.extract(carrier);
        fail("Exception not thrown.");
    } catch (IllegalStateException expected) {
        assertEquals("Carrier byte order must be big endian.", expected.getMessage());
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 45 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class TraceContextCodecTest method testInvalidParentId.

@Test
public void testInvalidParentId() {
    TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
    textMap.put(TRACE_PARENT, "00-00000000000000000000000000000001-0000000000000000-00");
    JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
    assertNull(spanContext);
    verifyWarningPresent();
}
Also used : TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Aggregations

JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)68 Test (org.junit.Test)59 HashMap (java.util.HashMap)20 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)19 JaegerSpan (io.jaegertracing.internal.JaegerSpan)10 JaegerTracer (io.jaegertracing.internal.JaegerTracer)8 Response (javax.ws.rs.core.Response)7 TextMap (io.opentracing.propagation.TextMap)6 CodecConfiguration (io.jaegertracing.Configuration.CodecConfiguration)4 ReporterConfiguration (io.jaegertracing.Configuration.ReporterConfiguration)4 SamplerConfiguration (io.jaegertracing.Configuration.SamplerConfiguration)4 SenderConfiguration (io.jaegertracing.Configuration.SenderConfiguration)4 List (java.util.List)3 ObservedSpan (io.jaegertracing.crossdock.api.ObservedSpan)2 TestBinaryCarrier (io.jaegertracing.internal.propagation.TestBinaryCarrier)2 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)1