Skip to content

Commit

Permalink
Cleans up RPC instrumentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed May 13, 2017
1 parent 53b68e1 commit 2d2a2be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 48 deletions.
Expand Up @@ -21,32 +21,28 @@
import io.grpc.StatusRuntimeException;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloRequest;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import zipkin.BinaryAnnotation;
import zipkin.Constants;
import zipkin.Endpoint;
import zipkin.Span;
import zipkin.storage.InMemoryStorage;
import zipkin.internal.Util;

import static brave.grpc.GreeterImpl.HELLO_REQUEST;
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
import static org.assertj.core.api.Assertions.tuple;

public class ITTracingServerInterceptor {

@Rule public ExpectedException thrown = ExpectedException.none();

Endpoint local = Endpoint.builder().serviceName("local").ipv4(127 << 24 | 1).port(100).build();
InMemoryStorage storage = new InMemoryStorage();
ConcurrentLinkedDeque<Span> spans = new ConcurrentLinkedDeque<>();

Tracing tracing;
Server server;
Expand Down Expand Up @@ -152,23 +148,15 @@ public void addsErrorTagOnException() throws Exception {
} catch (StatusRuntimeException e) {
assertThat(spans)
.flatExtracting(s -> s.binaryAnnotations)
.contains(
BinaryAnnotation.create(Constants.ERROR, e.getStatus().getCode().toString(), local));
.extracting(b -> tuple(b.key, new String(b.value, Util.UTF_8)))
.contains(tuple(Constants.ERROR, e.getStatus().getCode().toString()));
}
}

Tracing.Builder tracingBuilder(Sampler sampler) {
return Tracing.newBuilder()
.reporter(s -> storage.spanConsumer().accept(asList(s)))
.reporter(spans::add)
.currentTraceContext(new StrictCurrentTraceContext())
.localEndpoint(local)
.sampler(sampler);
}

List<Span> spans {
List<List<Span>> result = storage.spanStore().getRawTraces();
if (result.isEmpty()) return Collections.emptyList();
assertThat(result).hasSize(1);
return result.get(0);
}
}
Expand Up @@ -9,18 +9,16 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedDeque;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import zipkin.Constants;
import zipkin.Endpoint;
import zipkin.Span;
import zipkin.TraceKeys;
import zipkin.internal.MergeById;
import zipkin.internal.Util;
import zipkin.storage.InMemoryStorage;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.junit.Assume.assumeTrue;
Expand All @@ -29,8 +27,7 @@
public class ITTracingStatementInterceptor {
static final String QUERY = "select 'hello world'";

Endpoint local = Endpoint.builder().serviceName("local").ipv4(127 << 24 | 1).port(100).build();
InMemoryStorage storage = new InMemoryStorage();
ConcurrentLinkedDeque<Span> spans = new ConcurrentLinkedDeque<>();

Tracing tracing = tracingBuilder(Sampler.ALWAYS_SAMPLE).build();
Connection connection;
Expand All @@ -52,7 +49,7 @@ public class ITTracingStatementInterceptor {
dataSource.getUser() != null);
dataSource.setPassword(envOr("MYSQL_PASS", ""));
connection = dataSource.getConnection();
storage.clear(); // clear any spans for test statements
spans.clear();
}

@After public void close() throws SQLException {
Expand Down Expand Up @@ -125,15 +122,8 @@ void prepareExecuteSelect(String query) throws SQLException {

Tracing.Builder tracingBuilder(Sampler sampler) {
return Tracing.newBuilder()
.reporter(s -> storage.spanConsumer().accept(asList(s)))
.reporter(spans::add)
.currentTraceContext(new StrictCurrentTraceContext())
.localEndpoint(local)
.sampler(sampler);
}

List<Span> spans {
List<List<Span>> result = storage.spanStore().getRawTraces();
assertThat(result).hasSize(1);
return result.get(0);
}
}
Expand Up @@ -9,18 +9,15 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedDeque;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import zipkin.Constants;
import zipkin.Endpoint;
import zipkin.Span;
import zipkin.TraceKeys;
import zipkin.internal.Util;
import zipkin.storage.InMemoryStorage;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;

Expand All @@ -33,8 +30,7 @@ public class ITTracingP6Factory {
DerbyUtils.disableLog();
}

Endpoint local = Endpoint.builder().serviceName("local").ipv4(127 << 24 | 1).port(100).build();
InMemoryStorage storage = new InMemoryStorage();
ConcurrentLinkedDeque<Span> spans = new ConcurrentLinkedDeque<>();

Tracing tracing = tracingBuilder(Sampler.ALWAYS_SAMPLE).build();
Connection connection;
Expand Down Expand Up @@ -116,15 +112,8 @@ void prepareExecuteSelect(String query) throws SQLException {

Tracing.Builder tracingBuilder(Sampler sampler) {
return Tracing.newBuilder()
.reporter(s -> storage.spanConsumer().accept(asList(s)))
.reporter(spans::add)
.currentTraceContext(new StrictCurrentTraceContext())
.localEndpoint(local)
.sampler(sampler);
}

List<Span> spans {
List<List<Span>> result = storage.spanStore().getRawTraces();
assertThat(result).hasSize(1);
return result.get(0);
}
}

0 comments on commit 2d2a2be

Please sign in to comment.