Skip to content

Commit

Permalink
Excavator: Switch to JUnit 5 to parallelize tests and speed up CI
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot committed Feb 4, 2023
1 parent b973b41 commit 1377f52
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 59 deletions.
1 change: 1 addition & 0 deletions tracing-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ dependencies {

annotationProcessor "org.immutables:value"
compileOnly "org.immutables:value::annotations"
testImplementation 'org.junit.jupiter:junit-jupiter'
}
5 changes: 5 additions & 0 deletions tracing-okhttp3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ dependencies {
testImplementation "junit:junit"
testImplementation "org.assertj:assertj-core"
testImplementation "org.mockito:mockito-core"
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine', {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
testImplementation 'org.mockito:mockito-junit-jupiter'
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@
import java.util.Optional;
import okhttp3.Interceptor;
import okhttp3.Request;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@SuppressWarnings("deprecation")
public final class OkhttpTraceInterceptorTest {

Expand All @@ -59,14 +62,14 @@ public final class OkhttpTraceInterceptorTest {
@Captor
private ArgumentCaptor<Span> spanCaptor;

@Before
@BeforeEach
public void before() {
Request request = new Request.Builder().url("http://localhost").build();
when(chain.request()).thenReturn(request);
Tracer.subscribe("", observer);
}

@After
@AfterEach
public void after() {
Tracer.initTraceWithSpan(Observability.SAMPLE, Tracers.randomId(), "op", SpanType.LOCAL);
Tracer.unsubscribe("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.palantir.tracing;

import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class RenderTracingRuleDemo {

Expand Down
5 changes: 5 additions & 0 deletions tracing-undertow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine', {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
testImplementation 'org.mockito:mockito-junit-jupiter'
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@
import io.undertow.util.HttpString;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.slf4j.MDC;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class TracedOperationHandlerTest {

@Captor
Expand All @@ -69,7 +72,7 @@ public class TracedOperationHandlerTest {

private TracedOperationHandler handler;

@Before
@BeforeEach
public void before() {
Tracer.subscribe("TEST_OBSERVER", observer);
Tracer.setSampler(traceSampler);
Expand All @@ -83,7 +86,7 @@ public void before() {
handler = new TracedOperationHandler(delegate, "GET /foo");
}

@After
@AfterEach
public void after() {
Tracer.unsubscribe("TEST_OBSERVER");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class TracedRequestHandlerTest {

private static final AtomicInteger portSelector = new AtomicInteger(4439);
Expand All @@ -68,7 +71,7 @@ public class TracedRequestHandlerTest {

private volatile TagTranslator<? super HttpServerExchange> translator;

@Before
@BeforeEach
public void before() {
Tracer.subscribe("TracedRequestHandlerTest", observer);
Tracer.setSampler(traceSampler);
Expand Down Expand Up @@ -101,7 +104,7 @@ public <T> void translate(TagAdapter<T> adapter, T target, HttpServerExchange da
server.start();
}

@After
@AfterEach
public void after() {
Tracer.unsubscribe("TracedRequestHandlerTest");
server.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
import io.undertow.util.HeaderMap;
import io.undertow.util.HttpString;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.slf4j.MDC;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class TracedStateHandlerTest {

@Mock
Expand All @@ -58,7 +61,7 @@ public class TracedStateHandlerTest {

private HttpHandler handler;

@Before
@BeforeEach
public void before() {
Tracer.subscribe("TEST_OBSERVER", observer);
Tracer.setSampler(traceSampler);
Expand All @@ -72,7 +75,7 @@ public void before() {
handler = new TracedStateHandler(delegate);
}

@After
@AfterEach
public void after() {
Tracer.unsubscribe("TEST_OBSERVER");
}
Expand Down
5 changes: 5 additions & 0 deletions tracing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ dependencies {

annotationProcessor "org.immutables:value"
compileOnly "org.immutables:value::annotations"
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine', {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
testImplementation 'org.mockito:mockito-junit-jupiter'
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
import com.palantir.tracing.api.Span;
import com.palantir.tracing.api.SpanObserver;
import com.palantir.tracing.api.SpanType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public final class CloseableTracerTest {

@Before
@BeforeEach
public void before() {
Tracer.setSampler(AlwaysSampler.INSTANCE);
Tracer.getAndClearTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DeferredTracerTest {

Expand Down
10 changes: 5 additions & 5 deletions tracing/src/test/java/com/palantir/tracing/DetachedSpanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.MDC;

public final class DetachedSpanTest {

@Before
@BeforeEach
public void before() {
MDC.clear();
Tracer.clearCurrentTrace();
}

@After
@AfterEach
public void after() {
// Clear out the old trace from each test
Tracer.clearCurrentTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TagTranslatorTest {

Expand Down
2 changes: 1 addition & 1 deletion tracing/src/test/java/com/palantir/tracing/TraceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.palantir.tracing.api.OpenSpan;
import com.palantir.tracing.api.SpanType;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public final class TraceTest {

Expand Down
17 changes: 10 additions & 7 deletions tracing/src/test/java/com/palantir/tracing/TracerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@
import java.util.Optional;
import java.util.Set;
import org.assertj.core.util.Sets;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.slf4j.MDC;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public final class TracerTest {

@Mock
Expand All @@ -58,13 +61,13 @@ public final class TracerTest {
@Captor
private ArgumentCaptor<Span> spanCaptor;

@After
@AfterEach
public void before() {
Tracer.getAndClearTraceIfPresent();
Tracer.setSampler(AlwaysSampler.INSTANCE);
}

@After
@AfterEach
public void after() {
Tracer.initTraceWithSpan(Observability.SAMPLE, Tracers.randomId(), "op", SpanType.LOCAL);
Tracer.setSampler(AlwaysSampler.INSTANCE);
Expand Down
10 changes: 5 additions & 5 deletions tracing/src/test/java/com/palantir/tracing/TracersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.MDC;

@SuppressWarnings("deprecation")
public final class TracersTest {

@Before
@BeforeEach
public void before() {
MDC.clear();

Expand All @@ -67,7 +67,7 @@ public void before() {
Observability.SAMPLE, "defaultTraceId", Optional.of("forUserAgent"), "rootOperation", SpanType.LOCAL);
}

@After
@AfterEach
public void after() {
// Clear out the old trace from each test
Tracer.clearCurrentTrace();
Expand Down

0 comments on commit 1377f52

Please sign in to comment.