Skip to content

Commit

Permalink
[REMJMX-51] Added a test case to perform a smoke test for all support…
Browse files Browse the repository at this point in the history
…ed protocol versions.
  • Loading branch information
darranl committed Sep 7, 2012
1 parent 5875f0e commit 73466ee
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 2 deletions.
Expand Up @@ -51,6 +51,10 @@ public RemotingConnectorServer(final MBeanServer mbeanServer, final Endpoint end
this(mbeanServer, endpoint, Executors.newCachedThreadPool());
}

public RemotingConnectorServer(final MBeanServer mbeanServer, final Endpoint endpoint, final Map<String, ?> environment) {
this(mbeanServer, endpoint, Executors.newCachedThreadPool(), environment);
}

public RemotingConnectorServer(final MBeanServer mbeanServer, final Endpoint endpoint, Executor executor) {
this(mbeanServer, endpoint, executor, Collections.EMPTY_MAP);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jboss/remotingjmx/protocol/Versions.java
Expand Up @@ -84,7 +84,10 @@ private void split(final String from, final Set<Byte> to) {
String[] values = from.split(",");
for (String current : values) {
try {
to.add(Byte.valueOf(current.trim()));
String temp = current.trim();
if (temp.length() > 0) {
to.add(Byte.valueOf(current.trim()));
}
} catch (NumberFormatException e) {
log.warnf("Unrecognised version '%s' in list.", current);
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/jboss/remotingjmx/AbstractTestBase.java
Expand Up @@ -22,12 +22,15 @@

package org.jboss.remotingjmx;

import static org.jboss.remotingjmx.Constants.EXCLUDED_VERSIONS;
import static org.jboss.remotingjmx.common.Constants.BIND_ADDRESS_PROPERTY;
import static org.jboss.remotingjmx.common.Constants.DEFAULT_BIND_ADDRESS;
import static org.jboss.remotingjmx.common.Constants.PROTOCOL;
import static org.jboss.remotingjmx.common.JMXRemotingServer.DEFAULT_PORT;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
Expand Down Expand Up @@ -60,13 +63,18 @@ public abstract class AbstractTestBase {

@BeforeClass
public static void setupServer() throws IOException {
setupServer(null);
}

public static void setupServer(String excludedVersions) throws IOException {
bindAddress = System.getProperty(BIND_ADDRESS_PROPERTY, DEFAULT_BIND_ADDRESS);

mbeanServer = MBeanServerFactory.createMBeanServer(DEFAULT_DOMAIN);

JMXRemotingConfig config = new JMXRemotingConfig();
config.mbeanServer = mbeanServer;
config.host = bindAddress;
config.excludedVersions = excludedVersions;

remotingServer = new JMXRemotingServer(config);
remotingServer.start();
Expand All @@ -84,6 +92,14 @@ public static void tearDownServer() throws IOException {

@Before
public void connect() throws IOException {
connect(null);
}

public void connect(String excludedVersions) throws IOException {
Map<String, Object> environment = new HashMap<String, Object>();
if (excludedVersions != null) {
environment.put(EXCLUDED_VERSIONS, excludedVersions);
}
connector = JMXConnectorFactory.connect(serviceURL);
}

Expand Down
115 changes: 115 additions & 0 deletions src/test/java/org/jboss/remotingjmx/VersionSmokeTest.java
@@ -0,0 +1,115 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.remotingjmx;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.management.MBeanServerConnection;

import org.jboss.remotingjmx.protocol.Versions;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* Test case to ensure all versions of the protocols are used.
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
public class VersionSmokeTest extends AbstractTestBase {

// We still want the set-up as in the base class but we override the
// methods so we can control when these are call.

@BeforeClass
public static void setupServer() {
}

@AfterClass
public static void tearDownServer() {
}

@Before
public void connect() throws IOException {
}

@After
public void disconnect() throws IOException {
}

@Test
public void testVersions() throws Exception {
Versions versions = new Versions(Collections.EMPTY_MAP);
Set<Byte> supportedVersions = versions.getSupportedVersions();
Set<Byte> secondSupportedVersions = new HashSet<Byte>(supportedVersions);
for (Byte current : supportedVersions) {
StringBuilder sb = null;
for (Byte toAdd : secondSupportedVersions) {
if (toAdd != current) {
if (sb == null) {
sb = new StringBuilder();
} else {
sb.append(",");
}
sb.append(toAdd);
}
}
assertNotNull("At least one version should be excluded.", sb);

String excludedVersions = sb.toString();
super.setupServer(excludedVersions);
super.connect(excludedVersions);
smokeTest();
super.disconnect();
super.tearDownServer();
}
}

protected void smokeTest() throws Exception {
String defaultDomain = mbeanServer.getDefaultDomain();
assertNotNull("defaultDomain", defaultDomain);
assertEquals("Direct Access Default Domain", DEFAULT_DOMAIN, defaultDomain);

MBeanServerConnection connection = connector.getMBeanServerConnection();
defaultDomain = connection.getDefaultDomain();
assertNotNull("defaultDomain", defaultDomain);
assertEquals("Remote Access Default Domain", DEFAULT_DOMAIN, defaultDomain);

Integer count = mbeanServer.getMBeanCount();
assertNotNull("count", count);
assertEquals("Direct Access MBeanCount", (Integer) 1, count);

count = connection.getMBeanCount();
assertNotNull("count", count);
assertEquals("Remote Access MBeanCount", (Integer) 1, count);
}

}
Expand Up @@ -21,6 +21,7 @@
*/
package org.jboss.remotingjmx.common;

import static org.jboss.remotingjmx.Constants.EXCLUDED_VERSIONS;
import static org.xnio.Options.SASL_MECHANISMS;
import static org.xnio.Options.SASL_POLICY_NOANONYMOUS;
import static org.xnio.Options.SASL_POLICY_NOPLAINTEXT;
Expand All @@ -34,9 +35,11 @@
import java.security.Principal;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.management.MBeanServer;
Expand Down Expand Up @@ -101,6 +104,7 @@ public class JMXRemotingServer {
private final MBeanServer mbeanServer;
private final Set<String> saslMechanisms;
private final ServerAuthenticationProvider authenticationProvider;
private final String excludedVersions;

private Endpoint endpoint;
// TODO - This may not live here - maybe in the RemotingConnectorServer
Expand All @@ -125,6 +129,7 @@ public JMXRemotingServer(JMXRemotingConfig config) {
: Collections.EMPTY_SET);
authenticationProvider = config.authenticationProvider != null ? config.authenticationProvider
: new DefaultAuthenticationProvider();
excludedVersions = config.excludedVersions;
}

public void start() throws IOException {
Expand All @@ -142,8 +147,12 @@ public void start() throws IOException {

server = nsp.createServer(bindAddress, serverOptions, authenticationProvider, null);

Map<String, Object> configMap = new HashMap<String, Object>();
if (excludedVersions != null) {
configMap.put(EXCLUDED_VERSIONS, excludedVersions);
}
// Initialise the components that will provide JMX connectivity.
connectorServer = new RemotingConnectorServer(mbeanServer, endpoint);
connectorServer = new RemotingConnectorServer(mbeanServer, endpoint, configMap);
connectorServer.start();
}

Expand Down Expand Up @@ -348,6 +357,7 @@ public static class JMXRemotingConfig {
public MBeanServer mbeanServer = null;
public Set<String> saslMechanisms = null;
public ServerAuthenticationProvider authenticationProvider = null;
public String excludedVersions = null;
}

}

0 comments on commit 73466ee

Please sign in to comment.