fabric8io / kubernetes-client

Java client for Kubernetes & OpenShift
http://fabric8.io
Apache License 2.0
3.35k stars 1.44k forks source link

NPE when using mock Kubernetes Server #1818

Open lalithsuresh opened 4 years ago

lalithsuresh commented 4 years ago

Following what I could find in kubernetes-tests, I'm running into the following NPE when using the Kubernetes mock server.

public class MyTest {
    @Rule
    public KubernetesServer server = new KubernetesServer(false);

    @Test
    public void testInformer() {
        System.out.println(server.expect());
    }
}

NPE:

java.lang.NullPointerException
    at io.fabric8.kubernetes.client.server.mock.KubernetesServer.expect(KubernetesServer.java:72)

The dependencies I used were:

         <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>kubernetes-client</artifactId>
            <version>4.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>kubernetes-server-mock</artifactId>
            <version>4.6.1</version>
            <scope>test</scope>
        </dependency>   

I've tried different variants of the KubernetesServer constructors to no avail. What am I missing?

lalithsuresh commented 4 years ago

It appears that server.before() isn't being invoked by the @Rule. Invoking it manually works.

rohanKanojia commented 4 years ago

@lalithsuresh : ah, I see. Would it be possible for you to raise a PR to fix this behavior(if you have some time ;-) )?

lalithsuresh commented 4 years ago

I'll have a look sometime in the coming days.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

SahibYar commented 3 months ago

This issue should not be marked as closed / completed, facing same issue in 6.11.0

manusa commented 2 weeks ago

This issue should not be marked as closed / completed, facing same issue in 6.11.0

Could you please provide some sort of reproducer project? (@SahibYar)