Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.generic.GenericKubernetesApi;
import java.util.Collections;
import java.util.concurrent.Semaphore;
import java.util.concurrent.CountDownLatch;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -58,8 +58,8 @@ public String getName() {

@Override
public void doAction(ServeEvent serveEvent, Admin admin, Parameters parameters) {
Semaphore count = (Semaphore) parameters.get("semaphore");
count.release();
CountDownLatch latch = (CountDownLatch) parameters.get("semaphore");
latch.countDown();
}
}

Expand Down Expand Up @@ -107,12 +107,18 @@ void informerInjection() throws InterruptedException {
assertThat(podInformer).isNotNull();
assertThat(configMapInformer).isNotNull();

Semaphore getCount = new Semaphore(2);
Semaphore watchCount = new Semaphore(2);
Parameters getParams = new Parameters();
Parameters watchParams = new Parameters();
getParams.put("semaphore", getCount);
watchParams.put("semaphore", watchCount);
CountDownLatch podGetLatch = new CountDownLatch(1);
CountDownLatch podWatchLatch = new CountDownLatch(1);
CountDownLatch configMapGetLatch = new CountDownLatch(1);
CountDownLatch configMapWatchLatch = new CountDownLatch(1);
Parameters podGetParams = new Parameters();
Parameters podWatchParams = new Parameters();
Parameters configMapGetParams = new Parameters();
Parameters configMapWatchParams = new Parameters();
podGetParams.put("semaphore", podGetLatch);
podWatchParams.put("semaphore", podWatchLatch);
configMapGetParams.put("semaphore", configMapGetLatch);
configMapWatchParams.put("semaphore", configMapWatchLatch);

V1Pod foo1 =
new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
Expand All @@ -123,7 +129,7 @@ void informerInjection() throws InterruptedException {

apiServer.stubFor(
get(urlPathEqualTo("/api/v1/pods"))
.withPostServeAction("semaphore", getParams)
.withPostServeAction("semaphore", podGetParams)
.withQueryParam("watch", equalTo("false"))
.atPriority(1)
.willReturn(
Expand All @@ -137,7 +143,7 @@ void informerInjection() throws InterruptedException {
.items(Collections.singletonList(foo1))))));
apiServer.stubFor(
get(urlPathEqualTo("/api/v1/pods"))
.withPostServeAction("semaphore", watchParams)
.withPostServeAction("semaphore", podWatchParams)
.withQueryParam("watch", equalTo("true"))
.atPriority(2)
.willReturn(
Expand All @@ -148,7 +154,7 @@ void informerInjection() throws InterruptedException {

apiServer.stubFor(
get(urlPathEqualTo("/api/v1/namespaces/default/configmaps"))
.withPostServeAction("semaphore", getParams)
.withPostServeAction("semaphore", configMapGetParams)
.withQueryParam("watch", equalTo("false"))
.atPriority(1)
.willReturn(
Expand All @@ -162,7 +168,7 @@ void informerInjection() throws InterruptedException {
.items(Collections.singletonList(bar1))))));
apiServer.stubFor(
get(urlPathEqualTo("/api/v1/namespaces/default/configmaps"))
.withPostServeAction("semaphore", watchParams)
.withPostServeAction("semaphore", configMapWatchParams)
.withQueryParam("watch", equalTo("true"))
.atPriority(2)
.willReturn(
Expand All @@ -171,15 +177,13 @@ void informerInjection() throws InterruptedException {
.withHeader("Content-Type", "application/json")
.withBody("{}")));

// These will be released for each web call above.
getCount.acquire(2);
watchCount.acquire(2);

informerFactory.startAllRegisteredInformers();

// Wait for the GETs to complete and the watches to start.
getCount.acquire(2);
watchCount.acquire(2);
// Wait for each informer's list and watch to complete independently.
podGetLatch.await();
podWatchLatch.await();
configMapGetLatch.await();
configMapWatchLatch.await();

apiServer.verify(
1,
Expand Down