Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excavator: Switch to JUnit 5 to parallelize tests and speed up CI #612

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docker-proxy-rule-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ dependencies {
testImplementation group: 'org.assertj', name: 'assertj-core'
testImplementation group: 'org.mockito', name: 'mockito-core'
testRuntimeOnly group: 'org.mockito', name: 'mockito-inline'
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine', {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
}

moduleJvmArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DockerContainerInfoUtilsTest {
private static final String CONTAINER_ID = "container-id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class DockerNameServiceTest {
private static final String HOST_NAME = "host";
Expand Down Expand Up @@ -63,11 +64,13 @@ public void shouldGetIpOfHostFromSupplierEveryTime() throws UnknownHostException
verify(containerInfo, times(2)).getIpForHost(HOST_NAME);
}

@Test(expected = UnknownHostException.class)
@Test
public void shouldThrowUnknownHostExceptionWhenNoIpForHost() throws UnknownHostException {
when(containerInfo.getIpForHost(HOST_NAME)).thenReturn(Optional.empty());
Assertions.assertThrows(UnknownHostException.class, () -> {
when(containerInfo.getIpForHost(HOST_NAME)).thenReturn(Optional.empty());

dockerNameService.lookupAllHostAddr(HOST_NAME);
dockerNameService.lookupAllHostAddr(HOST_NAME);
});
}

@Test
Expand Down Expand Up @@ -98,10 +101,12 @@ public void shouldGetHostOfIpFromSupplierEveryTime() throws UnknownHostException
verify(containerInfo, times(2)).getHostForIp(HOST_IP);
}

@Test(expected = UnknownHostException.class)
@Test
public void shouldThrowUnknownHostExceptionWhenNoHostForIp() throws UnknownHostException {
when(containerInfo.getHostForIp(HOST_IP)).thenReturn(Optional.empty());
Assertions.assertThrows(UnknownHostException.class, () -> {
when(containerInfo.getHostForIp(HOST_IP)).thenReturn(Optional.empty());

dockerNameService.getHostByAddr(HOST_IP_INET.getAddress());
dockerNameService.getHostByAddr(HOST_IP_INET.getAddress());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
import java.net.URISyntaxException;
import java.util.List;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class DockerProxySelectorTest {
private static final String CLUSTER_IP = "172.17.0.1";
Expand All @@ -57,7 +58,7 @@ public class DockerProxySelectorTest {
private final ProxySelector dockerProxySelector =
new DockerProxySelector(setupProxyContainer(), containerInfo, originalProxySelector);

@Before
@BeforeEach
public void originalProxySelectorIsNoProxy() {
when(originalProxySelector.select(any())).thenReturn(ImmutableList.of(Proxy.NO_PROXY));
}
Expand Down Expand Up @@ -92,19 +93,25 @@ public void dockerIpsShouldGoThroughAProxy() {
assertThat(selectedProxy).containsExactly(new Proxy(Proxy.Type.SOCKS, PROXY_ADDRESS));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void connectionFailedShouldThrowOnNullUri() {
dockerProxySelector.connectFailed(null, PROXY_ADDRESS, new IOException());
Assertions.assertThrows(IllegalArgumentException.class, () -> {
dockerProxySelector.connectFailed(null, PROXY_ADDRESS, new IOException());
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void connectionFailedShouldThrowOnNullAddress() {
dockerProxySelector.connectFailed(TEST_HOSTNAME_URI, null, new IOException());
Assertions.assertThrows(IllegalArgumentException.class, () -> {
dockerProxySelector.connectFailed(TEST_HOSTNAME_URI, null, new IOException());
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void connectionFailedShouldThrowOnNullException() {
dockerProxySelector.connectFailed(TEST_HOSTNAME_URI, PROXY_ADDRESS, null);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
dockerProxySelector.connectFailed(TEST_HOSTNAME_URI, PROXY_ADDRESS, null);
});
}

@Test
Expand Down
5 changes: 5 additions & 0 deletions docker-proxy-rule-junit4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ dependencies {

testImplementation group: 'org.assertj', name: 'assertj-core'
testImplementation group: 'org.mockito', name: 'mockito-core'
integrationTestImplementation 'org.junit.jupiter:junit-jupiter'
integrationTestRuntimeOnly 'org.junit.vintage:junit-vintage-engine', {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
testImplementation 'org.junit.jupiter:junit-jupiter'
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.net.URL;
import java.net.URLConnection;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class DockerProxyRuleTest {
@ClassRule
Expand Down Expand Up @@ -125,9 +126,11 @@ public void otherHostnamesStillResolve() throws IOException, InterruptedExceptio
}
}

@Test(expected = IllegalStateException.class)
@Test
public void runningProxyRuleBeforeDockerComposeRuleFails() throws IOException, InterruptedException {
DockerProxyRule.fromNetworkName("doesnotexist", DockerProxyRuleTest.class)
.before();
Assertions.assertThrows(IllegalStateException.class, () -> {
DockerProxyRule.fromNetworkName("doesnotexist", DockerProxyRuleTest.class)
.before();
});
}
}
7 changes: 4 additions & 3 deletions versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ commons-io:commons-io:2.6 (1 constraints: 64156da7)
javax.annotation:javax.annotation-api:1.3.2 (1 constraints: f10f7399)
javax.ws.rs:javax.ws.rs-api:2.1.1 (1 constraints: f10f7399)
joda-time:joda-time:2.10.8 (2 constraints: 222ca439)
junit:junit:4.13.2 (2 constraints: 841bfe6b)
junit:junit:4.13.2 (3 constraints: d22b8dfd)
one.util:streamex:0.8.1 (2 constraints: cd1a403c)
org.apache.commons:commons-lang3:3.7 (1 constraints: 661571a7)
org.apiguardian:apiguardian-api:1.1.2 (5 constraints: 105480ac)
org.apiguardian:apiguardian-api:1.1.2 (6 constraints: 876453cc)
org.awaitility:awaitility:4.0.2 (1 constraints: c015bbd2)
org.hamcrest:hamcrest:2.1 (3 constraints: 3d2cbb31)
org.hamcrest:hamcrest-core:2.1 (1 constraints: cc05fe3f)
Expand All @@ -50,7 +50,8 @@ org.assertj:assertj-core:3.22.0 (1 constraints: 39053f3b)
org.junit.jupiter:junit-jupiter:5.8.2 (1 constraints: 11051e36)
org.junit.jupiter:junit-jupiter-engine:5.8.2 (1 constraints: 0c0edf3b)
org.junit.jupiter:junit-jupiter-params:5.8.2 (1 constraints: 0c0edf3b)
org.junit.platform:junit-platform-engine:1.8.2 (1 constraints: ab1027b4)
org.junit.platform:junit-platform-engine:1.8.2 (2 constraints: 2621c773)
org.junit.vintage:junit-vintage-engine:5.5.0 (1 constraints: 0c051336)
org.mockito:mockito-core:4.4.0 (2 constraints: f11021d5)
org.mockito:mockito-inline:4.4.0 (1 constraints: 0a050b36)
org.objenesis:objenesis:3.2 (1 constraints: b10a13bd)
1 change: 1 addition & 0 deletions versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ junit:junit = 4.13.2
one.util:streamex = 0.8.1
org.assertj:assertj-core = 3.22.0
org.junit.jupiter:* = 5.8.2
org.junit.vintage:* = 5.5.0
org.mockito:* = 4.4.0
org.hamcrest:* = 2.1
net.bytebuddy:* = 1.14.11