activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [activemq-artemis] branch master updated: NO-JIRA Fixing JMX Test
Date Sat, 04 May 2019 03:11:04 GMT
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic 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 b5b2cc9  NO-JIRA Fixing JMX Test
     new ac89471  This closes #2659
b5b2cc9 is described below

commit b5b2cc98b02e43101fb7449f59afc9c3f74f31e5
Author: Clebert Suconic <clebertsuconic@apache.org>
AuthorDate: Thu May 2 15:08:03 2019 -0400

    NO-JIRA Fixing JMX Test
    
    This test has been failing as part of the main testsuite
    and it should really be a smoke test as it is using a real test.
    so, I'm moving it as smoke-test
---
 .../server/management/ManagementConnector.java     |   1 +
 .../tests/integration/jmx/JmxConnectionTest.java   | 162 ---------------------
 tests/smoke-tests/pom.xml                          |  19 +++
 .../src/main/resources/servers/jmx/management.xml} |  23 +--
 .../artemis/tests/smoke/jmx/JmxConnectionTest.java | 123 ++++++++++++++++
 5 files changed, 155 insertions(+), 173 deletions(-)

diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementConnector.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementConnector.java
index 36113c6..1f53d49 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementConnector.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementConnector.java
@@ -59,6 +59,7 @@ public class ManagementConnector implements ActiveMQComponent {
 
       connectorServerFactory = new ConnectorServerFactory();
       connectorServerFactory.setServer(mbeanServer);
+      System.out.println("ServiceURL::" + configuration.getServiceUrl());
       connectorServerFactory.setServiceUrl(configuration.getServiceUrl());
       connectorServerFactory.setRmiServerHost(configuration.getConnectorHost());
       connectorServerFactory.setObjectName(new ObjectName(configuration.getObjectName()));
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jmx/JmxConnectionTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jmx/JmxConnectionTest.java
deleted file mode 100644
index 416dfcc..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jmx/JmxConnectionTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * 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
- * <br>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <br>
- * 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.integration.jmx;
-
-import com.sun.jmx.remote.internal.ProxyRef;
-import org.apache.activemq.artemis.cli.Artemis;
-import org.apache.activemq.artemis.cli.commands.Run;
-import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import sun.rmi.server.UnicastRef;
-import sun.rmi.transport.LiveRef;
-
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-import javax.management.remote.rmi.RMIConnection;
-import javax.management.remote.rmi.RMIConnector;
-import java.io.File;
-import java.lang.reflect.Field;
-import java.nio.file.Files;
-import java.nio.file.StandardCopyOption;
-import java.rmi.server.RemoteObject;
-import java.rmi.server.RemoteRef;
-import java.util.concurrent.TimeUnit;
-
-/**
- * This test checks JMX connection to Artemis with both necessary ports set up so that it's
easier to tunnel through
- * firewalls.
- */
-public class JmxConnectionTest extends ActiveMQTestBase {
-
-   private static final String MANAGEMENT_XML = "/jmx-test-management.xml";
-
-   // Make sure these values are always the same as in the MANAGEMENT_XML configuration file
-   private static final String JMX_SERVER_HOSTNAME = "127.0.0.1";
-   private static final int JMX_SERVER_PORT = 10099;
-   private static final int RMI_REGISTRY_PORT = 10098;
-
-   @Override
-   @Before
-   public void setUp() throws Exception {
-
-      super.setUp();
-
-      /* This needs to be disabled because otherwise there would be a lot of complains about
Artemis' own running threads
-       * and I suppose that this kind of leaks is most likely tested somewhere else.
-       */
-      disableCheckThread();
-
-      // Artemis instance dir
-      File instanceDir = new File(temporaryFolder.getRoot(), "instance");
-
-      // Create new Artemis instance
-      Run.setEmbedded(true);
-      Artemis.main("create", instanceDir.getAbsolutePath(), "--silent", "--no-fsync", "--no-autotune",
-              "--no-web", "--no-amqp-acceptor", "--no-mqtt-acceptor", "--no-stomp-acceptor",
"--no-hornetq-acceptor");
-
-      // Configure (this is THE subject of testing)
-      File managementConfigFile = new File(instanceDir, "etc/management.xml");
-      Files.copy(getClass().getResourceAsStream(MANAGEMENT_XML), managementConfigFile.toPath(),
-              StandardCopyOption.REPLACE_EXISTING);
-
-      // Point the server to the instance directory
-      System.setProperty("artemis.instance", instanceDir.getAbsolutePath());
-
-      // 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);
-
-      // Enable guest login module (dunno why this isn't automatic)
-      System.setProperty("java.security.auth.login.config", instanceDir.getAbsolutePath()
+ "/etc/login.config");
-
-      // Run Artemis server
-      Artemis.internalExecute("run");
-   }
-
-   @Test
-   public void testJmxConnection() throws Exception {
-
-      // 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;
-
-      try {
-         jmxConnector = JMXConnectorFactory.connect(url);
-         logAndSystemOut("Successfully connected to: " + urlString);
-      } catch (Exception e) {
-         logAndSystemOut("JMX connection failed: " + urlString, e);
-         Assert.fail(e.getMessage());
-         return;
-      }
-
-      try {
-
-         /* Now I need to extract the RMI registry port to make sure it's equal to the configured
one. It's gonna be
-          * messy because I have to use reflection to reach the information.
-          */
-
-         Assert.assertTrue(jmxConnector instanceof RMIConnector);
-
-         // 1. RMIConnector::connection is expected to be RMIConnectionImpl_Stub
-         Field connectionField = RMIConnector.class.getDeclaredField("connection");
-         connectionField.setAccessible(true);
-         RMIConnection rmiConnection = (RMIConnection) connectionField.get(jmxConnector);
-
-         // 2. RMIConnectionImpl_Stub extends RemoteStub which extends RemoteObject
-         Assert.assertTrue(rmiConnection instanceof RemoteObject);
-         RemoteObject remoteObject = (RemoteObject) rmiConnection;
-
-         // 3. RemoteObject::getRef is hereby expected to return ProxyRef
-         RemoteRef remoteRef = remoteObject.getRef();
-         Assert.assertTrue(remoteRef instanceof ProxyRef);
-         ProxyRef proxyRef = (ProxyRef) remoteRef;
-
-         // 4. ProxyRef::ref is expected to contain UnicastRef (UnicastRef2 resp.)
-         Field refField = ProxyRef.class.getDeclaredField("ref");
-         refField.setAccessible(true);
-         remoteRef = (RemoteRef) refField.get(proxyRef);
-         Assert.assertTrue(remoteRef instanceof UnicastRef);
-
-         // 5. UnicastRef::getLiveRef returns LiveRef
-         LiveRef liveRef = ((UnicastRef) remoteRef).getLiveRef();
-
-         // 6. LiveRef::getPort is expected to be the same as the RMI registry port configured
via management.xml
-         /* Accidentally, it can happen that even with the RMI registry port unconfigured
the randomly selected port
-          * will be the same as expected by the test which will make it succeed. But it's
highly unlikely.
-          */
-         Assert.assertEquals(RMI_REGISTRY_PORT, liveRef.getPort());
-
-      } finally {
-         jmxConnector.close();
-      }
-   }
-
-   @After
-   @Override
-   public void tearDown() throws Exception {
-      Artemis.internalExecute("stop");
-      Run.latchRunning.await(5, TimeUnit.SECONDS);
-      super.tearDown();
-   }
-
-}
diff --git a/tests/smoke-tests/pom.xml b/tests/smoke-tests/pom.xml
index 4c72161..2c75f6b 100644
--- a/tests/smoke-tests/pom.xml
+++ b/tests/smoke-tests/pom.xml
@@ -206,6 +206,25 @@
                      <instance>${basedir}/target/maxConsumers</instance>
                   </configuration>
                </execution>
+               <execution>
+                  <phase>test-compile</phase>
+                  <id>create-createJMX</id>
+                  <goals>
+                     <goal>create</goal>
+                  </goals>
+                  <configuration>
+                     <configuration>${basedir}/target/classes/servers/jmx</configuration>
+                     <allowAnonymous>true</allowAnonymous>
+                     <user>admin</user>
+                     <password>admin</password>
+                     <instance>${basedir}/target/jmx</instance>
+                     <args>
+                        <!-- this is needed to run the server remotely -->
+                        <arg>--java-options</arg>
+                        <arg>-Djava.rmi.server.hostname=localhost</arg>
+                     </args>
+                  </configuration>
+               </execution>
 
             </executions>
             <dependencies>
diff --git a/tests/integration-tests/src/test/resources/jmx-test-management.xml b/tests/smoke-tests/src/main/resources/servers/jmx/management.xml
similarity index 74%
rename from tests/integration-tests/src/test/resources/jmx-test-management.xml
rename to tests/smoke-tests/src/main/resources/servers/jmx/management.xml
index ac5ba6d..f62611e 100644
--- a/tests/integration-tests/src/test/resources/jmx-test-management.xml
+++ b/tests/smoke-tests/src/main/resources/servers/jmx/management.xml
@@ -16,25 +16,26 @@
   ~ limitations under the License.
   -->
 <management-context xmlns="http://activemq.org/schema">
-   <connector connector-port="10099" connector-host="127.0.0.1" rmi-registry-port="10098"
/>
+   <!-- carai -->
+   <connector connector-port="10099" connector-host="localhost" rmi-registry-port="10098"
/>
    <authorisation>
       <whitelist>
          <entry domain="hawtio"/>
       </whitelist>
       <default-access>
-         <access method="list*" roles="${role}"/>
-         <access method="get*" roles="${role}"/>
-         <access method="is*" roles="${role}"/>
-         <access method="set*" roles="${role}"/>
-         <access method="*" roles="${role}"/>
+         <access method="list*" roles="amq"/>
+         <access method="get*" roles="amq"/>
+         <access method="is*" roles="amq"/>
+         <access method="set*" roles="amq"/>
+         <access method="*" roles="amq"/>
       </default-access>
       <role-access>
          <match domain="org.apache.activemq.artemis">
-            <access method="list*" roles="${role}"/>
-            <access method="get*" roles="${role}"/>
-            <access method="is*" roles="${role}"/>
-            <access method="set*" roles="${role}"/>
-            <access method="*" roles="${role}"/>
+            <access method="list*" roles="amq"/>
+            <access method="get*" roles="amq"/>
+            <access method="is*" roles="amq"/>
+            <access method="set*" roles="amq"/>
+            <access method="*" roles="amq"/>
          </match>
          <!--example of how to configure a specific object-->
          <!--<match domain="org.apache.activemq.artemis" key="subcomponent=queues">
diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx/JmxConnectionTest.java
b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx/JmxConnectionTest.java
new file mode 100644
index 0000000..bb21c92
--- /dev/null
+++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx/JmxConnectionTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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
+ * <br>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <br>
+ * 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.jmx;
+
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import javax.management.remote.rmi.RMIConnection;
+import javax.management.remote.rmi.RMIConnector;
+import java.lang.reflect.Field;
+import java.rmi.server.RemoteObject;
+import java.rmi.server.RemoteRef;
+
+import com.sun.jmx.remote.internal.ProxyRef;
+import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import sun.rmi.server.UnicastRef;
+import sun.rmi.transport.LiveRef;
+
+/**
+ * This test checks JMX connection to Artemis with both necessary ports set up so that it's
easier to tunnel through
+ * firewalls.
+ */
+public class JmxConnectionTest 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 = 10099;
+   private static final int RMI_REGISTRY_PORT = 10098;
+
+   public static final String SERVER_NAME_0 = "jmx";
+
+   @Before
+   public void before() throws Exception {
+      cleanupData(SERVER_NAME_0);
+      disableCheckThread();
+      startServer(SERVER_NAME_0, 0, 30000);
+   }
+
+   @Test
+   public void testJmxConnection() throws Throwable {
+      try {
+
+         // 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;
+
+         try {
+            jmxConnector = JMXConnectorFactory.connect(url);
+            System.out.println("Successfully connected to: " + urlString);
+         } catch (Exception e) {
+            jmxConnector = null;
+            e.printStackTrace();
+            Assert.fail(e.getMessage());
+         }
+
+         try {
+
+         /* Now I need to extract the RMI registry port to make sure it's equal to the configured
one. It's gonna be
+          * messy because I have to use reflection to reach the information.
+          */
+
+            Assert.assertTrue(jmxConnector instanceof RMIConnector);
+
+            // 1. RMIConnector::connection is expected to be RMIConnectionImpl_Stub
+            Field connectionField = RMIConnector.class.getDeclaredField("connection");
+            connectionField.setAccessible(true);
+            RMIConnection rmiConnection = (RMIConnection) connectionField.get(jmxConnector);
+
+            // 2. RMIConnectionImpl_Stub extends RemoteStub which extends RemoteObject
+            Assert.assertTrue(rmiConnection instanceof RemoteObject);
+            RemoteObject remoteObject = (RemoteObject) rmiConnection;
+
+            // 3. RemoteObject::getRef is hereby expected to return ProxyRef
+            RemoteRef remoteRef = remoteObject.getRef();
+            Assert.assertTrue(remoteRef instanceof ProxyRef);
+            ProxyRef proxyRef = (ProxyRef) remoteRef;
+
+            // 4. ProxyRef::ref is expected to contain UnicastRef (UnicastRef2 resp.)
+            Field refField = ProxyRef.class.getDeclaredField("ref");
+            refField.setAccessible(true);
+            remoteRef = (RemoteRef) refField.get(proxyRef);
+            Assert.assertTrue(remoteRef instanceof UnicastRef);
+
+            // 5. UnicastRef::getLiveRef returns LiveRef
+            LiveRef liveRef = ((UnicastRef) remoteRef).getLiveRef();
+
+            Assert.assertEquals(RMI_REGISTRY_PORT, liveRef.getPort());
+
+         } finally {
+            jmxConnector.close();
+         }
+      } catch (Throwable e) {
+         e.printStackTrace();
+         throw e;
+      }
+   }
+
+
+}


Mime
View raw message