use of zipkin2.Callback in project zipkin by openzipkin.
the class ScribeSpanConsumerTest method decodesSpanGeneratedByFinagle.
/**
* Finagle's zipkin tracer breaks on a column width with a trailing newline
*/
@Test
void decodesSpanGeneratedByFinagle() throws Exception {
LogEntry entry = new LogEntry();
entry.category = "zipkin";
entry.message = "" + "CgABq/sBMnzE048LAAMAAAAOZ2V0VHJhY2VzQnlJZHMKAATN0p+4EGfTdAoABav7ATJ8xNOPDwAGDAAAAAQKAAEABR/wq+2DeAsAAgAAAAJzcgwAAwgAAX8AAAEGAAIkwwsAAwAAAAx6aXBraW4tcXVlcnkAAAoAAQAFH/Cr7zj4CwACAAAIAGFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF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ADCAABfwAAAQYAAiTDCwADAAAADHppcGtpbi1xdWVyeQAACgABAAUf8KwLPyILAAIAAABOR2MoOSwwLlBTU2NhdmVuZ2UsMjAxNS0wOS0xNyAxMjozNzowMiArMDAwMCwzMDQubWlsbGlzZWNvbmRzKzc2Mi5taWNyb3NlY29uZHMpDAADCAABfwAAAQYAAiTDCwADAAAADHppcGtpbi1xdWVyeQAIAAQABKZ6AAoAAQAFH/CsDLfACwACAAAAAnNzDAADCAABfwAAAQYAAiTDCwADAAAADHppcGtpbi1xdWVyeQAADwAIDAAAAAULAAEAAAATc3J2L2ZpbmFnbGUudmVyc2lvbgsAAgAAAAY2LjI4LjAIAAMAAAAGDAAECAABfwAAAQYAAgAACwADAAAADHppcGtpbi1xdWVyeQAACwABAAAAD3Nydi9tdXgvZW5hYmxlZAsAAgAAAAEBCAADAAAAAAwABAgAAX8AAAEGAAIAAAsAAwAAAAx6aXBraW4tcXVlcnkAAAsAAQAAAAJzYQsAAgAAAAEBCAADAAAAAAwABAgAAX8AAAEGAAIkwwsAAwAAAAx6aXBraW4tcXVlcnkAAAsAAQAAAAJjYQsAAgAAAAEBCAADAAAAAAwABAgAAX8AAAEGAAL5YAsAAwAAAAx6aXBraW4tcXVlcnkAAAsAAQAAAAZudW1JZHMLAAIAAAAEAAAAAQgAAwAAAAMMAAQIAAF/AAABBgACJMMLAAMAAAAMemlwa2luLXF1ZXJ5AAACAAkAAA==\n";
ScribeSpanConsumer scribe = newScribeSpanConsumer(entry.category, consumer);
expectSuccess(scribe, entry);
// Storage finishes after callback so wait for it.
await().untilAsserted(() -> assertThat(storage.getTraces()).containsExactly(asList(v2)));
assertThat(scribeMetrics.messages()).isEqualTo(1);
assertThat(scribeMetrics.messagesDropped()).isZero();
assertThat(scribeMetrics.bytes()).isEqualTo(Base64.getMimeDecoder().decode(entry.message).length);
assertThat(scribeMetrics.spans()).isEqualTo(1);
assertThat(scribeMetrics.spansDropped()).isZero();
}
use of zipkin2.Callback in project zipkin by openzipkin.
the class ScribeSpanConsumerTest method callbackExceptionDoesntThrow.
/**
* Callbacks are performed asynchronously. If they throw, it hints that we are chaining futures
* when we shouldn't
*/
@Test
void callbackExceptionDoesntThrow() throws Exception {
consumer = (input) -> new Call.Base<Void>() {
@Override
protected Void doExecute() {
throw new AssertionError();
}
@Override
protected void doEnqueue(Callback<Void> callback) {
callback.onError(new NullPointerException());
}
@Override
public Call<Void> clone() {
throw new AssertionError();
}
};
ScribeSpanConsumer scribe = newScribeSpanConsumer("zipkin", consumer);
LogEntry entry = new LogEntry();
entry.category = "zipkin";
entry.message = encodedSpan;
expectSuccess(scribe, entry);
// Storage finishes after callback so wait for it.
await().untilAsserted(() -> assertThat(scribeMetrics.messages()).isEqualTo(1));
assertThat(scribeMetrics.messagesDropped()).isZero();
assertThat(scribeMetrics.bytes()).isEqualTo(bytes.length);
assertThat(scribeMetrics.spans()).isEqualTo(1);
assertThat(scribeMetrics.spansDropped()).isEqualTo(1);
}
use of zipkin2.Callback in project zipkin by openzipkin.
the class ScribeSpanConsumerTest method entriesWithSpansAreConsumed.
@Test
void entriesWithSpansAreConsumed() throws Exception {
ScribeSpanConsumer scribe = newScribeSpanConsumer("zipkin", consumer);
LogEntry entry = new LogEntry();
entry.category = "zipkin";
entry.message = encodedSpan;
expectSuccess(scribe, entry);
// Storage finishes after callback so wait for it.
await().untilAsserted(() -> assertThat(storage.getTraces()).containsExactly(asList(v2)));
assertThat(scribeMetrics.messages()).isEqualTo(1);
assertThat(scribeMetrics.messagesDropped()).isZero();
assertThat(scribeMetrics.bytes()).isEqualTo(bytes.length);
assertThat(scribeMetrics.spans()).isEqualTo(1);
assertThat(scribeMetrics.spansDropped()).isZero();
}
use of zipkin2.Callback in project zipkin by openzipkin.
the class AggregateCallTest method enqueue_blocksOnCompletion.
/**
* This shows that regardless of success or error, we block on completion
*/
@Test(timeout = 1000L)
public void enqueue_blocksOnCompletion() throws InterruptedException {
CountDownLatch callsLatch = new CountDownLatch(10);
ExecutorService exec = Executors.newFixedThreadPool(10);
class LatchCall extends Call.Base<Void> {
final boolean fail;
LatchCall(boolean fail) {
this.fail = fail;
}
@Override
protected Void doExecute() {
throw new UnsupportedOperationException();
}
@Override
protected void doEnqueue(Callback<Void> callback) {
exec.submit(() -> {
try {
callsLatch.await();
} catch (InterruptedException e) {
callback.onError(e);
}
if (fail) {
callback.onError(new IOException());
} else {
callback.onSuccess(null);
}
});
}
@Override
public Call<Void> clone() {
return new LatchCall(fail);
}
}
List<Call<Void>> calls = new ArrayList<>();
for (int i = 0; i < 10; i++) calls.add(new LatchCall(i % 2 == 0));
Call<Void> call = AggregateCall.newVoidCall(calls);
AtomicReference<Object> result = new AtomicReference<>();
call.enqueue(new Callback<Void>() {
@Override
public void onSuccess(Void value) {
result.set("foo");
}
@Override
public void onError(Throwable t) {
result.set(t);
}
});
assertThat(result).hasValue(null);
// one down
callsLatch.countDown();
assertThat(result).hasValue(null);
// two down
callsLatch.countDown();
assertThat(result).hasValue(null);
for (int i = 0; i < 8; i++) callsLatch.countDown();
// wait for threads to finish
exec.shutdown();
exec.awaitTermination(1, TimeUnit.SECONDS);
assertThat(result.get()).isNotNull();
}
use of zipkin2.Callback in project zipkin by openzipkin.
the class AggregateCallTest method enqueue_errorDoesntStopOtherCalls.
@Test
public void enqueue_errorDoesntStopOtherCalls() {
Exception e = new IllegalArgumentException();
errorCallback(call1, e);
successCallback(call2);
Call<Void> call = AggregateCall.newVoidCall(asList(call1, call2));
call.enqueue(callback);
verify(callback).onError(e);
verify(call1).enqueue(any(Callback.class));
verify(call2).enqueue(any(Callback.class));
verifyNoMoreInteractions(call1, call2);
}
Aggregations