You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "djcoleman (via GitHub)" <gi...@apache.org> on 2023/03/16 09:37:29 UTC

[GitHub] [camel-quarkus] djcoleman opened a new pull request, #4663: camel-quarkus-management: Added tests for managed beans

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

   Fixes #4661
   
   - Added MBeans tests for the built-in types (components, endpoints, services etc)
   - Added MBeans test for custom bean
   - Updated docs.
   
   [x] 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.
   [x] 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 #.
   [x] 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.
   [x] 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.
   [x] Please run mvn process-resources -Pformat (and amend the changes if necessary) before sending the pull request.
   [x] 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] djcoleman commented on a diff in pull request #4663: camel-quarkus-management: Added tests for managed beans

Posted by "djcoleman (via GitHub)" <gi...@apache.org>.
djcoleman commented on code in PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663#discussion_r1138394936


##########
integration-tests-jvm/management/src/test/java/org/apache/camel/quarkus/component/management/it/ManagementTest.java:
##########
@@ -24,23 +24,69 @@
 import javax.management.ObjectName;
 
 import io.quarkus.test.junit.QuarkusTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @QuarkusTest
 class ManagementTest {
 
+    private MBeanServer server;
+
+    @Inject
+    ProducerTemplate template;
+
+    @Inject
+    CamelContext camelContext;
+
+    @BeforeEach
+    public void setUp() {
+        server = ManagementFactory.getPlatformMBeanServer();
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = { "components", "consumers", "context", "dataformats", "endpoints", "processors", "routes",
+            "services" })
+    public void testManagementObjects(String type) throws Exception {
+        // Look up an object instance by type
+        ObjectName objectName = new ObjectName("org.apache.camel:type=" + type + ",*");
+        Set<ObjectInstance> mbeans = server.queryMBeans(objectName, null);
+        assertTrue(mbeans.size() > 0);
+
+        // The CamelId attribute is common to all managed Camel objects,
+        // and should match the name of the CamelContext.
+        ObjectInstance mbean = mbeans.iterator().next();
+        String camelId = (String) server.getAttribute(mbean.getObjectName(), "CamelId");
+        assertEquals(camelContext.getName(), camelId);
+    }
+
     @Test
-    public void testCamelManagement() throws Exception {
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
-        ObjectName objectName = new ObjectName("org.apache.camel:type=context,*");
+    public void testManagedBean() throws Exception {
+        ObjectName objectName = new ObjectName("org.apache.camel:type=processors,name=\"counter\",*");
         Set<ObjectInstance> mbeans = server.queryMBeans(objectName, null);
         assertEquals(1, mbeans.size());
-
         ObjectInstance instance = mbeans.iterator().next();
-        String routeXML = (String) server.invoke(instance.getObjectName(), "dumpRoutesAsXml", new Object[] {}, new String[] {});

Review Comment:
   Sure, I can add that check back in.



-- 
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 pull request #4663: camel-quarkus-management: Added tests for managed beans

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663#issuecomment-1473387604

   > Please can someone merge this as I don't have permission. Thanks.
   
   I left one final nitpick comment. We should be good to merge after fixing that up.


-- 
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] djcoleman commented on pull request #4663: camel-quarkus-management: Added tests for managed beans

Posted by "djcoleman (via GitHub)" <gi...@apache.org>.
djcoleman commented on PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663#issuecomment-1473377042

   Please can someone merge this as I don't have permission. 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] jamesnetherton merged pull request #4663: camel-quarkus-management: Added tests for managed beans

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton merged PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663


-- 
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] djcoleman commented on a diff in pull request #4663: camel-quarkus-management: Added tests for managed beans

Posted by "djcoleman (via GitHub)" <gi...@apache.org>.
djcoleman commented on code in PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663#discussion_r1139919189


##########
integration-tests-jvm/management/src/test/java/org/apache/camel/quarkus/component/management/it/ManagementTest.java:
##########
@@ -24,23 +24,69 @@
 import javax.management.ObjectName;
 
 import io.quarkus.test.junit.QuarkusTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @QuarkusTest
 class ManagementTest {
 
+    private MBeanServer server;
+
+    @Inject
+    ProducerTemplate template;
+
+    @Inject
+    CamelContext camelContext;
+
+    @BeforeEach
+    public void setUp() {
+        server = ManagementFactory.getPlatformMBeanServer();
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = { "components", "consumers", "context", "dataformats", "endpoints", "processors", "routes",
+            "services" })
+    public void testManagementObjects(String type) throws Exception {
+        // Look up an object instance by type
+        ObjectName objectName = new ObjectName("org.apache.camel:type=" + type + ",*");
+        Set<ObjectInstance> mbeans = server.queryMBeans(objectName, null);
+        assertTrue(mbeans.size() > 0);
+
+        // The CamelId attribute is common to all managed Camel objects,
+        // and should match the name of the CamelContext.
+        ObjectInstance mbean = mbeans.iterator().next();
+        String camelId = (String) server.getAttribute(mbean.getObjectName(), "CamelId");
+        assertEquals(camelContext.getName(), camelId);
+    }
+
     @Test
-    public void testCamelManagement() throws Exception {
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
-        ObjectName objectName = new ObjectName("org.apache.camel:type=context,*");
+    public void testManagedBean() throws Exception {
+        ObjectName objectName = new ObjectName("org.apache.camel:type=processors,name=\"counter\",*");
         Set<ObjectInstance> mbeans = server.queryMBeans(objectName, null);
         assertEquals(1, mbeans.size());
-
         ObjectInstance instance = mbeans.iterator().next();
-        String routeXML = (String) server.invoke(instance.getObjectName(), "dumpRoutesAsXml", new Object[] {}, new String[] {});

Review Comment:
   I added that test back in.



-- 
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 #4663: camel-quarkus-management: Added tests for managed beans

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on code in PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663#discussion_r1139924170


##########
docs/modules/ROOT/pages/reference/extensions/management.adoc:
##########
@@ -33,6 +33,20 @@ ifeval::[{doc-show-user-guide-link} == true]
 Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
 endif::[]
 
+[id="extensions-management-usage"]
+== Usage
+For information on using Managed Beans in Camel, consult the https://camel.apache.org/manual/jmx.html[JMX section of the Camel Manual].

Review Comment:
   Please replace this with an `xref` link. You can find examples in some of the other extension docs. Just grep for `xref:manual`.



-- 
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] djcoleman commented on a diff in pull request #4663: camel-quarkus-management: Added tests for managed beans

Posted by "djcoleman (via GitHub)" <gi...@apache.org>.
djcoleman commented on code in PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663#discussion_r1139989156


##########
docs/modules/ROOT/pages/reference/extensions/management.adoc:
##########
@@ -33,6 +33,20 @@ ifeval::[{doc-show-user-guide-link} == true]
 Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
 endif::[]
 
+[id="extensions-management-usage"]
+== Usage
+For information on using Managed Beans in Camel, consult the https://camel.apache.org/manual/jmx.html[JMX section of the Camel Manual].

Review Comment:
   Done. I think I got the syntax right...



-- 
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 #4663: camel-quarkus-management: Added tests for managed beans

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on code in PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663#discussion_r1138380738


##########
integration-tests-jvm/management/src/test/java/org/apache/camel/quarkus/component/management/it/ManagementTest.java:
##########
@@ -24,23 +24,69 @@
 import javax.management.ObjectName;
 
 import io.quarkus.test.junit.QuarkusTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @QuarkusTest
 class ManagementTest {
 
+    private MBeanServer server;
+
+    @Inject
+    ProducerTemplate template;
+
+    @Inject
+    CamelContext camelContext;
+
+    @BeforeEach
+    public void setUp() {
+        server = ManagementFactory.getPlatformMBeanServer();
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = { "components", "consumers", "context", "dataformats", "endpoints", "processors", "routes",
+            "services" })
+    public void testManagementObjects(String type) throws Exception {
+        // Look up an object instance by type
+        ObjectName objectName = new ObjectName("org.apache.camel:type=" + type + ",*");
+        Set<ObjectInstance> mbeans = server.queryMBeans(objectName, null);
+        assertTrue(mbeans.size() > 0);
+
+        // The CamelId attribute is common to all managed Camel objects,
+        // and should match the name of the CamelContext.
+        ObjectInstance mbean = mbeans.iterator().next();
+        String camelId = (String) server.getAttribute(mbean.getObjectName(), "CamelId");
+        assertEquals(camelContext.getName(), camelId);
+    }
+
     @Test
-    public void testCamelManagement() throws Exception {
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
-        ObjectName objectName = new ObjectName("org.apache.camel:type=context,*");
+    public void testManagedBean() throws Exception {
+        ObjectName objectName = new ObjectName("org.apache.camel:type=processors,name=\"counter\",*");
         Set<ObjectInstance> mbeans = server.queryMBeans(objectName, null);
         assertEquals(1, mbeans.size());
-
         ObjectInstance instance = mbeans.iterator().next();
-        String routeXML = (String) server.invoke(instance.getObjectName(), "dumpRoutesAsXml", new Object[] {}, new String[] {});

Review Comment:
   I think we should still verify that `dumpRoutesAsXml` works ok as it's used by external tools like HawtIO etc.



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