Collector { public void acceptSpans(ByteBuffer encoded, SpanBytesDecoder decoder, Callback<Void> callback, Executor executor) { List<Span> spans; try { spans = decoder.decodeList(encoded); } catch (RuntimeException | Error e) { handleDecodeError(e, callback); return; } accept(spans, callback, executor); } Collector(Builder builder); static Builder newBuilder(Class<?> loggingClass); void accept(List<Span> spans, Callback<Void> callback); void accept(List<Span> spans, Callback<Void> callback, Executor executor); void acceptSpans(ByteBuffer encoded, SpanBytesDecoder decoder, Callback<Void> callback,
    Executor executor); void acceptSpans(byte[] serialized, Callback<Void> callback); void acceptSpans(
    byte[] serializedSpans, BytesDecoder<Span> decoder, Callback<Void> callback);  }
@Test public void errorDetectingFormat() { collector.acceptSpans(new byte[] {'f', 'o', 'o'}, callback); verify(callback).onError(any(RuntimeException.class)); verify(metrics).incrementMessagesDropped(); }
@Test public void acceptSpans_jsonV2() { byte[] bytes = SpanBytesEncoder.JSON_V2.encodeList(TRACE); collector.acceptSpans(bytes, callback); verify(collector).acceptSpans(bytes, SpanBytesDecoder.JSON_V2, callback); verify(callback).onSuccess(null); assertThat(testLogger.getLoggingEvents()).isEmpty(); verify(metrics).incrementSpans(4); assertThat(storage.getTraces()).containsOnly(TRACE); }
@Test public void acceptSpans_decodingError() { byte[] bytes = "[\"='".getBytes(UTF_8); collector.acceptSpans(bytes, SpanBytesDecoder.JSON_V2, callback); verify(callback).onError(any(IllegalArgumentException.class)); assertDebugLogIs("Malformed reading List<Span> from json"); verify(metrics).incrementMessagesDropped(); }
@Test public void acceptSpans_emptyMessageOk() { byte[] bytes = new byte[] {'[', ']'}; collector.acceptSpans(bytes, callback); verify(collector).acceptSpans(bytes, SpanBytesDecoder.JSON_V1, callback); verify(callback).onSuccess(null); assertThat(testLogger.getLoggingEvents()).isEmpty(); assertThat(storage.getTraces()).isEmpty(); }