Search in sources :

Example 31 with Endpoint

use of org.pjsip.pjsua2.Endpoint in project zipkin by openzipkin.

the class JsonSerializers method parseEndpoint.

static Endpoint parseEndpoint(JsonParser parser) throws IOException {
    if (!parser.isExpectedStartObjectToken()) {
        throw new IllegalArgumentException("Not a valid JSON object, start token: " + parser.currentToken());
    }
    String serviceName = null, ipv4 = null, ipv6 = null;
    int port = 0;
    while (parser.nextToken() != JsonToken.END_OBJECT) {
        JsonToken value = parser.nextValue();
        if (value == JsonToken.VALUE_NULL) {
            continue;
        }
        switch(parser.currentName()) {
            case "serviceName":
                serviceName = parser.getText();
                break;
            case "ipv4":
                ipv4 = parser.getText();
                break;
            case "ipv6":
                ipv6 = parser.getText();
                break;
            case "port":
                port = parser.getIntValue();
                break;
            default:
        }
    }
    if (serviceName == null && ipv4 == null && ipv6 == null && port == 0)
        return null;
    return Endpoint.newBuilder().serviceName(serviceName).ip(ipv4).ip(ipv6).port(port).build();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) Endpoint(zipkin2.Endpoint)

Example 32 with Endpoint

use of org.pjsip.pjsua2.Endpoint in project zipkin by openzipkin.

the class JsonSerializersTest method span_specialCharsInJson.

/**
 * This isn't a test of what we "should" accept as a span, rather that characters that trip-up
 * json don't fail in SPAN_PARSER.
 */
@Test
public void span_specialCharsInJson() {
    // service name is surrounded by control characters
    Endpoint e = Endpoint.newBuilder().serviceName(new String(new char[] { 0, 'a', 1 })).build();
    Span worstSpanInTheWorld = Span.newBuilder().traceId("1").id("1").name(new String(new char[] { '"', '\\', '\t', '\b', '\n', '\r', '\f' })).localEndpoint(e).addAnnotation(1L, "\u2028 and \u2029").putTag("\"foo", "Database error: ORA-00942:\u2028 and \u2029 table or view does not exist\n").build();
    assertThat(parse(SPAN_PARSER, new String(SpanBytesEncoder.JSON_V2.encode(worstSpanInTheWorld), UTF_8))).isEqualTo(worstSpanInTheWorld);
}
Also used : Endpoint(zipkin2.Endpoint) Span(zipkin2.Span) Test(org.junit.Test)

Example 33 with Endpoint

use of org.pjsip.pjsua2.Endpoint in project zipkin by openzipkin.

the class TraceTest method cleanupComparator_transitiveKindComparison.

/**
 * Comparators are meant to be transitive. This exploits edge cases to fool our comparator.
 */
@Test
public void cleanupComparator_transitiveKindComparison() {
    List<Span> trace = new ArrayList<>();
    Endpoint aEndpoint = Endpoint.newBuilder().serviceName("a").build();
    Endpoint bEndpoint = Endpoint.newBuilder().serviceName("b").build();
    Span template = Span.newBuilder().traceId("a").id("a").build();
    // when there are at least 32 elements.
    for (int i = 0, length = 7; i < length; i++) {
        trace.add(template.toBuilder().shared(true).localEndpoint(bEndpoint).build());
        trace.add(template.toBuilder().kind(Kind.CLIENT).localEndpoint(bEndpoint).build());
        trace.add(template.toBuilder().localEndpoint(aEndpoint).build());
        trace.add(template);
        trace.add(template.toBuilder().kind(Kind.CLIENT).localEndpoint(aEndpoint).build());
    }
    Collections.sort(trace, Trace.CLEANUP_COMPARATOR);
    assertThat(new LinkedHashSet<>(trace)).extracting(Span::shared, Span::kind, s -> s.localServiceName()).containsExactly(tuple(null, Kind.CLIENT, "a"), tuple(null, Kind.CLIENT, "b"), tuple(null, null, null), tuple(null, null, "a"), tuple(true, null, "b"));
}
Also used : List(java.util.List) Endpoint(zipkin2.Endpoint) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Arrays.asList(java.util.Arrays.asList) Kind(zipkin2.Span.Kind) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Span(zipkin2.Span) Test(org.junit.Test) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Endpoint(zipkin2.Endpoint) ArrayList(java.util.ArrayList) Span(zipkin2.Span) Endpoint(zipkin2.Endpoint) Test(org.junit.Test)

Example 34 with Endpoint

use of org.pjsip.pjsua2.Endpoint in project zipkin by openzipkin.

the class V1ThriftSpanWriterTest method endpoint_highPort.

@Test
public void endpoint_highPort() {
    int highPort = 63840;
    Endpoint endpoint = Endpoint.newBuilder().ip("127.0.0.1").port(63840).build();
    byte[] buff = new byte[ThriftEndpointCodec.sizeInBytes(endpoint)];
    ThriftEndpointCodec.write(endpoint, WriteBuffer.wrap(buff, 0));
    assertThat(buff).containsSequence(TYPE_I32, 0, 1, 127, 0, 0, // ipv4
    1).containsSequence(TYPE_I16, 0, 2, (highPort >> 8) & 0xFF, // port
    highPort & 0xFF);
    assertThat(ThriftEndpointCodec.read(ReadBuffer.wrap(buff)).portAsInt()).isEqualTo(highPort);
}
Also used : Endpoint(zipkin2.Endpoint) Endpoint(zipkin2.Endpoint) Test(org.junit.Test)

Example 35 with Endpoint

use of org.pjsip.pjsua2.Endpoint in project zipkin by openzipkin.

the class ThriftEndpointCodec method write.

static void write(Endpoint value, WriteBuffer buffer) {
    IPV4.write(buffer);
    buffer.write(value.ipv4Bytes() != null ? value.ipv4Bytes() : INT_ZERO);
    PORT.write(buffer);
    int port = value.portAsInt();
    // write short!
    buffer.writeByte((port >>> 8L) & 0xff);
    buffer.writeByte(port & 0xff);
    SERVICE_NAME.write(buffer);
    ThriftCodec.writeLengthPrefixed(buffer, value.serviceName() != null ? value.serviceName() : "");
    byte[] ipv6 = value.ipv6Bytes();
    if (ipv6 != null) {
        IPV6.write(buffer);
        ThriftCodec.writeInt(buffer, 16);
        buffer.write(ipv6);
    }
    buffer.writeByte(TYPE_STOP);
}
Also used : Endpoint(zipkin2.Endpoint)

Aggregations

Endpoint (zipkin2.Endpoint)55 Span (zipkin2.Span)27 Test (org.junit.jupiter.api.Test)18 V1Span (zipkin2.v1.V1Span)16 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)5 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)5 List (java.util.List)3 JsonToken (com.fasterxml.jackson.core.JsonToken)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 NetworkInterface (java.net.NetworkInterface)2 Arrays.asList (java.util.Arrays.asList)2 Endpoint (org.jboss.remoting3.Endpoint)2 Record (org.jooq.Record)2 Access (org.openstack4j.model.identity.v2.Access)2 V1SpanConverter (zipkin2.v1.V1SpanConverter)2 Tracing (brave.Tracing)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CrnkClient (io.crnk.client.CrnkClient)1