Skip to content

Commit

Permalink
This is PR rh-messaging#250
Browse files Browse the repository at this point in the history
  • Loading branch information
clebertsuconic committed Jun 21, 2019
2 parents 53055f3 + 057af54 commit 7c0022f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
6 changes: 6 additions & 0 deletions artemis-cdi-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<properties>
<activemq.basedir>${project.basedir}/..</activemq.basedir>
<javax.annotation.version>1.3.2</javax.annotation.version>
</properties>

<artifactId>artemis-cdi-client</artifactId>
Expand Down Expand Up @@ -83,6 +84,11 @@
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotation.version}</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions artemis-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
<artifactId>jboss-jaxb-api_2.2_spec</artifactId>
<version>${version.jaxb-api}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<jetty.version>9.4.3.v20170317</jetty.version>
<jgroups.version>3.6.13.Final</jgroups.version>
<maven.assembly.plugin.version>2.4</maven.assembly.plugin.version>
<mockito.version>2.8.47</mockito.version>
<mockito.version>2.25.0</mockito.version>
<netty.version>4.1.32.Final</netty.version>
<commons.io.version>2.6</commons.io.version>
<netty-tcnative-version>2.0.22.Final</netty-tcnative-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import java.rmi.server.RemoteObject;
import java.rmi.server.RemoteRef;

import com.sun.jmx.remote.internal.ProxyRef;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess;
import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import sun.rmi.server.UnicastRef;
Expand All @@ -47,16 +49,30 @@ public class JmxConnectionTest extends SmokeTestBase {
private static final int RMI_REGISTRY_PORT = 10098;

public static final String SERVER_NAME_0 = "jmx";
private Class<?> proxyRefClass;

@Before
public void before() throws Exception {
cleanupData(SERVER_NAME_0);
disableCheckThread();
startServer(SERVER_NAME_0, 0, 30000);
try {
final Class<?> aClass = Class.forName("com.sun.jmx.remote.internal.ProxyRef");
proxyRefClass = aClass;
} catch (ClassNotFoundException ex) {
//try with a shiny new version
try {
final Class<?> aClass = Class.forName("com.sun.jmx.remote.internal.rmi.ProxyRef");
proxyRefClass = aClass;
} catch (ClassNotFoundException ex2) {
//no op
}
}
}

@Test
public void testJmxConnection() throws Throwable {
Assert.assertNotNull(proxyRefClass);
try {

// Without this, the RMI server would bind to the default interface IP (the user's local IP mostly)
Expand Down Expand Up @@ -96,17 +112,22 @@ public void testJmxConnection() throws Throwable {

// 3. RemoteObject::getRef is hereby expected to return ProxyRef
RemoteRef remoteRef = remoteObject.getRef();
Assert.assertTrue(remoteRef instanceof ProxyRef);
ProxyRef proxyRef = (ProxyRef) remoteRef;

Assert.assertTrue(proxyRefClass.isInstance(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);
Field refField = proxyRefClass.getDeclaredField("ref");
RemoteRef remoteRefField;
try {
refField.setAccessible(true);
remoteRefField = (RemoteRef) refField.get(remoteRef);
} catch (Throwable error) {
Assume.assumeTrue("Unsafe must be available to continue the test", PlatformDependent.hasUnsafe());
remoteRefField = (RemoteRef) UnsafeAccess.UNSAFE.getObject(remoteRef, UnsafeAccess.UNSAFE.objectFieldOffset(refField));
}
Assert.assertNotNull(remoteRefField);
Assert.assertTrue(remoteRefField instanceof UnicastRef);

// 5. UnicastRef::getLiveRef returns LiveRef
LiveRef liveRef = ((UnicastRef) remoteRef).getLiveRef();
LiveRef liveRef = ((UnicastRef) remoteRefField).getLiveRef();

Assert.assertEquals(RMI_REGISTRY_PORT, liveRef.getPort());

Expand All @@ -119,5 +140,4 @@ public void testJmxConnection() throws Throwable {
}
}


}

0 comments on commit 7c0022f

Please sign in to comment.