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

Failure in update while operating on CRUD mode on Kubernetes mock server #957

Closed
rohanKanojia opened this issue Dec 18, 2017 · 5 comments
Closed

Comments

@rohanKanojia
Copy link
Member

rohanKanojia commented Dec 18, 2017

Here is some code snippet that uses Kubernetes mock server in crud mode:

public class SecretCrudTest {
  @Rule
  public KubernetesServer server = new KubernetesServer(true, true);

  @Test
  public void testCrud() {
    KubernetesClient client = server.getClient();

    Secret secret1 = new SecretBuilder()
      .withNewMetadata().withName("secret1").addToLabels("foo", "bar").endMetadata()
      .addToData("username", "guccifer")
      .addToData("password", "shadowgovernment")
      .addToData("secret1", "SECRET1")
      .build();

    Secret secret2 = new SecretBuilder()
      .withNewMetadata().withName("secret2").addToLabels("foo", "bar").endMetadata()
      .addToData("one", "1")
      .build();

    client.secrets().inNamespace("ns1").create(secret1);
    client.secrets().inNamespace("ns2").create(secret2);

    secret2 = client.secrets().inNamespace("ns2").withName("secret2").edit().removeFromData("one").done();
    assertNotNull(secret2);
    assertEquals(null, secret2.getData().get("one"));
  }
}

Whenever i try to udpdate this, i get a NullPointer exception :

Dec 18, 2017 12:20:38 PM okhttp3.mockwebserver.MockWebServer$2 acceptConnections
INFO: MockWebServer[42605] done accepting connections: Socket closed
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.199 sec <<< FAILURE! - in io.fabric8.kubernetes.client.mock.SecretCrudTest
testCrud(io.fabric8.kubernetes.client.mock.SecretCrudTest)  Time elapsed: 3.08 sec  <<< ERROR!
java.lang.NullPointerException
	at io.fabric8.kubernetes.client.mock.SecretCrudTest.testCrud(SecretCrudTest.java:78)


Results :

Tests in error: 
  SecretCrudTest.testCrud:78 » NullPointer

Ideally Mock server should support such simple update operations.

@icereed
Copy link

icereed commented Dec 22, 2017

Experienced the very same with createOrReplace()

@icereed
Copy link

icereed commented Dec 22, 2017

This makes CRUD mode almost unusable.

Exception is thrown, when the mockresponse is null:

      // class MockWebServer.java
      /**
       * Reads a request and writes its response. Returns true if further calls should be attempted
       * on the socket.
       */
      private boolean processOneRequest(Socket socket, BufferedSource source, BufferedSink sink)
          throws IOException, InterruptedException {
        RecordedRequest request = readRequest(socket, source, sink, sequenceNumber);
        if (request == null) return false;

        requestCount.incrementAndGet();
        requestQueue.add(request);

        MockResponse response = dispatcher.dispatch(request);
        if (response.getSocketPolicy() == DISCONNECT_AFTER_REQUEST) { // <-- Thrown here
          socket.close();
          return false;
        }

@piyush-garg
Copy link
Contributor

@rohanKanojia Are you still facing the issue ?

@piyush-garg piyush-garg added this to FKC Backlog in Project FKC Feb 26, 2018
@piyush-garg piyush-garg added this to the Sprint 147 H milestone Mar 28, 2018
@piyush-garg piyush-garg moved this from FKC Backlog to Sprint Backlog in Project FKC Mar 28, 2018
@rohanKanojia rohanKanojia self-assigned this Mar 28, 2018
@sthaha sthaha added this to Backlog in Build Team Apr 3, 2018
@piyush-garg piyush-garg moved this from Backlog to Sprint-147 Progress in Build Team Apr 3, 2018
@piyush-garg piyush-garg moved this from Sprint-147 Progress to Backlog in Build Team Apr 3, 2018
@piyush-garg
Copy link
Contributor

Please try editing something else in the resource like, change some data value or something else. Also please try to use .patch() if that works.

As far as I know, apiVersion, Kind and Name can't be changed, maybe I am wrong. If that's true, then I did not get what you are trying to achieve.

@rohanKanojia
Copy link
Member Author

ah, sorry my bad. I didn't realize that it's not possible to edit the name of a resource. You're right.

@rohanKanojia rohanKanojia moved this from Backlog to Sprint - 147 - Done in Build Team Apr 19, 2018
@sthaha sthaha moved this from Sprint - 147 - Done to Done - Archive in Build Team May 30, 2018
@rohanKanojia rohanKanojia moved this from Sprint Backlog to Done in Project FKC Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Build Team
  
Done - Archive
Project FKC
  
Done
Development

No branches or pull requests

3 participants