You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/04/25 14:56:53 UTC

[GitHub] [camel-quarkus] jamesnetherton opened a new pull request, #3747: Fix MockEndpoint usage in Infinispan tests

jamesnetherton opened a new pull request, #3747:
URL: https://github.com/apache/camel-quarkus/pull/3747

   Noticed some of the Infinispan mock endpoint assertions were having no effect, so this change fixes that.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton commented on a diff in pull request #3747: Fix MockEndpoint usage in Infinispan tests

Posted by GitBox <gi...@apache.org>.
jamesnetherton commented on code in PR #3747:
URL: https://github.com/apache/camel-quarkus/pull/3747#discussion_r858317188


##########
integration-tests/infinispan/src/main/java/org/apache/camel/quarkus/component/infinispan/InfinispanResources.java:
##########
@@ -198,16 +232,24 @@ public void putAllAsync(@QueryParam("component") String component)
     }
 
     @Path("/putIdempotent")
-    @POST
-    @Consumes(MediaType.TEXT_PLAIN)
-    public void putIdempotent(
-            @QueryParam("component") String component,
-            @QueryParam("messageId") String messageId,
-            String content) {
+    @GET
+    public void putIdempotent(@QueryParam("component") String component) throws InterruptedException {
+        MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:resultIdempotent", MockEndpoint.class);
+        mockEndpoint.expectedMessageCount(1);
+
+        String messageId = UUID.randomUUID().toString();
         String uri = component.equals("infinispan") ? "direct:camelIdempotent" : "direct:quarkusIdempotent";
-        Map<String, Object> headers = getCommonHeaders(component);
-        headers.put("MessageId", messageId);
-        template.sendBodyAndHeaders(uri, content, headers);
+        try {
+            IntStream.of(1, 10).forEach(value -> {
+                Map<String, Object> headers = getCommonHeaders(component);
+                headers.put("MessageId", messageId);
+                template.sendBodyAndHeaders(uri, "Message " + value, headers);
+            });
+
+            mockEndpoint.assertIsSatisfied(5000);
+        } finally {
+            mockEndpoint.reset();

Review Comment:
   >  I'm just wondering whether it would generally be better practice to have single usage mock endpoint where possible. In this PR, maybe we could have single use endpoint by integrating component name in the mock uri
   
   Would that maybe not be a good idea at the moment given that this is not fixed till Camel 3.17?
   
   https://issues.apache.org/jira/browse/CAMEL-17948
   
   Just so I understand the problem, is it that `reset` can still be in progress while some other test is trying to do assertions on the mock endpoint? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #3747: Fix MockEndpoint usage in Infinispan tests

Posted by GitBox <gi...@apache.org>.
aldettinger commented on code in PR #3747:
URL: https://github.com/apache/camel-quarkus/pull/3747#discussion_r857850055


##########
integration-tests/infinispan/src/main/java/org/apache/camel/quarkus/component/infinispan/InfinispanResources.java:
##########
@@ -198,16 +232,24 @@ public void putAllAsync(@QueryParam("component") String component)
     }
 
     @Path("/putIdempotent")
-    @POST
-    @Consumes(MediaType.TEXT_PLAIN)
-    public void putIdempotent(
-            @QueryParam("component") String component,
-            @QueryParam("messageId") String messageId,
-            String content) {
+    @GET
+    public void putIdempotent(@QueryParam("component") String component) throws InterruptedException {
+        MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:resultIdempotent", MockEndpoint.class);
+        mockEndpoint.expectedMessageCount(1);
+
+        String messageId = UUID.randomUUID().toString();
         String uri = component.equals("infinispan") ? "direct:camelIdempotent" : "direct:quarkusIdempotent";
-        Map<String, Object> headers = getCommonHeaders(component);
-        headers.put("MessageId", messageId);
-        template.sendBodyAndHeaders(uri, content, headers);
+        try {
+            IntStream.of(1, 10).forEach(value -> {
+                Map<String, Object> headers = getCommonHeaders(component);
+                headers.put("MessageId", messageId);
+                template.sendBodyAndHeaders(uri, "Message " + value, headers);
+            });
+
+            mockEndpoint.assertIsSatisfied(5000);
+        } finally {
+            mockEndpoint.reset();

Review Comment:
   Manually calling `reset()` on MockEndpoint generated a race condition in another test. Due to [this](https://github.com/apache/camel/blob/main/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java#L319). I don't think it applies to the case at hand. I'm just wondering whether it would generally be better practice to have single usage mock endpoint where possible. In this PR, maybe we could have single use endpoint by integrating component name in the mock uri ?
   
   It's not a blocker. Just an idea to share.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #3747: Fix MockEndpoint usage in Infinispan tests

Posted by GitBox <gi...@apache.org>.
aldettinger commented on code in PR #3747:
URL: https://github.com/apache/camel-quarkus/pull/3747#discussion_r860585491


##########
integration-tests/infinispan/src/main/java/org/apache/camel/quarkus/component/infinispan/InfinispanResources.java:
##########
@@ -198,16 +232,24 @@ public void putAllAsync(@QueryParam("component") String component)
     }
 
     @Path("/putIdempotent")
-    @POST
-    @Consumes(MediaType.TEXT_PLAIN)
-    public void putIdempotent(
-            @QueryParam("component") String component,
-            @QueryParam("messageId") String messageId,
-            String content) {
+    @GET
+    public void putIdempotent(@QueryParam("component") String component) throws InterruptedException {
+        MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:resultIdempotent", MockEndpoint.class);
+        mockEndpoint.expectedMessageCount(1);
+
+        String messageId = UUID.randomUUID().toString();
         String uri = component.equals("infinispan") ? "direct:camelIdempotent" : "direct:quarkusIdempotent";
-        Map<String, Object> headers = getCommonHeaders(component);
-        headers.put("MessageId", messageId);
-        template.sendBodyAndHeaders(uri, content, headers);
+        try {
+            IntStream.of(1, 10).forEach(value -> {
+                Map<String, Object> headers = getCommonHeaders(component);
+                headers.put("MessageId", messageId);
+                template.sendBodyAndHeaders(uri, "Message " + value, headers);
+            });
+
+            mockEndpoint.assertIsSatisfied(5000);
+        } finally {
+            mockEndpoint.reset();

Review Comment:
   As far as I understand, I was talking about another situation than CAMEL-17948.
   As far as I remember, the situation was that `reset` was called before or maybe during a call to getReceivedExchanges().
   
   Anyway, the implemented solution seems good here. Let's just recall that invoking `mock.reset()` should be done with care or not at all :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton merged pull request #3747: Fix MockEndpoint usage in Infinispan tests

Posted by GitBox <gi...@apache.org>.
jamesnetherton merged PR #3747:
URL: https://github.com/apache/camel-quarkus/pull/3747


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton commented on a diff in pull request #3747: Fix MockEndpoint usage in Infinispan tests

Posted by GitBox <gi...@apache.org>.
jamesnetherton commented on code in PR #3747:
URL: https://github.com/apache/camel-quarkus/pull/3747#discussion_r858532129


##########
integration-tests/infinispan/src/main/java/org/apache/camel/quarkus/component/infinispan/InfinispanResources.java:
##########
@@ -198,16 +232,24 @@ public void putAllAsync(@QueryParam("component") String component)
     }
 
     @Path("/putIdempotent")
-    @POST
-    @Consumes(MediaType.TEXT_PLAIN)
-    public void putIdempotent(
-            @QueryParam("component") String component,
-            @QueryParam("messageId") String messageId,
-            String content) {
+    @GET
+    public void putIdempotent(@QueryParam("component") String component) throws InterruptedException {
+        MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:resultIdempotent", MockEndpoint.class);
+        mockEndpoint.expectedMessageCount(1);
+
+        String messageId = UUID.randomUUID().toString();
         String uri = component.equals("infinispan") ? "direct:camelIdempotent" : "direct:quarkusIdempotent";
-        Map<String, Object> headers = getCommonHeaders(component);
-        headers.put("MessageId", messageId);
-        template.sendBodyAndHeaders(uri, content, headers);
+        try {
+            IntStream.of(1, 10).forEach(value -> {
+                Map<String, Object> headers = getCommonHeaders(component);
+                headers.put("MessageId", messageId);
+                template.sendBodyAndHeaders(uri, "Message " + value, headers);
+            });
+
+            mockEndpoint.assertIsSatisfied(5000);
+        } finally {
+            mockEndpoint.reset();

Review Comment:
   I've tweaked things to `use single use endpoint by integrating component name`. There are some other extension tests like this that I'd like to modify. So makes sense to have a consistent approach.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on a diff in pull request #3747: Fix MockEndpoint usage in Infinispan tests

Posted by GitBox <gi...@apache.org>.
essobedo commented on code in PR #3747:
URL: https://github.com/apache/camel-quarkus/pull/3747#discussion_r860622997


##########
integration-tests/infinispan/src/main/java/org/apache/camel/quarkus/component/infinispan/InfinispanResources.java:
##########
@@ -198,16 +232,24 @@ public void putAllAsync(@QueryParam("component") String component)
     }
 
     @Path("/putIdempotent")
-    @POST
-    @Consumes(MediaType.TEXT_PLAIN)
-    public void putIdempotent(
-            @QueryParam("component") String component,
-            @QueryParam("messageId") String messageId,
-            String content) {
+    @GET
+    public void putIdempotent(@QueryParam("component") String component) throws InterruptedException {
+        MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:resultIdempotent", MockEndpoint.class);
+        mockEndpoint.expectedMessageCount(1);
+
+        String messageId = UUID.randomUUID().toString();
         String uri = component.equals("infinispan") ? "direct:camelIdempotent" : "direct:quarkusIdempotent";
-        Map<String, Object> headers = getCommonHeaders(component);
-        headers.put("MessageId", messageId);
-        template.sendBodyAndHeaders(uri, content, headers);
+        try {
+            IntStream.of(1, 10).forEach(value -> {
+                Map<String, Object> headers = getCommonHeaders(component);
+                headers.put("MessageId", messageId);
+                template.sendBodyAndHeaders(uri, "Message " + value, headers);
+            });
+
+            mockEndpoint.assertIsSatisfied(5000);
+        } finally {
+            mockEndpoint.reset();

Review Comment:
   Hi, if [CAMEL-17948](https://issues.apache.org/jira/browse/CAMEL-17948) is not clear enough for you, let me know, I will try to clarify it a little bit more



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org