Skip to content

Commit

Permalink
Merge pull request #3178 from codefromthecrypt/migrate-to-jupiter
Browse files Browse the repository at this point in the history
Migrate to JUnit Jupiter
  • Loading branch information
k8s-ci-robot authored Mar 14, 2024
2 parents ec220f3 + 24749c7 commit aa01cb7
Show file tree
Hide file tree
Showing 131 changed files with 1,740 additions and 1,731 deletions.
4 changes: 2 additions & 2 deletions e2e/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1Status;
import io.kubernetes.client.util.ClientBuilder;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CoreV1ApiTest {
class CoreV1ApiTest {

@Test
public void testCreateAndDeleteNamespace() throws Exception {
void createAndDeleteNamespace() throws Exception {
ApiClient client = ClientBuilder.defaultClient();
CoreV1Api coreV1Api = new CoreV1Api(client);
V1Namespace namespaceFoo = new V1Namespace()
Expand Down
6 changes: 3 additions & 3 deletions e2e/src/test/java/io/kubernetes/client/e2e/csr/CSRTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CSRTest {
class CSRTest {

@Test
public void testBuildClientWithCSR() throws Exception {
void buildClientWithCSR() throws Exception {
// initialize test environment
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048, new SecureRandom());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesApi;
import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject;
import io.kubernetes.client.util.generic.dynamic.Dynamics;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DynamicApiTest {
class DynamicApiTest {

@Test
public void testDynamicApiCreateAndDeleteNamespace() throws Exception {
void dynamicApiCreateAndDeleteNamespace() throws Exception {
ApiClient client = ClientBuilder.defaultClient();
DynamicKubernetesApi dynamicApi =
new DynamicKubernetesApi("", "v1", "namespaces", client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.kubernetes.client.openapi.apis.CoordinationV1Api;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.util.ClientBuilder;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.time.Duration;
import java.util.ArrayList;
Expand All @@ -34,17 +33,16 @@
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(Parameterized.class)
public class LeaderElectorTest {
class LeaderElectorTest {

private static final Logger LOGGER = LoggerFactory.getLogger(LeaderElectorTest.class);

Expand All @@ -57,7 +55,6 @@ private enum LockType {
Lease
}

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> constructorFeeder() {
final List<Object[]> args = new ArrayList<>();

Expand All @@ -68,20 +65,11 @@ public static Collection<Object[]> constructorFeeder() {
return args;
}

private final ApiClient apiClient;
private final LockType lockType;
private ApiClient apiClient;
private LockType lockType;

public LeaderElectorTest(LockType lockType) {
try {
apiClient = ClientBuilder.defaultClient();
} catch (IOException ex) {
throw new RuntimeException("Couldn't create ApiClient", ex);
}
this.lockType = lockType;
}

@Before
public void setup() throws Exception {
private void initLeaderElectorTest(LockType lockType) throws Exception {
apiClient = ClientBuilder.defaultClient();
// delete the lock resource if it exists, or else first leader candidate might need to wait for
// a whole leaseDuration configured
switch (lockType) {
Expand All @@ -97,19 +85,23 @@ public void setup() throws Exception {
default:
throw new RuntimeException("Unknown LockType " + lockType);
}
this.lockType = lockType;
}

@Test(timeout = 30000L)
public void testSingleCandidateLeaderElection() throws Exception {
@MethodSource("constructorFeeder")
@ParameterizedTest(name = "{0}")
@Timeout(value = 30000L, unit = TimeUnit.MILLISECONDS)
void singleCandidateLeaderElection(LockType lockType) throws Exception {
initLeaderElectorTest(lockType);
CountDownLatch startLeadershipLatch = new CountDownLatch(1);
CountDownLatch stopLeadershipLatch = new CountDownLatch(1);

LeaderElector leaderElector =
makeAndRunLeaderElectorAsync(
"candidate",
null,
() -> startLeadershipLatch.countDown(),
() -> stopLeadershipLatch.countDown(),
startLeadershipLatch::countDown,
stopLeadershipLatch::countDown,
apiClient);

startLeadershipLatch.await();
Expand All @@ -119,8 +111,11 @@ public void testSingleCandidateLeaderElection() throws Exception {
stopLeadershipLatch.await();
}

@Test(timeout = 30000L)
public void testMultiCandidateLeaderElection() throws Exception {
@MethodSource("constructorFeeder")
@ParameterizedTest(name = "{0}")
@Timeout(value = 30000L, unit = TimeUnit.MILLISECONDS)
void multiCandidateLeaderElection(LockType lockType) throws Exception {
initLeaderElectorTest(lockType);
CyclicBarrier startBarrier = new CyclicBarrier(2);

CountDownLatch startBeingLeader = new CountDownLatch(1);
Expand Down Expand Up @@ -186,17 +181,20 @@ public void testMultiCandidateLeaderElection() throws Exception {
assertThat(stopBeingLeaderCount).hasValue(1);
}

@Test(timeout = 45000L)
public void testLeaderGracefulShutdown() throws Exception {
@MethodSource("constructorFeeder")
@ParameterizedTest(name = "{0}")
@Timeout(value = 45000L, unit = TimeUnit.MILLISECONDS)
void leaderGracefulShutdown(LockType lockType) throws Exception {
initLeaderElectorTest(lockType);
CountDownLatch startBeingLeader1 = new CountDownLatch(1);
CountDownLatch stopBeingLeader1 = new CountDownLatch(1);

LeaderElector leaderElector1 =
makeAndRunLeaderElectorAsync(
"candidate1",
null,
() -> startBeingLeader1.countDown(),
() -> stopBeingLeader1.countDown(),
startBeingLeader1::countDown,
stopBeingLeader1::countDown,
apiClient);

// wait for candidate1 to become leader
Expand All @@ -209,8 +207,8 @@ public void testLeaderGracefulShutdown() throws Exception {
makeAndRunLeaderElectorAsync(
"candidate2",
null,
() -> startBeingLeader2.countDown(),
() -> stopBeingLeader2.countDown(),
startBeingLeader2::countDown,
stopBeingLeader2::countDown,
apiClient);

leaderElector1.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import io.kubernetes.client.openapi.models.V1NamespaceList;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.generic.GenericKubernetesApi;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class NamespaceInformerTest {
class NamespaceInformerTest {
@Test
public void testListWatchingNamespaces() throws Exception {
void listWatchingNamespaces() throws Exception {
ApiClient client = ClientBuilder.defaultClient();
SharedInformerFactory informerFactory = new SharedInformerFactory(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import io.kubernetes.client.openapi.models.V1PodSpec;
import io.kubernetes.client.util.ClientBuilder;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class KubectlDrainTest {
class KubectlDrainTest {
@Test
public void testPodInvisibleAfterDrain() throws Exception {
void podInvisibleAfterDrain() throws Exception {
Configuration.setDefaultApiClient(ClientBuilder.defaultClient());

V1Node testNode = new V1Node().metadata(new V1ObjectMeta().name("foo"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import io.kubernetes.client.openapi.models.V1Namespace;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.util.ClientBuilder;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class KubectlNamespaceTest {
class KubectlNamespaceTest {

@Test
public void testCreateApplyDelete() throws Exception {
void createApplyDelete() throws Exception {
ApiClient client = ClientBuilder.standard().build();

// Create a namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class KubectlRolloutTest {
@Before
public void setup() throws Exception {
class KubectlRolloutTest {
@BeforeEach
void setup() throws Exception {
Configuration.setDefaultApiClient(ClientBuilder.defaultClient());
}

@Test
public void testRolloutDaemonSet() throws Exception {
void rolloutDaemonSet() throws Exception {
testRollout(V1DaemonSet.class, "/test-daemonset.yaml", "/test-daemonset-updated.yaml");
}

@Test
public void testRolloutDeployment() throws Exception {
void rolloutDeployment() throws Exception {
testRollout(V1Deployment.class, "/test-deployment.yaml", "/test-deployment-updated.yaml");
}

@Test
public void testRolloutStatefulSet() throws Exception {
void rolloutStatefulSet() throws Exception {
testRollout(V1StatefulSet.class, "/test-statefulset.yaml", "/test-statefulset-updated.yaml");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.ModelMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ModelMapperTest {
class ModelMapperTest {

@Test
public void apiDiscoveryShouldWork() throws Exception {
void apiDiscoveryShouldWork() throws Exception {
Discovery discovery = new Discovery(ClientBuilder.defaultClient());
ModelMapper.refresh(discovery);

Expand Down
4 changes: 2 additions & 2 deletions examples/examples-release-17/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,36 @@

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Configuration;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.V1Namespace;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class ExampleTest {
class ExampleTest {
private static final int PORT = 8089;
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);

@RegisterExtension
static WireMockExtension apiServer =
WireMockExtension.newInstance().options(WireMockConfiguration.options().port(PORT)).build();

@Test
public void exactUrlOnly() throws ApiException {
void exactUrlOnly() throws ApiException {
ApiClient client = new ApiClient();
client.setBasePath("http://localhost:" + PORT);
Configuration.setDefaultApiClient(client);

V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name"));

stubFor(
apiServer.stubFor(
get(urlEqualTo("/api/v1/namespaces/name"))
.willReturn(
aResponse()
Expand Down
4 changes: 2 additions & 2 deletions examples/examples-release-18/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Loading

0 comments on commit aa01cb7

Please sign in to comment.