Skip to content

Commit

Permalink
Provides a way to enable/disable the docker integration tests via a g…
Browse files Browse the repository at this point in the history
…radle property (#1115)

* Provides a way to disable the docker integration tests via a gradle property.

* switch the property to be the opposite

* add a new make target and let CI use it.

* Update gradle.properties

Co-Authored-By: Armin Ruech <armin.ruech@gmail.com>

* Update exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java

Co-Authored-By: Armin Ruech <armin.ruech@gmail.com>

* Update exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java

Co-Authored-By: Armin Ruech <armin.ruech@gmail.com>

* simplify the test flow

Co-authored-by: Armin Ruech <armin.ruech@gmail.com>
  • Loading branch information
jkwatson and arminru committed Apr 16, 2020
1 parent 36661f1 commit c32c776
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ init_task: &init_task
command: make init-git-submodules
build_task: &build_task
name: Build
command: make test
command: make test-with-docker
compile_benchmark_task: &compile_benchmark_task
name: Compile JMH
command: make benchmark
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ Continuous integration builds the project, runs the tests, and runs multiple
types of static analysis.

1. Note: Currently, to run the full suite of tests, you'll need to be running a docker daemon.
The tests that require docker are disabled by default. If you wish to run them,
you can enable the docker tests by setting a gradle property of
``"enable.docker.tests"`` to true. See the gradle.properties file in the root of the project
for more details.

2. From the root project directory, initialize repository dependencies

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
test:
./gradlew clean assemble check --stacktrace

.PHONY: test-with-docker
test-with-docker:
./gradlew -Penable.docker.tests=true clean assemble check --stacktrace

.PHONY: benchmark
benchmark:
./gradlew compileJmhJava
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ subprojects {
// see: https://github.com/grpc/grpc-java/issues/3633
compile("javax.annotation:javax.annotation-api:1.3.2")
}

test {
systemProperties project.properties.subMap(["enable.docker.tests"])
}
}

javadoc.options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.export.SimpleSpansProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Tracer;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.awaitility.Awaitility;
import org.junit.Before;
import org.junit.Assume;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -49,35 +51,43 @@ public class JaegerIntegrationTest {
private static final String JAEGER_URL = "http://localhost";
private final Tracer tracer =
OpenTelemetry.getTracerProvider().get(getClass().getCanonicalName());
private JaegerGrpcSpanExporter jaegerExporter;

@SuppressWarnings("rawtypes")
@ClassRule
public static GenericContainer jaeger =
new GenericContainer("jaegertracing/all-in-one:" + JAEGER_VERSION)
.withExposedPorts(COLLECTOR_PORT, QUERY_PORT)
.waitingFor(new HttpWaitStrategy().forPath("/"));
@Nullable
public static GenericContainer jaegerContainer = null;

@Before
public void setupJaegerExporter() {
static {
// make sure that the user has enabled the docker-based tests
if (Boolean.getBoolean("enable.docker.tests")) {
jaegerContainer =
new GenericContainer<>("jaegertracing/all-in-one:" + JAEGER_VERSION)
.withExposedPorts(COLLECTOR_PORT, QUERY_PORT)
.waitingFor(new HttpWaitStrategy().forPath("/"));
}
}

@Test
public void testJaegerIntegration() {
Assume.assumeNotNull(jaegerContainer);
setupJaegerExporter();
imitateWork();
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(assertJaegerHaveTrace());
}

private static void setupJaegerExporter() {
ManagedChannel jaegerChannel =
ManagedChannelBuilder.forAddress("127.0.0.1", jaeger.getMappedPort(COLLECTOR_PORT))
ManagedChannelBuilder.forAddress("127.0.0.1", jaegerContainer.getMappedPort(COLLECTOR_PORT))
.usePlaintext()
.build();
this.jaegerExporter =
SpanExporter jaegerExporter =
JaegerGrpcSpanExporter.newBuilder()
.setServiceName(SERVICE_NAME)
.setChannel(jaegerChannel)
.setDeadlineMs(30000)
.build();
OpenTelemetrySdk.getTracerProvider()
.addSpanProcessor(SimpleSpansProcessor.newBuilder(this.jaegerExporter).build());
}

@Test
public void testJaegerIntegration() {
imitateWork();
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(assertJaegerHaveTrace());
.addSpanProcessor(SimpleSpansProcessor.newBuilder(jaegerExporter).build());
}

private void imitateWork() {
Expand All @@ -99,7 +109,7 @@ public Boolean call() {
String url =
String.format(
"%s/api/traces?service=%s",
String.format(JAEGER_URL + ":%d", jaeger.getMappedPort(QUERY_PORT)),
String.format(JAEGER_URL + ":%d", jaegerContainer.getMappedPort(QUERY_PORT)),
SERVICE_NAME);
Response response =
given()
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
org.gradle.parallel=true
org.gradle.workers.max=4
org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m

### Override this property to 'true' to enable the end-to-end tests that use docker.
### This can be done via -Penable.docker.tests=true on the command line, or by
### setting this property to true in the gradle.properties in your home directory.
enable.docker.tests=false

0 comments on commit c32c776

Please sign in to comment.