forked from fabric8io/kubernetes-client
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes fabric8io#2306: Make KubernetesServer CRUD mode work with infor…
…mers This is addressed by making sure that MockWebServer returns a metadata object for list queries. Signed-off-by: Lalith Suresh <lsuresh@vmware.com>
- Loading branch information
1 parent
55cf52c
commit 73829ea
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CrudInformerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.fabric8.kubernetes.client.mock; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodBuilder; | ||
import io.fabric8.kubernetes.api.model.PodList; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.informers.ResourceEventHandler; | ||
import io.fabric8.kubernetes.client.informers.SharedIndexInformer; | ||
import io.fabric8.kubernetes.client.informers.SharedInformerFactory; | ||
import io.fabric8.kubernetes.client.server.mock.KubernetesServer; | ||
import org.junit.Rule; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@EnableRuleMigrationSupport | ||
public class CrudInformerTest { | ||
@Rule | ||
public KubernetesServer server = new KubernetesServer(true, true); | ||
|
||
// https://github.com/fabric8io/kubernetes-client/issues/2306 | ||
@Test | ||
void testCrudInformer() throws InterruptedException { | ||
Pod podToCreate = new PodBuilder().withNewMetadata().withName("pod1").endMetadata().build(); | ||
KubernetesClient client = server.getClient(); | ||
SharedInformerFactory factory = client.informers(); | ||
SharedIndexInformer<Pod> podInformer = factory.sharedIndexInformerFor(Pod.class, PodList.class, 4000); | ||
BlockingQueue<Pod> events = new LinkedBlockingQueue<>(); | ||
podInformer.addEventHandler( | ||
new ResourceEventHandler<Pod>() { | ||
@Override | ||
public void onAdd(Pod obj) { | ||
events.add(obj); | ||
} | ||
|
||
@Override | ||
public void onUpdate(Pod oldObj, Pod newObj) { | ||
} | ||
|
||
@Override | ||
public void onDelete(Pod oldObj, boolean deletedFinalStateUnknown) { | ||
} | ||
}); | ||
factory.startAllRegisteredInformers(); | ||
client.pods().create(podToCreate); | ||
Pod readPod = events.poll(5, TimeUnit.SECONDS); | ||
assertNotNull(readPod); | ||
assertEquals(readPod.getMetadata().getName(), podToCreate.getMetadata().getName()); | ||
factory.stopAllRegisteredInformers(); | ||
} | ||
} |