Search in sources :

Example 86 with Callback

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/Cr7zj4CwACAAAIAGFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYW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WFhYWFhYWFhYWFhYWFhDAADCAABfwAAAQYAAiTDCwADAAAADHppcGtpbi1xdWVyeQAACgABAAUf8KwLPyILAAIAAABOR2MoOSwwLlBTU2NhdmVuZ2UsMjAxNS0wOS0xNyAxMjozNzowMiArMDAwMCwzMDQubWlsbGlzZWNvbmRzKzc2Mi5taWNyb3NlY29uZHMpDAADCAABfwAAAQYAAiTDCwADAAAADHppcGtpbi1xdWVyeQAIAAQABKZ6AAoAAQAFH/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();
}
Also used : LogEntry(zipkin2.collector.scribe.generated.LogEntry) Test(org.junit.jupiter.api.Test)

Example 87 with Callback

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);
}
Also used : Call(zipkin2.Call) LogEntry(zipkin2.collector.scribe.generated.LogEntry) Test(org.junit.jupiter.api.Test)

Example 88 with Callback

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();
}
Also used : LogEntry(zipkin2.collector.scribe.generated.LogEntry) Test(org.junit.jupiter.api.Test)

Example 89 with Callback

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();
}
Also used : Call(zipkin2.Call) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Callback(zipkin2.Callback) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 90 with Callback

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);
}
Also used : Callback(zipkin2.Callback) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Callback (okhttp3.Callback)173 IOException (java.io.IOException)137 Call (okhttp3.Call)132 Response (okhttp3.Response)132 Request (okhttp3.Request)110 Callback (retrofit2.Callback)42 Call (retrofit2.Call)41 Test (org.junit.Test)39 Response (retrofit2.Response)39 RequestBody (okhttp3.RequestBody)37 OkHttpClient (okhttp3.OkHttpClient)34 File (java.io.File)27 Context (android.content.Context)24 JSONObject (org.json.JSONObject)20 FormBody (okhttp3.FormBody)19 ArrayList (java.util.ArrayList)18 View (android.view.View)16 Intent (android.content.Intent)14 TextView (android.widget.TextView)14 GsonBuilder (com.google.gson.GsonBuilder)14