Skip to content

Commit

Permalink
ARTEMIS-4174 fix style & rat
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram committed Sep 1, 2023
1 parent 791fb7f commit 691771c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class RmiRegistryFactory {
private Registry registry;
private String host;
private HostLimitedServerSocketFactory socketFactory;

/**
* @return the port
*/
Expand All @@ -62,7 +63,7 @@ public void setHost(String host) {
* Create a server socket for testing purposes.
*/
ServerSocket createTestSocket() throws IOException {
return socketFactory.createServerSocket(1100);
return socketFactory.createServerSocket(1100);
}

public Object getObject() throws Exception {
Expand All @@ -72,13 +73,13 @@ public Object getObject() throws Exception {
class HostLimitedServerSocketFactory implements RMIServerSocketFactory {
@Override
public ServerSocket createServerSocket(int port) throws IOException {
InetAddress hostAddress;
if (host != null) {
hostAddress = InetAddress.getByName(host);
} else {
hostAddress = null; // accept connections on all local addresses
}
return ServerSocketFactory.getDefault().createServerSocket(port, 0, hostAddress);
InetAddress hostAddress;
if (host != null) {
hostAddress = InetAddress.getByName(host);
} else {
hostAddress = null; // accept connections on all local addresses
}
return ServerSocketFactory.getDefault().createServerSocket(port, 0, hostAddress);
}
}

Expand All @@ -91,9 +92,7 @@ public Socket createSocket(String host, int port) throws IOException {

public void init() throws RemoteException, UnknownHostException {
socketFactory = new HostLimitedServerSocketFactory();
registry = LocateRegistry.createRegistry(port,
new PassThroughToDefaultSocketFactory(),
socketFactory);
registry = LocateRegistry.createRegistry(port, new PassThroughToDefaultSocketFactory(), socketFactory);
}

public void destroy() throws RemoteException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.core.server.management;

import org.apache.activemq.artemis.core.config.JMXConnectorConfiguration;
Expand All @@ -10,43 +26,40 @@

public class JMXRMIRegistryPortTest {

@Test
public void explicitLocalhostRegistry() throws IOException {
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
registryFactory.setHost("localhost");
registryFactory.setPort(1099);
registryFactory.init();
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
Assert.assertEquals(InetAddress.getByName("localhost"),
testSocket.getInetAddress());
}
registryFactory.destroy();
}
@Test
public void explicitLocalhostRegistry() throws IOException {
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
registryFactory.setHost("localhost");
registryFactory.setPort(1099);
registryFactory.init();
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
Assert.assertEquals(InetAddress.getByName("localhost"), testSocket.getInetAddress());
}
registryFactory.destroy();
}

@Test
public void unlimitedHostRegistry() throws IOException {
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
registryFactory.setHost(null);
registryFactory.setPort(1099);
registryFactory.init();
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
Assert.assertEquals(InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 }),
testSocket.getInetAddress());
}
registryFactory.destroy();
}
@Test
public void unlimitedHostRegistry() throws IOException {
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
registryFactory.setHost(null);
registryFactory.setPort(1099);
registryFactory.init();
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
Assert.assertEquals(InetAddress.getByAddress(new byte[]{0, 0, 0, 0}), testSocket.getInetAddress());
}
registryFactory.destroy();
}

@Test
public void defaultRegistry() throws IOException {
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
JMXConnectorConfiguration configuration = new JMXConnectorConfiguration();
registryFactory.setHost(configuration.getConnectorHost());
registryFactory.setPort(configuration.getConnectorPort());
registryFactory.init();
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
Assert.assertEquals(InetAddress.getByName("localhost"),
testSocket.getInetAddress());
}
registryFactory.destroy();
}
@Test
public void defaultRegistry() throws IOException {
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
JMXConnectorConfiguration configuration = new JMXConnectorConfiguration();
registryFactory.setHost(configuration.getConnectorHost());
registryFactory.setPort(configuration.getConnectorPort());
registryFactory.init();
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
Assert.assertEquals(InetAddress.getByName("localhost"), testSocket.getInetAddress());
}
registryFactory.destroy();
}
}

0 comments on commit 691771c

Please sign in to comment.