-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Feature/extensions] Added unit test for createComponent workflow #3750
Conversation
Gradle Check (Jenkins) Run Completed with:
|
@peterzhuamazon bot commented before the gradle check is still running. Any idea here? |
Gradle Check (Jenkins) Run Completed with:
|
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 |
to
|
server/src/test/java/org/opensearch/extensions/ExtensionsOrchestratorTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/opensearch/extensions/ExtensionsOrchestratorTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/opensearch/extensions/ExtensionsOrchestratorTests.java
Outdated
Show resolved
Hide resolved
false, | ||
ExtensionRequest::new, | ||
(request, channel, task) -> { | ||
channel.sendResponse(new ClusterStateResponse(clusterName, null, false)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Signed-off-by: Owais Kazi <[email protected]>
Signed-off-by: Owais Kazi <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
ClusterName clusterName = new ClusterName("cluster-1"); | ||
ClusterStateResponse clusterStateResponse = new ClusterStateResponse(clusterName, null, false); | ||
assertEquals(clusterStateResponse.getClusterName(), clusterName); |
There was a problem hiding this comment.
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
inClusterStateResponseTest
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.
There was a problem hiding this comment.
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.
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Owais Kazi <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
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); |
There was a problem hiding this comment.
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.
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Owais Kazi <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
There was a problem hiding this 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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit
registerRequestHandler(); | |
registerRequestHandlers(); |
There was a problem hiding this comment.
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 :)
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
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.