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

[Feature/extensions] Added unit test for createComponent workflow #3750

Merged

Conversation

owaiskazi19
Copy link
Member

@owaiskazi19 owaiskazi19 commented Jun 30, 2022

Signed-off-by: Owais Kazi [email protected]

Description

Added Unit tests for registerHandler of ClusterState, ClusterSettings and LocalNode

Issues Resolved

Part of opensearch-project/opensearch-sdk-java#25

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@owaiskazi19 owaiskazi19 requested review from a team and reta as code owners June 30, 2022 18:52
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@owaiskazi19
Copy link
Member Author

Gradle Check (Jenkins) Run Completed with:

@peterzhuamazon bot commented before the gradle check is still running. Any idea here?

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@peterzhuamazon
Copy link
Member

peterzhuamazon commented Jun 30, 2022

Gradle Check (Jenkins) Run Completed with:

@peterzhuamazon bot commented before the gradle check is still running. Any idea here?

Hi Owais, you force pushed the branch so it takes both

@owaiskazi19 owaiskazi19 force-pushed the unit-tests branch from 3f6b8b8 to 34b9d0e 1 hour ago

image

@owaiskazi19
Copy link
Member Author

owaiskazi19 commented Jun 30, 2022

@peterzhuamazon

  1. can we add the console url here instead of the run for the Github bot
https://build.ci.opensearch.org/job/gradle-check/106/

to

https://build.ci.opensearch.org/job/gradle-check/106/console
  1. and change name from URL to LOGS

@saratvemulapalli saratvemulapalli changed the title Added unit test for createComponent workflow [Feature/extensions] Added unit test for createComponent workflow Jul 5, 2022
false,
ExtensionRequest::new,
(request, channel, task) -> {
channel.sendResponse(new ClusterStateResponse(clusterName, null, false));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we creating a new ClusterStateResponse here?
Ideally we should be able to test the response coming from extensionsOrchestrator.handleExtensionRequest(request)

Or Am I missing something here?

Copy link
Member Author

@owaiskazi19 owaiskazi19 Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another test here to test the response.
This test focusses on mocking registerRequestHandler. Let me know if you have other thoughts.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2022

Gradle Check (Jenkins) Run Completed with:

Comment on lines 349 to 351
ClusterName clusterName = new ClusterName("cluster-1");
ClusterStateResponse clusterStateResponse = new ClusterStateResponse(clusterName, null, false);
assertEquals(clusterStateResponse.getClusterName(), clusterName);
Copy link
Member

@saratvemulapalli saratvemulapalli Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing the ClusterStateResponse which is good, but its not testing the handler response.

Lets write unit tests for:

  • handleExtensionRequest pass in a request and verify the response params it sends back.
  • Test all responses, eg ClusterStateResponse in ClusterStateResponseTest file.
  • How can we verify if ExtensionsOrchestrator is registering all the handlers we expect?

Unit tests are usually for that specific class. Lets write new files for every different class we'd want to test.

Copy link
Member Author

@owaiskazi19 owaiskazi19 Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Done. Mocked the class type to verify the response is correct
  • We already have ClusterStateResponseTest file present in OpenSearch. Rest of the responses are handled when verifying the class type of return object of handleExtensionRequest test.
  • Can you please elaborate more on this? From my understanding I have added a test to verify if a different RequestType is passed.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2022

Gradle Check (Jenkins) Run Completed with:

  • RESULT: null ❌
  • URL: null
  • CommitID: 4cd35d0a51ae862dc09e90e208e53c6f2424a6bb

@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2022

Gradle Check (Jenkins) Run Completed with:

assertEquals(extensionsOrchestrator.handleExtensionRequest(localNodeRequest).getClass(), LocalNodeResponse.class);

ExtensionRequest nullRequest = new ExtensionRequest(ExtensionsOrchestrator.RequestType.GET_SETTINGS);
assertEquals(extensionsOrchestrator.handleExtensionRequest(nullRequest), null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not return null. Its going to make the system indeterministic when the caller doesnt handle it cleanly.
Lets throw an exception and make sure this test expects that exception.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2022

Gradle Check (Jenkins) Run Completed with:

Copy link
Member

@saratvemulapalli saratvemulapalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @owaiskazi19 for these changes!!

@@ -107,10 +107,14 @@ public ExtensionsOrchestrator(Settings settings, Path extensionsPath) throws IOE

public void setTransportService(TransportService transportService) {
this.transportService = transportService;
registerRequestHandler();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit

Suggested change
registerRequestHandler();
registerRequestHandlers();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will cover it in the next PR :)

@owaiskazi19 owaiskazi19 merged commit acd7db1 into opensearch-project:feature/extensions Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants