zipkin2.codec.Encoding Java Examples

The following examples show how to use zipkin2.codec.Encoding. 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: BufferNextMessageTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test public void offer_json() {
  BufferNextMessage<Integer> pending = BufferNextMessage.create(Encoding.JSON, 10, 0L);
  pending.offer(1, 1);

  assertThat(pending.bufferFull)
      .isFalse();
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(3 /* [1] */);

  pending.offer(2, 1);

  assertThat(pending.bufferFull)
      .isFalse();
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(5 /* [1,2] */);
}
 
Example #2
Source File: BufferNextMessageTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test public void offerWhenFull_json() {
  BufferNextMessage<Integer> pending = BufferNextMessage.create(Encoding.JSON, 10, 0L);
  for (int i = 0; i < 4; i++) {
    assertThat(pending.offer(i, 1))
        .isTrue();
  }
  // buffer is not quite full
  assertThat(pending.bufferFull)
      .isFalse();
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(9 /* [0,1,2,3] */);

  // but another element will put it over the edge, so drops
  assertThat(pending.offer(4, 1))
      // should drop because 4 implies ",4" which makes the total length 11
      .isFalse();
  // then we should consider buffer is full and drain all
  assertThat(pending.bufferFull).isTrue();
}
 
Example #3
Source File: BufferNextMessageTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test public void offer_proto3() {
  BufferNextMessage<Character> pending = BufferNextMessage.create(Encoding.PROTO3, 10, 0L);
  pending.offer('a', 1);

  assertThat(pending.bufferFull)
      .isFalse();
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(1 /* a */);

  pending.offer('b', 1);

  assertThat(pending.bufferFull)
      .isFalse();
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(2 /* ab */);
}
 
Example #4
Source File: BufferNextMessageTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test public void drain_incrementally_json() {
  BufferNextMessage<Integer> pending = BufferNextMessage.create(Encoding.JSON, 10, 0L);
  for (int i = 0; i < 4; i++) {
    pending.offer(i, 1);
  }

  // partial drain
  pending.drain((s, n) -> s < 2);

  assertThat(pending.spans)
      .containsExactly(2, 3);
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(5 /* [2,3] */);

  // partial drain again
  pending.drain((s, n) -> s < 3);

  assertThat(pending.spans)
      .containsExactly(3);
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(3 /* [3] */);
}
 
Example #5
Source File: BufferNextMessageTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test public void offerWhenFull_proto3() {
  BufferNextMessage<Integer> pending = BufferNextMessage.create(Encoding.PROTO3, 10, 0L);
  for (int i = 0; i < 3; i++) {
    assertThat(pending.offer(i, 3))
        .isTrue();
  }
  // buffer is not quite full
  assertThat(pending.bufferFull)
      .isFalse();
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(9 /* 012 */);

  // but another element will put it over the edge, so drops
  assertThat(pending.offer(3, 3))
      // should drop because this implies adding 3 bytes which makes the total length 12
      .isFalse();
  // then we should consider buffer is full and drain all
  assertThat(pending.bufferFull).isTrue();
}
 
Example #6
Source File: BufferNextMessageTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test public void drain_incrementally_proto3() {
  BufferNextMessage<Integer> pending = BufferNextMessage.create(Encoding.PROTO3, 10, 0L);
  for (int i = 0; i < 4; i++) {
    pending.offer(i, 1);
  }

  // partial drain
  pending.drain((s, n) -> s < 2);

  assertThat(pending.spans)
      .containsExactly(2, 3);
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(2 /* 23 */);

  // partial drain again
  pending.drain((s, n) -> s < 3);

  assertThat(pending.spans)
      .containsExactly(3);
  assertThat(pending.messageSizeInBytes)
      .isEqualTo(1 /* 3 */);
}
 
Example #7
Source File: KinesisSenderTest.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Test
public void sendsSpans_PROTO3() throws Exception {
  server.enqueue(new MockResponse());

  sender.close();
  sender = sender.toBuilder().encoding(Encoding.PROTO3).build();

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  assertThat(extractSpans(server.takeRequest().getBody()))
      .containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #8
Source File: BufferNextMessageTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void drain_json() {
  BufferNextMessage<Integer> pending = BufferNextMessage.create(Encoding.JSON, 10, 0L);
  for (int i = 0; i < 4; i++) {
    pending.offer(i, 1);
  }

  // fully drain
  pending.drain((s, n) -> true);

  // back to initial state
  assertThat(pending).isEqualToComparingFieldByField(
      BufferNextMessage.create(Encoding.JSON, 10, 0L)
  );
}
 
Example #9
Source File: TracingBuilder.java    From brave-kafka-interceptor with Apache License 2.0 5 votes vote down vote up
Sender build() {
  Encoding encoding = new EncodingBuilder(configuration).build();
  switch (senderType) {
    case HTTP:
      return new HttpSenderBuilder(configuration).build(encoding);
    case KAFKA:
      return new KafkaSenderBuilder(configuration).build(encoding);
    case NONE:
      return null;
    default:
      throw new IllegalArgumentException("Zipkin sender type unknown");
  }
}
 
Example #10
Source File: OkHttpSenderTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void sendsSpans_THRIFT() throws Exception {
  sender = sender.toBuilder().encoding(Encoding.THRIFT).build();

  server.enqueue(new MockResponse());

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  // Ensure only one request was sent
  assertThat(server.getRequestCount()).isEqualTo(1);

  // Now, let's read back the spans we sent!
  assertThat(SpanBytesDecoder.THRIFT.decodeList(server.takeRequest().getBody().readByteArray()))
      .containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #11
Source File: KafkaSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void encoding() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.KafkaSenderFactoryBean\">\n"
      + "  <property name=\"bootstrapServers\" value=\"localhost:9092\"/>\n"
      + "  <property name=\"encoding\" value=\"PROTO3\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", KafkaSender.class))
      .extracting("encoding")
      .isEqualTo(Encoding.PROTO3);
}
 
Example #12
Source File: HaystackKafkaForwarderTest.java    From pitchfork with Apache License 2.0 5 votes vote down vote up
/**
 * Create reporter.
 */
private AsyncReporter<zipkin2.Span> setupReporter() {
    var sender = OkHttpSender.newBuilder()
            .encoding(Encoding.PROTO3)
            .endpoint("http://localhost:" + localServerPort + "/api/v2/spans")
            .build();
    return AsyncReporter.create(sender);
}
 
Example #13
Source File: KafkaZipkinCollectorConfiguration.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Sender getSender() {

    return KafkaSender
            .newBuilder()
            .bootstrapServers(super.getZipkinUrl())
            .topic(super.getTopic())
            .encoding(Encoding.JSON)
            .build();
}
 
Example #14
Source File: URLConnectionSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void encoding() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.URLConnectionSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "  <property name=\"encoding\" value=\"PROTO3\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", URLConnectionSender.class))
      .extracting("encoding")
      .isEqualTo(Encoding.PROTO3);
}
 
Example #15
Source File: RabbitMQSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void encoding() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.RabbitMQSenderFactoryBean\">\n"
      + "  <property name=\"addresses\" value=\"localhost\"/>\n"
      + "  <property name=\"encoding\" value=\"PROTO3\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", RabbitMQSender.class))
      .extracting("encoding")
      .isEqualTo(Encoding.PROTO3);
}
 
Example #16
Source File: FakeSender.java    From zipkin-finagle with Apache License 2.0 5 votes vote down vote up
static FakeSender create() {
  return new FakeSender(
      Encoding.THRIFT,
      Integer.MAX_VALUE,
      BytesMessageEncoder.forEncoding(Encoding.THRIFT),
      SpanBytesEncoder.THRIFT,
      SpanBytesDecoder.THRIFT,
      spans -> {
      }
  );
}
 
Example #17
Source File: FakeSender.java    From zipkin-finagle with Apache License 2.0 5 votes vote down vote up
FakeSender(
    Encoding encoding,
    int messageMaxBytes,
    BytesMessageEncoder messageEncoder,
    BytesEncoder<Span> encoder,
    BytesDecoder<Span> decoder,
    Consumer<List<Span>> onSpans
) {
  this.encoding = encoding;
  this.messageMaxBytes = messageMaxBytes;
  this.messageEncoder = messageEncoder;
  this.encoder = encoder;
  this.decoder = decoder;
  this.onSpans = onSpans;
}
 
Example #18
Source File: KafkaZipkinTracer.java    From zipkin-finagle with Apache License 2.0 5 votes vote down vote up
KafkaZipkinTracer(Config config, StatsReceiver stats) {
  this(KafkaSender.newBuilder()
      .encoding(Encoding.JSON)
      .bootstrapServers(config.bootstrapServers())
      .topic(config.topic())
      .build(), config, stats);
}
 
Example #19
Source File: SQSSenderTest.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Test
public void sendsSpans_PROTO3() throws Exception {
  sender.close();
  sender = sender.toBuilder().encoding(Encoding.PROTO3).build();

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #20
Source File: URLConnectionSenderTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void sendsSpans_PROTO3() throws Exception {
  sender = sender.toBuilder().encoding(Encoding.PROTO3).build();

  server.enqueue(new MockResponse());

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  // Ensure only one request was sent
  assertThat(server.getRequestCount()).isEqualTo(1);

  // Now, let's read back the spans we sent!
  assertThat(SpanBytesDecoder.PROTO3.decodeList(server.takeRequest().getBody().readByteArray()))
      .containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #21
Source File: FakeSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
public static FakeSender create() {
  return new FakeSender(
      Encoding.JSON,
      Integer.MAX_VALUE,
      BytesMessageEncoder.forEncoding(Encoding.JSON),
      SpanBytesEncoder.JSON_V2,
      SpanBytesDecoder.JSON_V2,
      spans -> {
      }
  );
}
 
Example #22
Source File: ITRabbitMQSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void sendsSpans_PROTO3() throws Exception {
  sender.close();
  sender = rabbit.tryToInitializeSender(rabbit.newSenderBuilder().encoding(Encoding.PROTO3));

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  assertThat(SpanBytesDecoder.PROTO3.decodeList(readMessage()))
      .containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #23
Source File: URLConnectionSenderTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void sendsSpans_THRIFT() throws Exception {
  sender = sender.toBuilder().encoding(Encoding.THRIFT).build();

  server.enqueue(new MockResponse());

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  // Ensure only one request was sent
  assertThat(server.getRequestCount()).isEqualTo(1);

  // Now, let's read back the spans we sent!
  assertThat(SpanBytesDecoder.THRIFT.decodeList(server.takeRequest().getBody().readByteArray()))
      .containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #24
Source File: AbstractSender.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override public Call<Void> sendSpans(List<byte[]> list) {
  if (closeCalled) throw new IllegalStateException("closed");

  byte[] encodedSpans = BytesMessageEncoder.forEncoding(encoding()).encode(list);
  String body =
      encoding() == Encoding.JSON && isAscii(encodedSpans)
          ? new String(encodedSpans, StandardCharsets.UTF_8)
          : Base64.getEncoder().encodeToString(encodedSpans);

  return call(SendMessageRequest.builder().messageBody(body).queueUrl(queueUrl).build());
}
 
Example #25
Source File: ITKafkaSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test
public void sendsSpans_THRIFT() throws Exception {
  sender.close();
  sender = sender.toBuilder().encoding(Encoding.THRIFT).build();

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  assertThat(SpanBytesDecoder.THRIFT.decodeList(readMessages().get(0)))
      .containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #26
Source File: BufferNextMessageTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void empty_proto3() {
  BufferNextMessage<Integer> pending = BufferNextMessage.create(Encoding.PROTO3, 10, 0L);

  assertThat(pending.bufferFull)
      .isFalse();
  assertThat(pending.messageSizeInBytes)
      .isZero();
}
 
Example #27
Source File: SQSAsyncSenderTest.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Test
public void sendsSpans_PROTO3() throws Exception {
  sender.close();
  sender = sender.toBuilder().encoding(Encoding.PROTO3).build();

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #28
Source File: ITKafkaSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test
public void sendsSpans_PROTO3() throws Exception {
  sender.close();
  sender = sender.toBuilder().encoding(Encoding.PROTO3).build();

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  assertThat(SpanBytesDecoder.PROTO3.decodeList(readMessages().get(0)))
      .containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #29
Source File: SQSSenderTest.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Test
public void sendsSpans_PROTO3() throws Exception {
  sender.close();
  sender = sender.toBuilder().encoding(Encoding.PROTO3).build();

  send(CLIENT_SPAN, CLIENT_SPAN).execute();

  assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN);
}
 
Example #30
Source File: SQSSender.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override
public Call<Void> sendSpans(List<byte[]> list) {
  if (closeCalled) throw new IllegalStateException("closed");

  byte[] encodedSpans = BytesMessageEncoder.forEncoding(encoding()).encode(list);
  String body =
      encoding() == Encoding.JSON && isAscii(encodedSpans)
          ? new String(encodedSpans, UTF_8)
          : Base64.encodeAsString(encodedSpans);

  return new SQSCall(new SendMessageRequest(queueUrl, body));
}