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/07 14:45:35 UTC

[GitHub] [camel-quarkus] zhfeng opened a new pull request, #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

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

   <!-- Uncomment and fill this section if your PR is not trivial
   [ ] An issue should be filed for the change unless this is a trivial change (fixing a typo or similar). One issue should ideally be fixed by not more than one commit and the other way round, each commit should fix just one issue, without pulling in other changes.
   [ ] Each commit in the pull request should have a meaningful and properly spelled subject line and body. Copying the title of the associated issue is typically enough. Please include the issue number in the commit message prefixed by #.
   [ ] The pull request description should explain what the pull request does, how, and why. If the info is available in the associated issue or some other external document, a link is enough.
   [ ] Phrases like Fix #<issueNumber> or Fixes #<issueNumber> will auto-close the named issue upon merging the pull request. Using them is typically a good idea.
   [ ] Please run mvn process-resources -Pformat (and amend the changes if necessary) before sending the pull request.
   [ ] Contributor guide is your good friend: https://camel.apache.org/camel-quarkus/latest/contributor-guide.html
   -->


-- 
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] zhfeng merged pull request #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

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


-- 
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 #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

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


##########
integration-tests/paho-mqtt5/src/main/java/org/apache/camel/quarkus/component/paho/mqtt5/it/PahoMqtt5Resource.java:
##########
@@ -60,12 +86,94 @@ public Response producePahoMessage(
             @PathParam("protocol") String protocol,
             @PathParam("queueName") String queueName,
             String message) throws Exception {
+        if ("ssl".equals(protocol)) {
+            setKeyStore(keystore, password);
+        }
         producerTemplate.sendBody("paho-mqtt5:" + queueName + "?retained=true&brokerUrl=" + brokerUrl(protocol), message);
+        if ("ssl".equals(protocol)) {
+            removeKeyStore(keystore);
+        }
+        return Response.created(new URI("https://camel.apache.org/")).build();
+    }
+
+    @Path("/override/{queueName}")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    public Response overrideQueueName(
+            @PathParam("queueName") String queueName,
+            String message) throws Exception {
+        producerTemplate.sendBodyAndHeader("paho-mqtt5:test?retained=true&brokerUrl=" + brokerUrl("tcp"), message,
+                PahoMqtt5Constants.CAMEL_PAHO_OVERRIDE_TOPIC, queueName);
+        return Response.created(new URI("https://camel.apache.org/")).build();
+    }
+
+    @Path("/readThenWriteWithFilePersistenceShouldSucceed")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String readThenWriteWithFilePersistenceShouldSucceed(@QueryParam("message") String message) throws Exception {
+        producerTemplate.sendBody(
+                "paho-mqtt5:withFilePersistence?retained=true&persistence=FILE&brokerUrl="
+                        + brokerUrl("tcp"),
+                message);
+        return consumerTemplate.receiveBody(
+                "paho-mqtt5:withFilePersistence?persistence=FILE&brokerUrl=" + brokerUrl("tcp"),
+                5000,
+                String.class);
+    }
+
+    @Path("/routeStatus/{id}")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String routeStatus(@PathParam("id") String routeId,
+            @QueryParam("waitForContainerStarted") @DefaultValue("false") boolean wait) throws Exception {
+        RouteController routeController = context.getRouteController();
+        if (wait) {
+            counter.await(30, TimeUnit.SECONDS);
+        }
+        return routeController.getRouteStatus(routeId).name();
+    }
+
+    @Path("/mock")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public String mock(String message) throws Exception {
+        MockEndpoint endpoint = context.getEndpoint("mock:test", MockEndpoint.class);
+        endpoint.expectedBodiesReceived(message);
+
+        endpoint.assertIsSatisfied();
+        return "OK";
+    }
+
+    @Path("/send")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response send(String message) throws Exception {
+        producerTemplate.sendBody("direct:test", message);
         return Response.created(new URI("https://camel.apache.org/")).build();
     }
 
     private String brokerUrl(String protocol) {
         return ConfigProvider.getConfig().getValue("paho5.broker." + protocol + ".url", String.class);
     }
 
+    private void setKeyStore(String keystore, String password) {
+        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(keystore);
+
+        try {
+            Files.copy(in, Paths.get(keystore));
+        } catch (Exception e) {
+        }
+
+        System.setProperty("javax.net.ssl.keyStore", keystore);
+        System.setProperty("javax.net.ssl.keyStorePassword", password);
+        System.setProperty("javax.net.ssl.trustStore", keystore);
+        System.setProperty("javax.net.ssl.trustStorePassword", password);
+    }
+
+    private void removeKeyStore(String keystore) {
+        try {
+            Files.delete(Paths.get(keystore));

Review Comment:
   Should we unset the SSL system properties here?



-- 
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] zhfeng commented on a diff in pull request #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

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


##########
integration-tests/paho-mqtt5/src/main/java/org/apache/camel/quarkus/component/paho/mqtt5/it/PahoMqtt5Resource.java:
##########
@@ -60,12 +86,94 @@ public Response producePahoMessage(
             @PathParam("protocol") String protocol,
             @PathParam("queueName") String queueName,
             String message) throws Exception {
+        if ("ssl".equals(protocol)) {
+            setKeyStore(keystore, password);
+        }
         producerTemplate.sendBody("paho-mqtt5:" + queueName + "?retained=true&brokerUrl=" + brokerUrl(protocol), message);
+        if ("ssl".equals(protocol)) {
+            removeKeyStore(keystore);
+        }
+        return Response.created(new URI("https://camel.apache.org/")).build();
+    }
+
+    @Path("/override/{queueName}")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    public Response overrideQueueName(
+            @PathParam("queueName") String queueName,
+            String message) throws Exception {
+        producerTemplate.sendBodyAndHeader("paho-mqtt5:test?retained=true&brokerUrl=" + brokerUrl("tcp"), message,
+                PahoMqtt5Constants.CAMEL_PAHO_OVERRIDE_TOPIC, queueName);
+        return Response.created(new URI("https://camel.apache.org/")).build();
+    }
+
+    @Path("/readThenWriteWithFilePersistenceShouldSucceed")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String readThenWriteWithFilePersistenceShouldSucceed(@QueryParam("message") String message) throws Exception {
+        producerTemplate.sendBody(
+                "paho-mqtt5:withFilePersistence?retained=true&persistence=FILE&brokerUrl="
+                        + brokerUrl("tcp"),
+                message);
+        return consumerTemplate.receiveBody(
+                "paho-mqtt5:withFilePersistence?persistence=FILE&brokerUrl=" + brokerUrl("tcp"),
+                5000,
+                String.class);
+    }
+
+    @Path("/routeStatus/{id}")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String routeStatus(@PathParam("id") String routeId,
+            @QueryParam("waitForContainerStarted") @DefaultValue("false") boolean wait) throws Exception {
+        RouteController routeController = context.getRouteController();
+        if (wait) {
+            counter.await(30, TimeUnit.SECONDS);
+        }
+        return routeController.getRouteStatus(routeId).name();
+    }
+
+    @Path("/mock")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public String mock(String message) throws Exception {
+        MockEndpoint endpoint = context.getEndpoint("mock:test", MockEndpoint.class);
+        endpoint.expectedBodiesReceived(message);
+
+        endpoint.assertIsSatisfied();
+        return "OK";
+    }
+
+    @Path("/send")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response send(String message) throws Exception {
+        producerTemplate.sendBody("direct:test", message);
         return Response.created(new URI("https://camel.apache.org/")).build();
     }
 
     private String brokerUrl(String protocol) {
         return ConfigProvider.getConfig().getValue("paho5.broker." + protocol + ".url", String.class);
     }
 
+    private void setKeyStore(String keystore, String password) {
+        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(keystore);
+
+        try {
+            Files.copy(in, Paths.get(keystore));
+        } catch (Exception e) {
+        }
+
+        System.setProperty("javax.net.ssl.keyStore", keystore);
+        System.setProperty("javax.net.ssl.keyStorePassword", password);
+        System.setProperty("javax.net.ssl.trustStore", keystore);
+        System.setProperty("javax.net.ssl.trustStorePassword", password);
+    }
+
+    private void removeKeyStore(String keystore) {
+        try {
+            Files.delete(Paths.get(keystore));

Review Comment:
   good catch! I will unset these properties.



-- 
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 #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

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


##########
integration-tests/paho-mqtt5/src/test/java/org/apache/camel/quarkus/component/paho/mqtt5/it/PahoMqtt5TestResource.java:
##########
@@ -32,25 +36,76 @@
     private static final Logger LOGGER = LoggerFactory.getLogger(PahoMqtt5TestResource.class);
     private static final String IMAGE = "eclipse-mosquitto:1.6.12";
     private static final int TCP_PORT = 1883;
+    private static final int SSL_PORT = 8883;
+    private static final int WS_PORT = 9001;
+    private static final String MQTT_USERNAME = "quarkus";
+    private static final String MQTT_PASSWORD = "quarkus";
 
     private GenericContainer<?> container;
+    private boolean useFixedPort = false;
+    private boolean startContainer = true;
+
+    @Override
+    public void init(Map<String, String> initArgs) {
+        initArgs.forEach((name, value) -> {
+            if (name.equals("useFixedPort")) {
+                useFixedPort = Boolean.parseBoolean(value);
+            } else if (name.equals("startContainer")) {
+                startContainer = Boolean.parseBoolean(value);
+            }
+        });
+    }
+
+    @Override
+    public void inject(TestInjector testInjector) {
+        testInjector.injectIntoFields(container,
+                new TestInjector.AnnotatedAndMatchesType(InjectPahoContainer.class, GenericContainer.class));
+    }
 
     @Override
     public Map<String, String> start() {
         LOGGER.info(TestcontainersConfiguration.getInstance().toString());
 
         try {
-            container = new GenericContainer<>(IMAGE)
-                    .withExposedPorts(TCP_PORT)
-                    .withLogConsumer(new Slf4jLogConsumer(LOGGER))
+            Map<String, String> result = new HashMap<>();
+
+            if (useFixedPort) {

Review Comment:
   Could you please describe why we need to have use `useFixedPort` ? When should we use it ? And when not to use it please ?



-- 
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 #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

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


##########
integration-tests/paho-mqtt5/src/test/java/org/apache/camel/quarkus/component/paho/mqtt5/it/PahoMqtt5TestResource.java:
##########
@@ -32,25 +36,76 @@
     private static final Logger LOGGER = LoggerFactory.getLogger(PahoMqtt5TestResource.class);
     private static final String IMAGE = "eclipse-mosquitto:1.6.12";
     private static final int TCP_PORT = 1883;
+    private static final int SSL_PORT = 8883;
+    private static final int WS_PORT = 9001;
+    private static final String MQTT_USERNAME = "quarkus";
+    private static final String MQTT_PASSWORD = "quarkus";
 
     private GenericContainer<?> container;
+    private boolean useFixedPort = false;
+    private boolean startContainer = true;
+
+    @Override
+    public void init(Map<String, String> initArgs) {
+        initArgs.forEach((name, value) -> {
+            if (name.equals("useFixedPort")) {
+                useFixedPort = Boolean.parseBoolean(value);
+            } else if (name.equals("startContainer")) {
+                startContainer = Boolean.parseBoolean(value);
+            }
+        });
+    }
+
+    @Override
+    public void inject(TestInjector testInjector) {
+        testInjector.injectIntoFields(container,
+                new TestInjector.AnnotatedAndMatchesType(InjectPahoContainer.class, GenericContainer.class));
+    }
 
     @Override
     public Map<String, String> start() {
         LOGGER.info(TestcontainersConfiguration.getInstance().toString());
 
         try {
-            container = new GenericContainer<>(IMAGE)
-                    .withExposedPorts(TCP_PORT)
-                    .withLogConsumer(new Slf4jLogConsumer(LOGGER))
+            Map<String, String> result = new HashMap<>();
+
+            if (useFixedPort) {

Review Comment:
   Ok, So it's only for manual testing. And yes, I know this re-connection scenario is hard to setup :) Many thanks.



-- 
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] zhfeng commented on a diff in pull request #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

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


##########
integration-tests/paho-mqtt5/src/test/java/org/apache/camel/quarkus/component/paho/mqtt5/it/PahoMqtt5TestResource.java:
##########
@@ -32,25 +36,76 @@
     private static final Logger LOGGER = LoggerFactory.getLogger(PahoMqtt5TestResource.class);
     private static final String IMAGE = "eclipse-mosquitto:1.6.12";
     private static final int TCP_PORT = 1883;
+    private static final int SSL_PORT = 8883;
+    private static final int WS_PORT = 9001;
+    private static final String MQTT_USERNAME = "quarkus";
+    private static final String MQTT_PASSWORD = "quarkus";
 
     private GenericContainer<?> container;
+    private boolean useFixedPort = false;
+    private boolean startContainer = true;
+
+    @Override
+    public void init(Map<String, String> initArgs) {
+        initArgs.forEach((name, value) -> {
+            if (name.equals("useFixedPort")) {
+                useFixedPort = Boolean.parseBoolean(value);
+            } else if (name.equals("startContainer")) {
+                startContainer = Boolean.parseBoolean(value);
+            }
+        });
+    }
+
+    @Override
+    public void inject(TestInjector testInjector) {
+        testInjector.injectIntoFields(container,
+                new TestInjector.AnnotatedAndMatchesType(InjectPahoContainer.class, GenericContainer.class));
+    }
 
     @Override
     public Map<String, String> start() {
         LOGGER.info(TestcontainersConfiguration.getInstance().toString());
 
         try {
-            container = new GenericContainer<>(IMAGE)
-                    .withExposedPorts(TCP_PORT)
-                    .withLogConsumer(new Slf4jLogConsumer(LOGGER))
+            Map<String, String> result = new HashMap<>();
+
+            if (useFixedPort) {

Review Comment:
   We need to use ```useFixedPort``` in case of we want to start or stop the container manually during the testing, especailly for reconnecting test. With ```useFixedPort``` the expose port of the container will not be changed after it restarted, this is important for a reconnecting test. Is it clear ?



-- 
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 #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

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


##########
integration-tests/paho-mqtt5/src/main/java/org/apache/camel/quarkus/component/paho/mqtt5/it/PahoMqtt5Resource.java:
##########
@@ -60,12 +86,94 @@ public Response producePahoMessage(
             @PathParam("protocol") String protocol,
             @PathParam("queueName") String queueName,
             String message) throws Exception {
+        if ("ssl".equals(protocol)) {
+            setKeyStore(keystore, password);
+        }
         producerTemplate.sendBody("paho-mqtt5:" + queueName + "?retained=true&brokerUrl=" + brokerUrl(protocol), message);
+        if ("ssl".equals(protocol)) {
+            removeKeyStore(keystore);
+        }
+        return Response.created(new URI("https://camel.apache.org/")).build();
+    }
+
+    @Path("/override/{queueName}")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    public Response overrideQueueName(
+            @PathParam("queueName") String queueName,
+            String message) throws Exception {
+        producerTemplate.sendBodyAndHeader("paho-mqtt5:test?retained=true&brokerUrl=" + brokerUrl("tcp"), message,
+                PahoMqtt5Constants.CAMEL_PAHO_OVERRIDE_TOPIC, queueName);
+        return Response.created(new URI("https://camel.apache.org/")).build();
+    }
+
+    @Path("/readThenWriteWithFilePersistenceShouldSucceed")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String readThenWriteWithFilePersistenceShouldSucceed(@QueryParam("message") String message) throws Exception {
+        producerTemplate.sendBody(
+                "paho-mqtt5:withFilePersistence?retained=true&persistence=FILE&brokerUrl="
+                        + brokerUrl("tcp"),
+                message);
+        return consumerTemplate.receiveBody(
+                "paho-mqtt5:withFilePersistence?persistence=FILE&brokerUrl=" + brokerUrl("tcp"),
+                5000,
+                String.class);
+    }
+
+    @Path("/routeStatus/{id}")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String routeStatus(@PathParam("id") String routeId,
+            @QueryParam("waitForContainerStarted") @DefaultValue("false") boolean wait) throws Exception {
+        RouteController routeController = context.getRouteController();
+        if (wait) {
+            counter.await(30, TimeUnit.SECONDS);
+        }
+        return routeController.getRouteStatus(routeId).name();
+    }
+
+    @Path("/mock")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public String mock(String message) throws Exception {
+        MockEndpoint endpoint = context.getEndpoint("mock:test", MockEndpoint.class);
+        endpoint.expectedBodiesReceived(message);
+
+        endpoint.assertIsSatisfied();
+        return "OK";
+    }
+
+    @Path("/send")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response send(String message) throws Exception {
+        producerTemplate.sendBody("direct:test", message);
         return Response.created(new URI("https://camel.apache.org/")).build();
     }
 
     private String brokerUrl(String protocol) {
         return ConfigProvider.getConfig().getValue("paho5.broker." + protocol + ".url", String.class);
     }
 
+    private void setKeyStore(String keystore, String password) {
+        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(keystore);
+
+        try {
+            Files.copy(in, Paths.get(keystore));
+        } catch (Exception e) {
+        }
+
+        System.setProperty("javax.net.ssl.keyStore", keystore);
+        System.setProperty("javax.net.ssl.keyStorePassword", password);
+        System.setProperty("javax.net.ssl.trustStore", keystore);
+        System.setProperty("javax.net.ssl.trustStorePassword", password);
+    }
+
+    private void removeKeyStore(String keystore) {
+        try {
+            Files.delete(Paths.get(keystore));

Review Comment:
   Also, I guess we want this to always happen. E.g even if the call to the `ProducerTemplate` throws an exception.



-- 
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