-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: add methods to verify service invocation #121
base: main
Are you sure you want to change the base?
feat: add methods to verify service invocation #121
Conversation
Welcome to the Microcks community! 💖 Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly. Hope you have a great time there! |
fb98071
to
043602c
Compare
Hello If the unit test code calls the Microcks Metrics REST API too quickly after the desired service have been invoked, randomly (about 1 time out of 2) the API responds as if the service wasn't invoked. @lbroudoux and Microcks community : have you ever heard of this kind of issue with Microcks Metrics REST API ? You will find this code, calling |
Hi @pierrechristinimsa Regarding the race condition you're facing: this is expected as the processing of invocation metrics (association to correct day/time and increment of the counter in the database) is done in an asynchronous way vs. the mock controller. I think that adding a timer cannot be avoided to fix the race condition... I just wonder if it wouldn't be better to put this directly in the library method to avoid the consumer worrying about this... 🤔 |
043602c
to
1fd77d0
Compare
Thank you for your reactive answer and explanations @lbroudoux. I think that's what I've done : the sleep is hard-coded inside the library method, so the consumer shouldn't be aware of this. I would have liked to make this sleep time possibly configurable, but as I'm not used to do this, I didn't manage to do this simply. By the way, I remove the "Draft" state of this PR and I remain available to make some changes if needed. |
1fd77d0
to
235e188
Compare
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.*; |
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.
Could you please restore the explicit import list?
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
import java.util.List; | ||
import java.util.Set; | ||
import java.text.SimpleDateFormat; | ||
import java.util.*; |
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.
Could you please restore the explicit imports list?
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
String encodedServiceName = UrlEscapers.urlFragmentEscaper().escape(serviceName); | ||
String encodedServiceVersion = UrlEscapers.urlFragmentEscaper().escape(serviceVersion); |
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.
I'm not sure this is needed as most of the HTTP client libraries or utilities are doing the encoding of the URL. Could you please check this one? If actually needed, couldn't we use instead the standard URLEncoder.encode()
to avoid depending on third-party libs?
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.
I encountered space character encoding issue.
Using URLEncoder.encode()
, with UTF-8
, it is changed in "%20".
Whereas the Metrics REST API expects the space character to be changed to "+".
Maybe there is another way to encode the service name so as it is correctly sent to the Metrics REST API ?
} | ||
|
||
try { | ||
Thread.sleep(100); // to avoid race condition issue when requesting Microcks Metrics REST API |
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.
👍 See https://github.com/microcks/microcks/blob/master/webapp/src/main/java/io/github/microcks/web/MockControllerCommons.java#L337 => the processing of invocation event metrics is anychronous.
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.
Thank you for the link, interesting to see notably the event management.
/* | ||
* Microcks API v1.10 | ||
* API offered by Microcks, the Kubernetes native tool for API and microservices mocking and testing (microcks.io) | ||
* | ||
* The version of the OpenAPI document: 1.10.0 | ||
* Contact: [email protected] | ||
* | ||
* NOTE: This class comes from microcks-java-client project : https://github.com/microcks/microcks-java-client | ||
*/ |
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.
Could you place here the standard header like in https://github.com/microcks/microcks-testcontainers-java/blob/main/src/main/java/io/github/microcks/testcontainers/MicrocksContainer.java#L1-L15 ?
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
public boolean verify(String serviceName, String serviceVersion) { | ||
return this.doVerify(serviceName, serviceVersion, 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.
Could you add static
version of these methods with first parameters being the microcksContainerHttpEndpoint
like in https://github.com/microcks/microcks-testcontainers-java/blob/main/src/main/java/io/github/microcks/testcontainers/MicrocksContainer.java#L303 ? This help making these methods available to the microcks-quarkus
DevService where we don't have access to the container object itself but just to its exposed URL. Thanks!
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
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.
Hey @pierrechristinimsa!
This looks very good - I just suggested a few changes to stick to coding style or governance issues. Nice job!
Signed-off-by: Pierre CHRISTIN <[email protected]>
235e188
to
6ab5d12
Compare
Description
Thread.sleep(...)
to avoid race condition issue with the Metrics REST API.It still lacks of more detailed results.
For instance, for SOAP Mock: it is still impossible to know exactly the count of invocations for a given Operation of the mocked Service. But that doesn't seem to be managed by the microcks server itself, or at least not exposed by the Metrics REST API.
I would also have liked to make the sleep time possibly configurable, but didn't manage to do this simply.
Please feel free to bring feedbacks, thanks by advance.
Related issue(s)
See also #91