You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2019/06/25 20:02:52 UTC

[activemq-artemis] branch master updated: ARTEMIS-2350 Fix ClassNotFoundException while invoking ActiveMQServerControlImpl::listConsumers

This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 665a698  ARTEMIS-2350 Fix ClassNotFoundException while invoking ActiveMQServerControlImpl::listConsumers
     new 824b732  This closes #2677
665a698 is described below

commit 665a69886e2f09778df1fb14c1f889e68ba71a40
Author: yang wei <wy...@gmail.com>
AuthorDate: Wed May 22 20:37:35 2019 +0800

    ARTEMIS-2350 Fix ClassNotFoundException while invoking ActiveMQServerControlImpl::listConsumers
---
 .../apache/activemq/artemis/api/core/JsonUtil.java |   5 +-
 tests/smoke-tests/pom.xml                          |  18 ++++
 .../tests/smoke/jmx2/JmxServerControlTest.java     | 107 +++++++++++++++++++++
 3 files changed, 127 insertions(+), 3 deletions(-)

diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
index eed944f..bd8b8df 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
@@ -16,7 +16,6 @@
  */
 package org.apache.activemq.artemis.api.core;
 
-import javax.json.Json;
 import javax.json.JsonArray;
 import javax.json.JsonArrayBuilder;
 import javax.json.JsonNumber;
@@ -275,11 +274,11 @@ public final class JsonUtil {
    }
 
    public static JsonArray readJsonArray(String jsonString) {
-      return Json.createReader(new StringReader(jsonString)).readArray();
+      return JsonLoader.createReader(new StringReader(jsonString)).readArray();
    }
 
    public static JsonObject readJsonObject(String jsonString) {
-      return Json.createReader(new StringReader(jsonString)).readObject();
+      return JsonLoader.createReader(new StringReader(jsonString)).readObject();
    }
 
    public static Map<String, String> readJsonProperties(String jsonString) {
diff --git a/tests/smoke-tests/pom.xml b/tests/smoke-tests/pom.xml
index 5caef58..b8885af 100644
--- a/tests/smoke-tests/pom.xml
+++ b/tests/smoke-tests/pom.xml
@@ -229,6 +229,24 @@
                      </args>
                   </configuration>
                </execution>
+               <execution>
+                  <phase>test-compile</phase>
+                  <id>create-createJMX2</id>
+                  <goals>
+                     <goal>create</goal>
+                  </goals>
+                  <configuration>
+                     <allowAnonymous>true</allowAnonymous>
+                     <user>admin</user>
+                     <password>admin</password>
+                     <instance>${basedir}/target/jmx2</instance>
+                     <args>
+                        <!-- this is needed to run the server remotely -->
+                        <arg>--java-options</arg>
+                        <arg>-Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=11099 -Dcom.sun.management.jmxremote.rmi.port=11098 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false</arg>
+                     </args>
+                  </configuration>
+               </execution>
 
             </executions>
             <dependencies>
diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx2/JmxServerControlTest.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx2/JmxServerControlTest.java
new file mode 100644
index 0000000..b0abf59
--- /dev/null
+++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx2/JmxServerControlTest.java
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.tests.smoke.jmx2;
+
+import javax.jms.Session;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
+import org.apache.activemq.artemis.api.core.JsonUtil;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
+import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
+import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
+import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JmxServerControlTest extends SmokeTestBase {
+   // This test will use a smoke created by the pom on this project (smoke-tsts)
+
+   private static final String JMX_SERVER_HOSTNAME = "localhost";
+   private static final int JMX_SERVER_PORT = 11099;
+
+   public static final String SERVER_NAME_0 = "jmx2";
+
+   @Before
+   public void before() throws Exception {
+      cleanupData(SERVER_NAME_0);
+      disableCheckThread();
+      startServer(SERVER_NAME_0, 0, 30000);
+   }
+
+   @Test
+   public void testListConsumers() throws Exception {
+      // Without this, the RMI server would bind to the default interface IP (the user's local IP mostly)
+      System.setProperty("java.rmi.server.hostname", JMX_SERVER_HOSTNAME);
+
+      // I don't specify both ports here manually on purpose. See actual RMI registry connection port extraction below.
+      String urlString = "service:jmx:rmi:///jndi/rmi://" + JMX_SERVER_HOSTNAME + ":" + JMX_SERVER_PORT + "/jmxrmi";
+
+      JMXServiceURL url = new JMXServiceURL(urlString);
+      JMXConnector jmxConnector = null;
+
+      try {
+         jmxConnector = JMXConnectorFactory.connect(url);
+         System.out.println("Successfully connected to: " + urlString);
+      } catch (Exception e) {
+         jmxConnector = null;
+         e.printStackTrace();
+         Assert.fail(e.getMessage());
+      }
+
+      try {
+         MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
+         String brokerName = "0.0.0.0";  // configured e.g. in broker.xml <broker-name> element
+         ObjectNameBuilder objectNameBuilder = ObjectNameBuilder.create(ActiveMQDefaultConfiguration.getDefaultJmxDomain(), brokerName, true);
+         ActiveMQServerControl activeMQServerControl = MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, objectNameBuilder.getActiveMQServerObjectName(), ActiveMQServerControl.class, false);
+
+         String addressName = "test_list_consumers_address";
+         String queueName = "test_list_consumers_queue";
+         activeMQServerControl.createAddress(addressName, RoutingType.ANYCAST.name());
+         activeMQServerControl.createQueue(addressName, queueName, RoutingType.ANYCAST.name());
+         String uri = "tcp://localhost:61616";
+         try (ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null)) {
+            cf.createConnection().createSession(true, Session.SESSION_TRANSACTED).createConsumer(new ActiveMQQueue(queueName));
+
+            String options = JsonUtil.toJsonObject(ImmutableMap.of("field","queue", "operation", "EQUALS", "value", queueName)).toString();
+            String consumersAsJsonString = activeMQServerControl.listConsumers(options, 1, 10);
+
+            JsonObject consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
+            JsonArray array = (JsonArray) consumersAsJsonObject.get("data");
+
+            Assert.assertEquals("number of consumers returned from query", 1, array.size());
+            JsonObject jsonConsumer = array.getJsonObject(0);
+            Assert.assertEquals("queue name in consumer", queueName, jsonConsumer.getString("queue"));
+            Assert.assertEquals("address name in consumer", addressName, jsonConsumer.getString("address"));
+         }
+      } finally {
+         jmxConnector.close();
+      }
+   }
+}