diff options
Diffstat (limited to 'qpid/java/broker/src/test/java/org/apache/qpid')
37 files changed, 1011 insertions, 3695 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java deleted file mode 100644 index 63423cbaa7..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java +++ /dev/null @@ -1,196 +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 - * - * 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.qpid.server; - -import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; -import static org.apache.qpid.server.configuration.ServerConfiguration.DEFAULT_PORT; -import static org.apache.qpid.server.configuration.ServerConfiguration.DEFAULT_JMXPORT; - -import java.util.Collections; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - - -import org.apache.qpid.test.utils.QpidTestCase; - - -public class BrokerOptionsTest extends QpidTestCase -{ - private BrokerOptions _options; - - private static final int TEST_PORT1 = 6789; - private static final int TEST_PORT2 = 6790; - - - protected void setUp() - { - _options = new BrokerOptions(); - } - - public void testDefaultPort() - { - assertEquals(Collections.<Integer>emptySet(), _options.getPorts()); - } - - public void testOverriddenPort() - { - _options.addPort(TEST_PORT1); - assertEquals(Collections.singleton(TEST_PORT1), _options.getPorts()); - } - - public void testManyOverriddenPorts() - { - _options.addPort(TEST_PORT1); - _options.addPort(TEST_PORT2); - final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); - assertEquals(expectedPorts, _options.getPorts()); - } - - public void testDuplicateOverriddenPortsAreSilentlyIgnored() - { - _options.addPort(TEST_PORT1); - _options.addPort(TEST_PORT2); - _options.addPort(TEST_PORT1); // duplicate - should be silently ignored - final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); - assertEquals(expectedPorts, _options.getPorts()); - } - - public void testDefaultSSLPort() - { - assertEquals(Collections.<Integer>emptySet(), _options.getSSLPorts()); - } - - public void testOverriddenSSLPort() - { - _options.addSSLPort(TEST_PORT1); - assertEquals(Collections.singleton(TEST_PORT1), _options.getSSLPorts()); - } - - public void testManyOverriddenSSLPorts() - { - _options.addSSLPort(TEST_PORT1); - _options.addSSLPort(TEST_PORT2); - final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); - assertEquals(expectedPorts, _options.getSSLPorts()); - } - - public void testDuplicateOverriddenSSLPortsAreSilentlyIgnored() - { - _options.addSSLPort(TEST_PORT1); - _options.addSSLPort(TEST_PORT2); - _options.addSSLPort(TEST_PORT1); // duplicate - should be silently ignored - final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); - assertEquals(expectedPorts, _options.getSSLPorts()); - } - - public void testDefaultConfigFile() - { - assertNull(_options.getConfigFile()); - } - - public void testOverriddenConfigFile() - { - final String testConfigFile = "etc/mytestconfig.xml"; - _options.setConfigFile(testConfigFile); - assertEquals(testConfigFile, _options.getConfigFile()); - } - - public void testDefaultLogConfigFile() - { - assertNull(_options.getLogConfigFile()); - } - - public void testOverriddenLogConfigFile() - { - final String testLogConfigFile = "etc/mytestlog4j.xml"; - _options.setLogConfigFile(testLogConfigFile); - assertEquals(testLogConfigFile, _options.getLogConfigFile()); - } - - public void testDefaultJmxPort() - { - assertNull(_options.getJmxPort()); - } - - public void testJmxPort() - { - _options.setJmxPort(TEST_PORT1); - assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPort()); - } - - public void testQpidHomeExposesSysProperty() - { - assertEquals(System.getProperty("QPID_HOME"), _options.getQpidHome()); - } - - public void testDefaultExcludesPortFor0_10() - { - assertEquals(Collections.EMPTY_SET, _options.getExcludedPorts(ProtocolExclusion.v0_10)); - } - - public void testOverriddenExcludesPortFor0_10() - { - _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1); - assertEquals(Collections.singleton(TEST_PORT1), _options.getExcludedPorts(ProtocolExclusion.v0_10)); - } - - public void testManyOverriddenExcludedPortFor0_10() - { - _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1); - _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT2); - final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); - assertEquals(expectedPorts, _options.getExcludedPorts(ProtocolExclusion.v0_10)); - } - - public void testDuplicatedOverriddenExcludedPortFor0_10AreSilentlyIgnored() - { - _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1); - _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT2); - final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); - assertEquals(expectedPorts, _options.getExcludedPorts(ProtocolExclusion.v0_10)); - } - - public void testDefaultBind() - { - assertNull(_options.getBind()); - } - - public void testOverriddenBind() - { - final String bind = "192.168.0.1"; - _options.setBind(bind); - assertEquals(bind, _options.getBind()); - } - - public void testDefaultLogWatchFrequency() - { - assertEquals(0L, _options.getLogWatchFrequency()); - } - - public void testOverridenLogWatchFrequency() - { - final int myFreq = 10 * 1000; - - _options.setLogWatchFrequency(myFreq); - assertEquals(myFreq, _options.getLogWatchFrequency()); - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java deleted file mode 100644 index 3bb8d33190..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.apache.qpid.server; - -import java.util.EnumSet; - -import org.apache.qpid.test.utils.QpidTestCase; - -/** - * Test to verify the command line parsing within the Main class, by - * providing it a series of command line arguments and verifying the - * BrokerOptions emerging for use in starting the Broker instance. - */ -public class MainTest extends QpidTestCase -{ - public void testNoOptionsSpecified() - { - BrokerOptions options = startDummyMain(""); - - assertTrue(options.getPorts().isEmpty()); - assertTrue(options.getSSLPorts().isEmpty()); - assertEquals(null, options.getJmxPort()); - assertEquals(null, options.getConfigFile()); - assertEquals(null, options.getLogConfigFile()); - assertEquals(null, options.getBind()); - - for(ProtocolExclusion pe : EnumSet.allOf(ProtocolExclusion.class)) - { - assertEquals(0, options.getExcludedPorts(pe).size()); - } - } - - public void testPortOverriddenSingle() - { - BrokerOptions options = startDummyMain("-p 1234"); - - assertTrue(options.getPorts().contains(1234)); - assertEquals(1, options.getPorts().size()); - assertTrue(options.getSSLPorts().isEmpty()); - } - - public void testPortOverriddenMultiple() - { - BrokerOptions options = startDummyMain("-p 1234 -p 4321"); - - assertTrue(options.getPorts().contains(1234)); - assertTrue(options.getPorts().contains(4321)); - assertEquals(2, options.getPorts().size()); - assertTrue(options.getSSLPorts().isEmpty()); - } - - public void testSSLPortOverriddenSingle() - { - BrokerOptions options = startDummyMain("-s 5678"); - - assertTrue(options.getSSLPorts().contains(5678)); - assertEquals(1, options.getSSLPorts().size()); - assertTrue(options.getPorts().isEmpty()); - } - - public void testSSLPortOverriddenMultiple() - { - BrokerOptions options = startDummyMain("-s 5678 -s 8765"); - - assertTrue(options.getSSLPorts().contains(5678)); - assertTrue(options.getSSLPorts().contains(8765)); - assertEquals(2, options.getSSLPorts().size()); - assertTrue(options.getPorts().isEmpty()); - } - - public void testNonSSLandSSLPortsOverridden() - { - BrokerOptions options = startDummyMain("-p 5678 -s 8765"); - - assertTrue(options.getPorts().contains(5678)); - assertTrue(options.getSSLPorts().contains(8765)); - assertEquals(1, options.getPorts().size()); - assertEquals(1, options.getSSLPorts().size()); - } - - public void testJMXportOverridden() - { - BrokerOptions options = startDummyMain("-m 3456"); - - assertEquals(Integer.valueOf(3456), options.getJmxPort()); - } - - public void testExclude0_10() - { - BrokerOptions options = startDummyMain("-p 3456 --exclude-0-10 3456"); - - assertTrue(options.getPorts().contains(3456)); - assertEquals(1, options.getPorts().size()); - assertTrue(options.getExcludedPorts(ProtocolExclusion.v0_10).contains(3456)); - assertEquals(1, options.getExcludedPorts(ProtocolExclusion.v0_10).size()); - assertEquals(0, options.getExcludedPorts(ProtocolExclusion.v0_9_1).size()); - } - - public void testConfig() - { - BrokerOptions options = startDummyMain("-c abcd/config.xml"); - - assertEquals("abcd/config.xml", options.getConfigFile()); - } - - public void testLogConfig() - { - BrokerOptions options = startDummyMain("-l wxyz/log4j.xml"); - - assertEquals("wxyz/log4j.xml", options.getLogConfigFile()); - } - - public void testLogWatch() - { - BrokerOptions options = startDummyMain("-w 9"); - - assertEquals(9, options.getLogWatchFrequency()); - } - - private BrokerOptions startDummyMain(String commandLine) - { - return (new TestMain(commandLine.split("\\s"))).getOptions(); - } - - private class TestMain extends Main - { - private BrokerOptions _options; - - public TestMain(String[] args) - { - super(args); - } - - @Override - protected void startBroker(BrokerOptions options) - { - _options = options; - } - - public BrokerOptions getOptions() - { - return _options; - } - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/RunBrokerWithCommand.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/RunBrokerWithCommand.java new file mode 100644 index 0000000000..59543874b4 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/RunBrokerWithCommand.java @@ -0,0 +1,132 @@ +/* + * 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.qpid.server; + +import org.apache.log4j.Logger; +import org.apache.log4j.Level; + +import java.io.InputStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; + +public class RunBrokerWithCommand +{ + public static void main(String[] args) + { + //Start the broker + try + { + String[] fudge = args.clone(); + + // Override the first value which is the command we are going to run later. + fudge[0] = "-v"; + new Main(fudge).startup(); + } + catch (Exception e) + { + System.err.println("Unable to start broker due to: " + e.getMessage()); + + e.printStackTrace(); + exit(1); + } + + Logger.getRootLogger().setLevel(Level.ERROR); + + //run command + try + { + Process task = Runtime.getRuntime().exec(args[0]); + System.err.println("Started Proccess: " + args[0]); + + InputStream inputStream = task.getInputStream(); + + InputStream errorStream = task.getErrorStream(); + + Thread out = new Thread(new Outputter("[OUT]", new BufferedReader(new InputStreamReader(inputStream)))); + Thread err = new Thread(new Outputter("[ERR]", new BufferedReader(new InputStreamReader(errorStream)))); + + out.start(); + err.start(); + + out.join(); + err.join(); + + System.err.println("Waiting for process to exit: " + args[0]); + task.waitFor(); + System.err.println("Done Proccess: " + args[0]); + + } + catch (IOException e) + { + System.err.println("Proccess had problems: " + e.getMessage()); + e.printStackTrace(System.err); + exit(1); + } + catch (InterruptedException e) + { + System.err.println("Proccess had problems: " + e.getMessage()); + e.printStackTrace(System.err); + + exit(1); + } + + + exit(0); + } + + private static void exit(int i) + { + Logger.getRootLogger().setLevel(Level.INFO); + System.exit(i); + } + + static class Outputter implements Runnable + { + + BufferedReader reader; + String prefix; + + Outputter(String s, BufferedReader r) + { + prefix = s; + reader = r; + } + + public void run() + { + String line; + try + { + while ((line = reader.readLine()) != null) + { + System.out.println(prefix + line); + } + } + catch (IOException e) + { + System.out.println("Error occured reading; " + e.getMessage()); + } + } + + } + +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java index b0893eb53f..718874cf69 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java @@ -20,558 +20,742 @@ */ package org.apache.qpid.server.configuration; -import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; - import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.List; import java.util.Locale; +import junit.framework.TestCase; + import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.exchange.Exchange; +import org.apache.qpid.server.protocol.AMQProtocolEngine; +import org.apache.qpid.server.protocol.AMQProtocolSession; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; -import org.apache.qpid.server.util.TestApplicationRegistry; +import org.apache.qpid.server.util.InternalBrokerBaseCase; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; -import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.transport.TestNetworkDriver; -public class ServerConfigurationTest extends QpidTestCase +public class ServerConfigurationTest extends InternalBrokerBaseCase { private XMLConfiguration _config = new XMLConfiguration(); - private ServerConfiguration _serverConfig = null; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - _serverConfig = new ServerConfiguration(_config); - ApplicationRegistry.initialise(new TestApplicationRegistry(_serverConfig)); - } - @Override - protected void tearDown() throws Exception - { - super.tearDown(); - ApplicationRegistry.remove(); - } public void testSetJMXManagementPort() throws ConfigurationException { - _serverConfig.initialise(); - _serverConfig.setJMXManagementPort(23); - assertEquals(23, _serverConfig.getJMXManagementPort()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + serverConfig.setJMXManagementPort(23); + assertEquals(23, serverConfig.getJMXManagementPort()); } public void testGetJMXManagementPort() throws ConfigurationException { _config.setProperty("management.jmxport", 42); - _serverConfig.initialise(); - assertEquals(42, _serverConfig.getJMXManagementPort()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(42, serverConfig.getJMXManagementPort()); } public void testGetPlatformMbeanserver() throws ConfigurationException { - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getPlatformMbeanserver()); + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getPlatformMbeanserver()); // Check value we set _config.setProperty("management.platform-mbeanserver", false); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getPlatformMbeanserver()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getPlatformMbeanserver()); } public void testGetPluginDirectory() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(null, _serverConfig.getPluginDirectory()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(null, serverConfig.getPluginDirectory()); // Check value we set _config.setProperty("plugin-directory", "/path/to/plugins"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("/path/to/plugins", _serverConfig.getPluginDirectory()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("/path/to/plugins", serverConfig.getPluginDirectory()); } public void testGetCacheDirectory() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(null, _serverConfig.getCacheDirectory()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(null, serverConfig.getCacheDirectory()); // Check value we set _config.setProperty("cache-directory", "/path/to/cache"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("/path/to/cache", _serverConfig.getCacheDirectory()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("/path/to/cache", serverConfig.getCacheDirectory()); + } + + public void testGetPrincipalDatabaseNames() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getPrincipalDatabaseNames().size()); + + // Check value we set + _config.setProperty("security.principal-databases.principal-database(0).name", "a"); + _config.setProperty("security.principal-databases.principal-database(1).name", "b"); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + List<String> dbs = serverConfig.getPrincipalDatabaseNames(); + assertEquals(2, dbs.size()); + assertEquals("a", dbs.get(0)); + assertEquals("b", dbs.get(1)); + } + + public void testGetPrincipalDatabaseClass() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getPrincipalDatabaseClass().size()); + + // Check value we set + _config.setProperty("security.principal-databases.principal-database(0).class", "a"); + _config.setProperty("security.principal-databases.principal-database(1).class", "b"); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + List<String> dbs = serverConfig.getPrincipalDatabaseClass(); + assertEquals(2, dbs.size()); + assertEquals("a", dbs.get(0)); + assertEquals("b", dbs.get(1)); + } + + public void testGetPrincipalDatabaseAttributeNames() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getPrincipalDatabaseAttributeNames(1).size()); + + // Check value we set + _config.setProperty("security.principal-databases.principal-database(0).attributes(0).attribute.name", "a"); + _config.setProperty("security.principal-databases.principal-database(0).attributes(1).attribute.name", "b"); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + List<String> dbs = serverConfig.getPrincipalDatabaseAttributeNames(0); + assertEquals(2, dbs.size()); + assertEquals("a", dbs.get(0)); + assertEquals("b", dbs.get(1)); + } + + public void testGetPrincipalDatabaseAttributeValues() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getPrincipalDatabaseAttributeValues(1).size()); + + // Check value we set + _config.setProperty("security.principal-databases.principal-database(0).attributes(0).attribute.value", "a"); + _config.setProperty("security.principal-databases.principal-database(0).attributes(1).attribute.value", "b"); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + List<String> dbs = serverConfig.getPrincipalDatabaseAttributeValues(0); + assertEquals(2, dbs.size()); + assertEquals("a", dbs.get(0)); + assertEquals("b", dbs.get(1)); + } + + public void testGetManagementAccessList() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getManagementAccessList().size()); + + // Check value we set + _config.setProperty("security.jmx.access(0)", "a"); + _config.setProperty("security.jmx.access(1)", "b"); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + List<String> dbs = serverConfig.getManagementAccessList(); + assertEquals(2, dbs.size()); + assertEquals("a", dbs.get(0)); + assertEquals("b", dbs.get(1)); } public void testGetFrameSize() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(65536, _serverConfig.getFrameSize()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(65536, serverConfig.getFrameSize()); // Check value we set _config.setProperty("advanced.framesize", "23"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(23, _serverConfig.getFrameSize()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(23, serverConfig.getFrameSize()); + } + + public void testGetProtectIOEnabled() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getProtectIOEnabled()); + + // Check value we set + _config.setProperty(ServerConfiguration.CONNECTOR_PROTECTIO_ENABLED, true); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getProtectIOEnabled()); + } + + public void testGetBufferReadLimit() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(262144, serverConfig.getBufferReadLimit()); + + // Check value we set + _config.setProperty(ServerConfiguration.CONNECTOR_PROTECTIO_READ_BUFFER_LIMIT_SIZE, 23); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(23, serverConfig.getBufferReadLimit()); } + public void testGetBufferWriteLimit() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(262144, serverConfig.getBufferWriteLimit()); + + // Check value we set + _config.setProperty(ServerConfiguration.CONNECTOR_PROTECTIO_WRITE_BUFFER_LIMIT_SIZE, 23); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(23, serverConfig.getBufferWriteLimit()); + } + + public void testGetStatusEnabled() throws ConfigurationException { // Check default - _serverConfig.initialise(); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); assertEquals(ServerConfiguration.DEFAULT_STATUS_UPDATES.equalsIgnoreCase("on"), - _serverConfig.getStatusUpdatesEnabled()); + serverConfig.getStatusUpdatesEnabled()); // Check disabling we set _config.setProperty(ServerConfiguration.STATUS_UPDATES, "off"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getStatusUpdatesEnabled()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getStatusUpdatesEnabled()); // Check invalid values don't cause error but result in disabled _config.setProperty(ServerConfiguration.STATUS_UPDATES, "Yes Please"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getStatusUpdatesEnabled()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getStatusUpdatesEnabled()); } public void testGetSynchedClocks() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getSynchedClocks()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getSynchedClocks()); // Check value we set _config.setProperty("advanced.synced-clocks", true); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getSynchedClocks()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getSynchedClocks()); } public void testGetLocale() throws ConfigurationException { // Check default - _serverConfig.initialise(); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); // The Default is what ever the VMs default is Locale defaultLocale = Locale.getDefault(); - assertEquals(defaultLocale, _serverConfig.getLocale()); + assertEquals(defaultLocale, serverConfig.getLocale()); //Test Language only Locale update = new Locale("es"); _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(update, _serverConfig.getLocale()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(update, serverConfig.getLocale()); //Test Language and Country update = new Locale("es","ES"); _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es_ES"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(update, _serverConfig.getLocale()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(update, serverConfig.getLocale()); //Test Language and Country and Variant update = new Locale("es","ES", "Traditional_WIN"); _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es_ES_Traditional_WIN"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(update, _serverConfig.getLocale()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(update, serverConfig.getLocale()); } public void testGetMsgAuth() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getMsgAuth()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getMsgAuth()); // Check value we set _config.setProperty("security.msg-auth", true); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getMsgAuth()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getMsgAuth()); + } + + public void testGetJMXPrincipalDatabase() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(null, serverConfig.getJMXPrincipalDatabase()); + + // Check value we set + _config.setProperty("security.jmx.principal-database", "a"); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("a", serverConfig.getJMXPrincipalDatabase()); } public void testGetManagementKeyStorePath() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(null, _serverConfig.getManagementKeyStorePath()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(null, serverConfig.getManagementKeyStorePath()); // Check value we set _config.setProperty("management.ssl.keyStorePath", "a"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("a", _serverConfig.getManagementKeyStorePath()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("a", serverConfig.getManagementKeyStorePath()); } public void testGetManagementSSLEnabled() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getManagementSSLEnabled()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getManagementSSLEnabled()); // Check value we set _config.setProperty("management.ssl.enabled", false); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getManagementSSLEnabled()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getManagementSSLEnabled()); } public void testGetManagementKeyStorePassword() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(null, _serverConfig.getManagementKeyStorePassword()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(null, serverConfig.getManagementKeyStorePassword()); // Check value we set _config.setProperty("management.ssl.keyStorePassword", "a"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("a", _serverConfig.getManagementKeyStorePassword()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("a", serverConfig.getManagementKeyStorePassword()); } public void testGetQueueAutoRegister() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getQueueAutoRegister()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getQueueAutoRegister()); // Check value we set _config.setProperty("queue.auto_register", false); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getQueueAutoRegister()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getQueueAutoRegister()); } public void testGetManagementEnabled() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getManagementEnabled()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getManagementEnabled()); // Check value we set _config.setProperty("management.enabled", false); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getManagementEnabled()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getManagementEnabled()); } public void testSetManagementEnabled() throws ConfigurationException { // Check value we set - _serverConfig.initialise(); - _serverConfig.setManagementEnabled(false); - assertEquals(false, _serverConfig.getManagementEnabled()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + serverConfig.setManagementEnabled(false); + assertEquals(false, serverConfig.getManagementEnabled()); } public void testGetHeartBeatDelay() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(5, _serverConfig.getHeartBeatDelay()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(5, serverConfig.getHeartBeatDelay()); // Check value we set _config.setProperty("heartbeat.delay", 23); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(23, _serverConfig.getHeartBeatDelay()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(23, serverConfig.getHeartBeatDelay()); } public void testGetHeartBeatTimeout() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(2.0, _serverConfig.getHeartBeatTimeout()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(2.0, serverConfig.getHeartBeatTimeout()); // Check value we set _config.setProperty("heartbeat.timeoutFactor", 2.3); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(2.3, _serverConfig.getHeartBeatTimeout()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(2.3, serverConfig.getHeartBeatTimeout()); } public void testGetMaximumMessageAge() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(0, _serverConfig.getMaximumMessageAge()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getMaximumMessageAge()); // Check value we set _config.setProperty("maximumMessageAge", 10L); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(10, _serverConfig.getMaximumMessageAge()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(10, serverConfig.getMaximumMessageAge()); } public void testGetMaximumMessageCount() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(0, _serverConfig.getMaximumMessageCount()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getMaximumMessageCount()); // Check value we set _config.setProperty("maximumMessageCount", 10L); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(10, _serverConfig.getMaximumMessageCount()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(10, serverConfig.getMaximumMessageCount()); } public void testGetMaximumQueueDepth() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(0, _serverConfig.getMaximumQueueDepth()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getMaximumQueueDepth()); // Check value we set _config.setProperty("maximumQueueDepth", 10L); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(10, _serverConfig.getMaximumQueueDepth()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(10, serverConfig.getMaximumQueueDepth()); } public void testGetMaximumMessageSize() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(0, _serverConfig.getMaximumMessageSize()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getMaximumMessageSize()); // Check value we set _config.setProperty("maximumMessageSize", 10L); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(10, _serverConfig.getMaximumMessageSize()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(10, serverConfig.getMaximumMessageSize()); } public void testGetMinimumAlertRepeatGap() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(0, _serverConfig.getMinimumAlertRepeatGap()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(0, serverConfig.getMinimumAlertRepeatGap()); // Check value we set _config.setProperty("minimumAlertRepeatGap", 10L); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(10, _serverConfig.getMinimumAlertRepeatGap()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(10, serverConfig.getMinimumAlertRepeatGap()); } public void testGetProcessors() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(4, _serverConfig.getConnectorProcessors()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(4, serverConfig.getProcessors()); // Check value we set _config.setProperty("connector.processors", 10); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(10, _serverConfig.getConnectorProcessors()); - } + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(10, serverConfig.getProcessors()); + } - public void testGetPorts() throws ConfigurationException + public void testGetPort() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertNotNull(_serverConfig.getPorts()); - assertEquals(1, _serverConfig.getPorts().size()); - assertEquals(5672, _serverConfig.getPorts().get(0)); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertNotNull(serverConfig.getPorts()); + assertEquals(1, serverConfig.getPorts().size()); + assertEquals(5672, serverConfig.getPorts().get(0)); // Check value we set _config.setProperty("connector.port", "10"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertNotNull(_serverConfig.getPorts()); - assertEquals(1, _serverConfig.getPorts().size()); - assertEquals("10", _serverConfig.getPorts().get(0)); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertNotNull(serverConfig.getPorts()); + assertEquals(1, serverConfig.getPorts().size()); + assertEquals("10", serverConfig.getPorts().get(0)); } public void testGetBind() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(WILDCARD_ADDRESS, _serverConfig.getBind()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("wildcard", serverConfig.getBind()); // Check value we set _config.setProperty("connector.bind", "a"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("a", _serverConfig.getBind()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("a", serverConfig.getBind()); } public void testGetReceiveBufferSize() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(ServerConfiguration.DEFAULT_BUFFER_SIZE, _serverConfig.getReceiveBufferSize()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(32767, serverConfig.getReceiveBufferSize()); // Check value we set _config.setProperty("connector.socketReceiveBuffer", "23"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(23, _serverConfig.getReceiveBufferSize()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(23, serverConfig.getReceiveBufferSize()); } public void testGetWriteBufferSize() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(ServerConfiguration.DEFAULT_BUFFER_SIZE, _serverConfig.getWriteBufferSize()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(32767, serverConfig.getWriteBufferSize()); // Check value we set _config.setProperty("connector.socketWriteBuffer", "23"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(23, _serverConfig.getWriteBufferSize()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(23, serverConfig.getWriteBufferSize()); } public void testGetTcpNoDelay() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getTcpNoDelay()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getTcpNoDelay()); // Check value we set _config.setProperty("connector.tcpNoDelay", false); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getTcpNoDelay()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getTcpNoDelay()); } public void testGetEnableExecutorPool() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getEnableExecutorPool()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getEnableExecutorPool()); // Check value we set _config.setProperty("advanced.filterchain[@enableExecutorPool]", true); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getEnableExecutorPool()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getEnableExecutorPool()); } public void testGetEnableSSL() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getEnableSSL()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getEnableSSL()); // Check value we set _config.setProperty("connector.ssl.enabled", true); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getEnableSSL()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getEnableSSL()); } public void testGetSSLOnly() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getSSLOnly()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getSSLOnly()); // Check value we set _config.setProperty("connector.ssl.sslOnly", true); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getSSLOnly()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getSSLOnly()); } - public void testGetSSLPorts() throws ConfigurationException + public void testGetSSLPort() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertNotNull(_serverConfig.getSSLPorts()); - assertEquals(1, _serverConfig.getSSLPorts().size()); - assertEquals(ServerConfiguration.DEFAULT_SSL_PORT, _serverConfig.getSSLPorts().get(0)); - + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(8672, serverConfig.getSSLPort()); // Check value we set - _config.setProperty("connector.ssl.port", "10"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertNotNull(_serverConfig.getSSLPorts()); - assertEquals(1, _serverConfig.getSSLPorts().size()); - assertEquals("10", _serverConfig.getSSLPorts().get(0)); + _config.setProperty("connector.ssl.port", 23); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(23, serverConfig.getSSLPort()); } public void testGetKeystorePath() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals("none", _serverConfig.getKeystorePath()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("none", serverConfig.getKeystorePath()); // Check value we set _config.setProperty("connector.ssl.keystorePath", "a"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("a", _serverConfig.getKeystorePath()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("a", serverConfig.getKeystorePath()); } public void testGetKeystorePassword() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals("none", _serverConfig.getKeystorePassword()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("none", serverConfig.getKeystorePassword()); // Check value we set _config.setProperty("connector.ssl.keystorePassword", "a"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("a", _serverConfig.getKeystorePassword()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("a", serverConfig.getKeystorePassword()); } public void testGetCertType() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals("SunX509", _serverConfig.getCertType()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("SunX509", serverConfig.getCertType()); // Check value we set _config.setProperty("connector.ssl.certType", "a"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("a", _serverConfig.getCertType()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals("a", serverConfig.getCertType()); + } + + public void testGetQpidNIO() throws ConfigurationException + { + // Check default + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getQpidNIO()); + + // Check value we set + _config.setProperty("connector.qpidnio", true); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getQpidNIO()); } public void testGetUseBiasedWrites() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(false, _serverConfig.getUseBiasedWrites()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(false, serverConfig.getUseBiasedWrites()); // Check value we set _config.setProperty("advanced.useWriteBiasedPool", true); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(true, _serverConfig.getUseBiasedWrites()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(true, serverConfig.getUseBiasedWrites()); } public void testGetHousekeepingExpiredMessageCheckPeriod() throws ConfigurationException { // Check default - _serverConfig.initialise(); - assertEquals(30000, _serverConfig.getHousekeepingCheckPeriod()); + ServerConfiguration serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(30000, serverConfig.getHousekeepingCheckPeriod()); // Check value we set _config.setProperty("housekeeping.expiredMessageCheckPeriod", 23L); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals(23, _serverConfig.getHousekeepingCheckPeriod()); - _serverConfig.setHousekeepingExpiredMessageCheckPeriod(42L); - assertEquals(42, _serverConfig.getHousekeepingCheckPeriod()); + serverConfig = new ServerConfiguration(_config); + serverConfig.initialise(); + assertEquals(23, serverConfig.getHousekeepingCheckPeriod()); + serverConfig.setHousekeepingExpiredMessageCheckPeriod(42L); + assertEquals(42, serverConfig.getHousekeepingCheckPeriod()); } public void testSingleConfiguration() throws IOException, ConfigurationException @@ -583,7 +767,7 @@ public class ServerConfigurationTest extends QpidTestCase out.close(); ServerConfiguration conf = new ServerConfiguration(fileA); conf.initialise(); - assertEquals("4235", conf.getSSLPorts().get(0)); + assertEquals(4235, conf.getSSLPort()); } public void testCombinedConfiguration() throws IOException, ConfigurationException @@ -608,17 +792,19 @@ public class ServerConfigurationTest extends QpidTestCase out.close(); out = new FileWriter(fileB); - out.write("<broker><connector><ssl><port>2345</port></ssl></connector></broker>"); + out.write("<broker><connector><ssl><port>2345</port></ssl><qpidnio>true</qpidnio></connector></broker>"); out.close(); ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile()); config.initialise(); - assertEquals("4235", config.getSSLPorts().get(0)); // From first file, not + assertEquals(4235, config.getSSLPort()); // From first file, not // overriden by second assertNotNull(config.getPorts()); assertEquals(1, config.getPorts().size()); assertEquals("2342", config.getPorts().get(0)); // From the first file, not // present in the second + assertEquals(true, config.getQpidNIO()); // From the second file, not + // present in the first } public void testVariableInterpolation() throws Exception @@ -649,8 +835,9 @@ public class ServerConfigurationTest extends QpidTestCase out.write("<broker>\n"); out.write("\t<management><enabled>false</enabled></management>\n"); out.write("\t<security>\n"); - out.write("\t\t<pd-auth-manager>\n"); + out.write("\t\t<principal-databases>\n"); out.write("\t\t\t<principal-database>\n"); + out.write("\t\t\t\t<name>passwordfile</name>\n"); out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n"); out.write("\t\t\t\t<attributes>\n"); out.write("\t\t\t\t\t<attribute>\n"); @@ -659,7 +846,11 @@ public class ServerConfigurationTest extends QpidTestCase out.write("\t\t\t\t\t</attribute>\n"); out.write("\t\t\t\t</attributes>\n"); out.write("\t\t\t</principal-database>\n"); - out.write("\t\t</pd-auth-manager>\n"); + out.write("\t\t</principal-databases>\n"); + out.write("\t\t<jmx>\n"); + out.write("\t\t\t<access>/dev/null</access>\n"); + out.write("\t\t\t<principal-database>passwordfile</principal-database>\n"); + out.write("\t\t</jmx>\n"); out.write("\t\t<firewall>\n"); out.write("\t\t\t<rule access=\""+ ((allow) ? "allow" : "deny") +"\" network=\"127.0.0.1\"/>"); out.write("\t\t</firewall>\n"); @@ -695,8 +886,9 @@ public class ServerConfigurationTest extends QpidTestCase out.write("<broker>\n"); out.write("\t<management><enabled>false</enabled></management>\n"); out.write("\t<security>\n"); - out.write("\t\t<pd-auth-manager>\n"); + out.write("\t\t<principal-databases>\n"); out.write("\t\t\t<principal-database>\n"); + out.write("\t\t\t\t<name>passwordfile</name>\n"); out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n"); out.write("\t\t\t\t<attributes>\n"); out.write("\t\t\t\t\t<attribute>\n"); @@ -705,7 +897,11 @@ public class ServerConfigurationTest extends QpidTestCase out.write("\t\t\t\t\t</attribute>\n"); out.write("\t\t\t\t</attributes>\n"); out.write("\t\t\t</principal-database>\n"); - out.write("\t\t</pd-auth-manager>\n"); + out.write("\t\t</principal-databases>\n"); + out.write("\t\t<jmx>\n"); + out.write("\t\t\t<access>/dev/null</access>\n"); + out.write("\t\t\t<principal-database>passwordfile</principal-database>\n"); + out.write("\t\t</jmx>\n"); out.write("\t\t<firewall>\n"); out.write("\t\t\t<rule access=\"allow\" network=\"127.0.0.1\"/>"); out.write("\t\t</firewall>\n"); @@ -796,8 +992,9 @@ public class ServerConfigurationTest extends QpidTestCase out.write("<broker>\n"); out.write("\t<management><enabled>false</enabled></management>\n"); out.write("\t<security>\n"); - out.write("\t\t<pd-auth-manager>\n"); + out.write("\t\t<principal-databases>\n"); out.write("\t\t\t<principal-database>\n"); + out.write("\t\t\t\t<name>passwordfile</name>\n"); out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n"); out.write("\t\t\t\t<attributes>\n"); out.write("\t\t\t\t\t<attribute>\n"); @@ -806,7 +1003,11 @@ public class ServerConfigurationTest extends QpidTestCase out.write("\t\t\t\t\t</attribute>\n"); out.write("\t\t\t\t</attributes>\n"); out.write("\t\t\t</principal-database>\n"); - out.write("\t\t</pd-auth-manager>\n"); + out.write("\t\t</principal-databases>\n"); + out.write("\t\t<jmx>\n"); + out.write("\t\t\t<access>/dev/null</access>\n"); + out.write("\t\t\t<principal-database>passwordfile</principal-database>\n"); + out.write("\t\t</jmx>\n"); out.write("\t\t<firewall>\n"); out.write("\t\t\t<rule access=\"allow\" network=\"127.0.0.1\"/>"); out.write("\t\t</firewall>\n"); @@ -843,9 +1044,8 @@ public class ServerConfigurationTest extends QpidTestCase writeConfigFile(mainFile, false, true, null, "test"); // Load config - ApplicationRegistry.remove(); ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg, 1); // Test config VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry(); @@ -876,9 +1076,8 @@ public class ServerConfigurationTest extends QpidTestCase writeVirtualHostsFile(vhostsFile, "test"); // Load config - ApplicationRegistry.remove(); ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg, 1); // Test config VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry(); @@ -911,9 +1110,8 @@ public class ServerConfigurationTest extends QpidTestCase writeConfigFile(mainFile, false, false, vhostsFile, null); // Load config - ApplicationRegistry.remove(); ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg, 1); // Test config VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry(); @@ -955,10 +1153,9 @@ public class ServerConfigurationTest extends QpidTestCase // Load config try - { - ApplicationRegistry.remove(); + { ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg, 1); fail("Different virtualhost XML configurations not allowed"); } catch (ConfigurationException ce) @@ -991,9 +1188,8 @@ public class ServerConfigurationTest extends QpidTestCase // Load config try { - ApplicationRegistry.remove(); ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg, 1); fail("Multiple virtualhost XML configurations not allowed"); } catch (ConfigurationException ce) @@ -1285,81 +1481,4 @@ public class ServerConfigurationTest extends QpidTestCase fail("Should throw a ConfigurationException"); } } - - /* - * Tests that the old element security.jmx.access (that used to be used - * to define JMX access rights) is rejected. - */ - public void testManagementAccessRejected() throws ConfigurationException - { - // Check default - _serverConfig.initialise(); - - // Check value we set - _config.setProperty("security.jmx.access(0)", "jmxremote.access"); - _serverConfig = new ServerConfiguration(_config); - - try - { - _serverConfig.initialise(); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - assertEquals("Incorrect error message", - "Validation error : security/jmx/access is no longer a supported element within the configuration xml.", - ce.getMessage()); - } - } - - /* - * Tests that the old element security.jmx.principal-database (that used to define the - * principal database used for JMX authentication) is rejected. - */ - public void testManagementPrincipalDatabaseRejected() throws ConfigurationException - { - // Check default - _serverConfig.initialise(); - - // Check value we set - _config.setProperty("security.jmx.principal-database(0)", "mydb"); - _serverConfig = new ServerConfiguration(_config); - - try - { - _serverConfig.initialise(); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - assertEquals("Incorrect error message", - "Validation error : security/jmx/principal-database is no longer a supported element within the configuration xml.", - ce.getMessage()); - } - } - - /* - * Tests that the old element security.principal-databases. ... (that used to define - * principal databases) is rejected. - */ - public void testPrincipalDatabasesRejected() throws ConfigurationException - { - _serverConfig.initialise(); - - // Check value we set - _config.setProperty("security.principal-databases.principal-database.class", "myclass"); - _serverConfig = new ServerConfiguration(_config); - - try - { - _serverConfig.initialise(); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - assertEquals("Incorrect error message", - "Validation error : security/principal-databases is no longer supported within the configuration xml.", - ce.getMessage()); - } - } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java index 593119041d..917755e8a5 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java @@ -20,8 +20,6 @@ package org.apache.qpid.server.configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.XMLConfiguration; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.queue.AMQPriorityQueue; import org.apache.qpid.server.queue.AMQQueue; @@ -205,29 +203,5 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase } - /** - * Tests that the old element security.authentication.name is rejected. This element - * was never supported properly as authentication is performed before the virtual host - * is considered. - */ - public void testSecurityAuthenticationNameRejected() throws Exception - { - getConfigXml().addProperty("virtualhosts.virtualhost.testSecurityAuthenticationNameRejected.security.authentication.name", - "testdb"); - - try - { - super.createBroker(); - fail("Exception not thrown"); - } - catch(ConfigurationException ce) - { - assertEquals("Incorrect error message", - "Validation error : security/authentication/name is no longer a supported element within the configuration xml." + - " It appears in virtual host definition : " + getName(), - ce.getMessage()); - } - } - } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java index 44da761353..7b58966a4c 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java @@ -276,7 +276,7 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase static ContentHeaderBody getContentHeader(FieldTable headers) { ContentHeaderBody header = new ContentHeaderBody(); - header.setProperties(getProperties(headers)); + header.properties = getProperties(headers); return header; } @@ -482,16 +482,6 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase { return 0; //To change body of implemented methods use File | Settings | File Templates. } - - public boolean isDequeued() - { - return false; - } - - public boolean isDispensed() - { - return false; - } }; if(action != null) diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java index 403a290a0f..f72961c03c 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java @@ -396,7 +396,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase IncomingMessage message = new IncomingMessage(info); final ContentHeaderBody chb = new ContentHeaderBody(); BasicContentHeaderProperties props = new BasicContentHeaderProperties(); - chb.setProperties(props); + chb.properties = props; message.setContentHeaderBody(chb); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java index e8defd0e58..3752dcb37e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java @@ -28,7 +28,11 @@ import org.apache.qpid.server.logging.AbstractRootMessageLogger; public class UnitTestMessageLogger extends AbstractRootMessageLogger { - private final List<Object> _log = new LinkedList<Object>(); + List<Object> _log; + + { + _log = new LinkedList<Object>(); + } public UnitTestMessageLogger() { @@ -65,14 +69,4 @@ public class UnitTestMessageLogger extends AbstractRootMessageLogger { _log.clear(); } - - public boolean messageContains(final int index, final String contains) - { - if (index + 1 > _log.size()) - { - throw new IllegalArgumentException("Message with index " + index + " has not been logged"); - } - final String message = _log.get(index).toString(); - return message.contains(contains); - } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java index f3ee2707b0..a6c17e042e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java @@ -21,26 +21,22 @@ package org.apache.qpid.server.management; +import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.TabularData; - - -import org.apache.commons.lang.NotImplementedException; -import org.apache.qpid.management.common.mbeans.UserManagement; +import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; import org.apache.qpid.server.security.auth.management.AMQUserManagementMBean; import org.apache.qpid.server.util.InternalBrokerBaseCase; -/** - * - * Tests the AMQUserManagementMBean and its interaction with the PrincipalDatabase. - * +/* Note: The main purpose is to test the jmx access rights file manipulation + * within AMQUserManagementMBean. The Principal Databases are tested by their own tests, + * this test just exercises their usage in AMQUserManagementMBean. */ public class AMQUserManagementMBeanTest extends InternalBrokerBaseCase { @@ -48,6 +44,7 @@ public class AMQUserManagementMBeanTest extends InternalBrokerBaseCase private AMQUserManagementMBean _amqumMBean; private File _passwordFile; + private File _accessFile; private static final String TEST_USERNAME = "testuser"; private static final String TEST_PASSWORD = "password"; @@ -60,6 +57,7 @@ public class AMQUserManagementMBeanTest extends InternalBrokerBaseCase _database = new PlainPasswordFilePrincipalDatabase(); _amqumMBean = new AMQUserManagementMBean(); loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); } @Override @@ -67,67 +65,142 @@ public class AMQUserManagementMBeanTest extends InternalBrokerBaseCase { //clean up test password/access files File _oldPasswordFile = new File(_passwordFile.getAbsolutePath() + ".old"); + File _oldAccessFile = new File(_accessFile.getAbsolutePath() + ".old"); _oldPasswordFile.delete(); + _oldAccessFile.delete(); _passwordFile.delete(); + _accessFile.delete(); super.tearDown(); } public void testDeleteUser() { - assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size()); - assertTrue("Delete should return true to flag successful delete", _amqumMBean.deleteUser(TEST_USERNAME)); - assertEquals("Unexpected number of users after test", 0,_amqumMBean.viewUsers().size()); - } - - public void testDeleteUserWhereUserDoesNotExist() - { - assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size()); - assertFalse("Delete should return false to flag unsuccessful delete", _amqumMBean.deleteUser("made.up.username")); - assertEquals("Unexpected number of users after test", 1,_amqumMBean.viewUsers().size()); + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); + //try deleting a non existant user + assertFalse(_amqumMBean.deleteUser("made.up.username")); + + assertTrue(_amqumMBean.deleteUser(TEST_USERNAME)); } - public void testCreateUser() + public void testDeleteUserIsSavedToAccessFile() { - assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size()); - assertTrue("Create should return true to flag successful create", _amqumMBean.createUser("newuser", "mypass")); - assertEquals("Unexpected number of users before test", 2,_amqumMBean.viewUsers().size()); - } + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); - public void testCreateUserWhereUserAlreadyExists() - { - assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size()); - assertFalse("Create should return false to flag unsuccessful create", _amqumMBean.createUser(TEST_USERNAME, "mypass")); - assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size()); + assertTrue(_amqumMBean.deleteUser(TEST_USERNAME)); + + //check the access rights were actually deleted from the file + try{ + BufferedReader reader = new BufferedReader(new FileReader(_accessFile)); + + //check the 'generated by' comment line is present + assertTrue("File has no content", reader.ready()); + assertTrue("'Generated by' comment line was missing",reader.readLine().contains("Generated by " + + "AMQUserManagementMBean Console : Last edited by user:")); + + //there should also be a modified date/time comment line + assertTrue("File has no modified date/time comment line", reader.ready()); + assertTrue("Modification date/time comment line was missing",reader.readLine().startsWith("#")); + + //the access file should not contain any further data now as we just deleted the only user + assertFalse("User access data was present when it should have been deleted", reader.ready()); + } + catch (IOException e) + { + fail("Unable to valdate file contents due to:" + e.getMessage()); + } + } - public void testSetPassword() + public void testSetRights() { - assertTrue("Set password should return true to flag successful change", _amqumMBean.setPassword(TEST_USERNAME, "newpassword")); + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); + + assertFalse(_amqumMBean.setRights("made.up.username", true, false, false)); + + assertTrue(_amqumMBean.setRights(TEST_USERNAME, true, false, false)); + assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, true, false)); + assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, false, true)); } - public void testSetPasswordWhereUserDoesNotExist() + public void testSetRightsIsSavedToAccessFile() { - assertFalse("Set password should return false to flag successful change", _amqumMBean.setPassword("made.up.username", "newpassword")); + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); + + assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, false, true)); + + //check the access rights were actually updated in the file + try{ + BufferedReader reader = new BufferedReader(new FileReader(_accessFile)); + + //check the 'generated by' comment line is present + assertTrue("File has no content", reader.ready()); + assertTrue("'Generated by' comment line was missing",reader.readLine().contains("Generated by " + + "AMQUserManagementMBean Console : Last edited by user:")); + + //there should also be a modified date/time comment line + assertTrue("File has no modified date/time comment line", reader.ready()); + assertTrue("Modification date/time comment line was missing",reader.readLine().startsWith("#")); + + //the access file should not contain any further data now as we just deleted the only user + assertTrue("User access data was not updated in the access file", + reader.readLine().equals(TEST_USERNAME + "=" + MBeanInvocationHandlerImpl.ADMIN)); + + //the access file should not contain any further data now as we just deleted the only user + assertFalse("Additional user access data was present when there should be no more", reader.ready()); + } + catch (IOException e) + { + fail("Unable to valdate file contents due to:" + e.getMessage()); + } } - public void testViewUsers() + public void testSetAccessFileWithMissingFile() { - TabularData userList = _amqumMBean.viewUsers(); + try + { + _amqumMBean.setAccessFile("made.up.filename"); + } + catch (IOException e) + { + fail("Should not have been an IOE." + e.getMessage()); + } + catch (ConfigurationException e) + { + assertTrue(e.getMessage(), e.getMessage().endsWith("does not exist")); + } + } - assertNotNull(userList); - assertEquals("Unexpected number of users in user list", 1, userList.size()); - assertTrue(userList.containsKey(new Object[]{TEST_USERNAME})); - - // Check the deprecated read, write and admin items continue to exist but return false. - CompositeData userRec = userList.get(new Object[]{TEST_USERNAME}); - assertTrue(userRec.containsKey(UserManagement.RIGHTS_READ_ONLY)); - assertEquals(false, userRec.get(UserManagement.RIGHTS_READ_ONLY)); - assertEquals(false, userRec.get(UserManagement.RIGHTS_READ_WRITE)); - assertTrue(userRec.containsKey(UserManagement.RIGHTS_READ_WRITE)); - assertTrue(userRec.containsKey(UserManagement.RIGHTS_ADMIN)); - assertEquals(false, userRec.get(UserManagement.RIGHTS_ADMIN)); + public void testSetAccessFileWithReadOnlyFile() + { + File testFile = null; + try + { + testFile = File.createTempFile(this.getClass().getName(),".access.readonly"); + BufferedWriter passwordWriter = new BufferedWriter(new FileWriter(testFile, false)); + passwordWriter.write(TEST_USERNAME + ":" + TEST_PASSWORD); + passwordWriter.newLine(); + passwordWriter.flush(); + passwordWriter.close(); + + testFile.setReadOnly(); + _amqumMBean.setAccessFile(testFile.getPath()); + } + catch (IOException e) + { + fail("Access file was not created." + e.getMessage()); + } + catch (ConfigurationException e) + { + fail("There should not have been a configuration exception." + e.getMessage()); + } + + testFile.delete(); } // ============================ Utility methods ========================= @@ -154,4 +227,37 @@ public class AMQUserManagementMBeanTest extends InternalBrokerBaseCase fail("Unable to create test password file: " + e.getMessage()); } } + + private void loadFreshTestAccessFile() + { + try + { + if(_accessFile == null) + { + _accessFile = File.createTempFile(this.getClass().getName(),".access"); + } + + BufferedWriter accessWriter = new BufferedWriter(new FileWriter(_accessFile,false)); + accessWriter.write("#Last Updated By comment"); + accessWriter.newLine(); + accessWriter.write("#Date/time comment"); + accessWriter.newLine(); + accessWriter.write(TEST_USERNAME + "=" + MBeanInvocationHandlerImpl.READONLY); + accessWriter.newLine(); + accessWriter.flush(); + accessWriter.close(); + } + catch (IOException e) + { + fail("Unable to create test access file: " + e.getMessage()); + } + + try{ + _amqumMBean.setAccessFile(_accessFile.toString()); + } + catch (Exception e) + { + fail("Unable to set access file: " + e.getMessage()); + } + } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java index 3af665141c..3b6cd37ea9 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java @@ -21,31 +21,23 @@ package org.apache.qpid.server.protocol; import java.security.Principal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import javax.security.auth.Subject; - import org.apache.qpid.AMQException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.ContentHeaderBody; import org.apache.qpid.framing.abstraction.MessagePublishInfo; import org.apache.qpid.protocol.AMQConstant; import org.apache.qpid.server.AMQChannel; -import org.apache.qpid.server.message.AMQMessage; -import org.apache.qpid.server.message.MessageContentSource; import org.apache.qpid.server.output.ProtocolOutputConverter; +import org.apache.qpid.server.message.AMQMessage; import org.apache.qpid.server.queue.QueueEntry; import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal; import org.apache.qpid.server.state.AMQState; import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.transport.TestNetworkConnection; +import org.apache.qpid.server.message.MessageContentSource; +import org.apache.qpid.transport.TestNetworkDriver; public class InternalTestProtocolSession extends AMQProtocolEngine implements ProtocolOutputConverter { @@ -55,13 +47,18 @@ public class InternalTestProtocolSession extends AMQProtocolEngine implements Pr public InternalTestProtocolSession(VirtualHost virtualHost) throws AMQException { - super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkConnection()); + super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkDriver()); _channelDelivers = new HashMap<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>>(); // Need to authenticate session for it to be representative testing. - setAuthorizedSubject(new Subject(true, Collections.singleton(new UsernamePrincipal("InternalTestProtocolSession")), - Collections.EMPTY_SET, Collections.EMPTY_SET)); + setAuthorizedID(new Principal() + { + public String getName() + { + return "InternalTestProtocolSession"; + } + }); setVirtualHost(virtualHost); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java index 3961b3b355..d52f4c03f3 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java @@ -96,7 +96,7 @@ public class AMQPriorityQueueTest extends SimpleAMQQueueTest AMQMessage msg = super.createMessage(id); BasicContentHeaderProperties props = new BasicContentHeaderProperties(); props.setPriority(i); - msg.getContentHeaderBody().setProperties(props); + msg.getContentHeaderBody().properties = props; return msg; } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java index a8bddcf6bf..0707cab3d5 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java @@ -277,7 +277,7 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase ContentHeaderBody contentHeaderBody = new ContentHeaderBody(); BasicContentHeaderProperties props = new BasicContentHeaderProperties(); - contentHeaderBody.setProperties(props); + contentHeaderBody.properties = props; contentHeaderBody.bodySize = size; // in bytes IncomingMessage message = new IncomingMessage(publish); message.setContentHeaderBody(contentHeaderBody); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java index 365353e734..5b72cfac40 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java @@ -402,8 +402,8 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase ContentHeaderBody contentHeaderBody = new ContentHeaderBody(); contentHeaderBody.bodySize = MESSAGE_SIZE; // in bytes - contentHeaderBody.setProperties(new BasicContentHeaderProperties()); - ((BasicContentHeaderProperties) contentHeaderBody.getProperties()).setDeliveryMode((byte) (persistent ? 2 : 1)); + contentHeaderBody.properties = new BasicContentHeaderProperties(); + ((BasicContentHeaderProperties) contentHeaderBody.properties).setDeliveryMode((byte) (persistent ? 2 : 1)); IncomingMessage msg = new IncomingMessage(publish); msg.setContentHeaderBody(contentHeaderBody); return msg; diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java index 0f5374b3e5..04608275a3 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java @@ -126,7 +126,7 @@ public class AckTest extends InternalBrokerBaseCase //IncomingMessage msg2 = null; BasicContentHeaderProperties b = new BasicContentHeaderProperties(); ContentHeaderBody cb = new ContentHeaderBody(); - cb.setProperties(b); + cb.properties = b; if (persistent) { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java index 4c31092983..888a16053c 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java @@ -29,7 +29,7 @@ import org.apache.qpid.server.subscription.Subscription; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.management.ManagedObject; import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.security.AuthorizationHolder; +import org.apache.qpid.server.security.PrincipalHolder; import org.apache.qpid.server.AMQChannel; import org.apache.qpid.server.protocol.AMQSessionModel; import org.apache.qpid.server.binding.Binding; @@ -48,7 +48,7 @@ public class MockAMQQueue implements AMQQueue private AMQShortString _name; private VirtualHost _virtualhost; - private AuthorizationHolder _authorizationHolder; + private PrincipalHolder _principalHolder; private AMQSessionModel _exclusiveOwner; private AMQShortString _owner; @@ -536,14 +536,14 @@ public class MockAMQQueue implements AMQQueue return null; //To change body of implemented methods use File | Settings | File Templates. } - public AuthorizationHolder getAuthorizationHolder() + public PrincipalHolder getPrincipalHolder() { - return _authorizationHolder; + return _principalHolder; } - public void setAuthorizationHolder(final AuthorizationHolder authorizationHolder) + public void setPrincipalHolder(PrincipalHolder principalHolder) { - _authorizationHolder = authorizationHolder; + _principalHolder = principalHolder; } public AMQSessionModel getExclusiveOwningSession() diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java index a3f8f4c0d3..5bdbe2c68e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java @@ -231,14 +231,4 @@ public class MockQueueEntry implements QueueEntry _message = msg; } - public boolean isDequeued() - { - return false; - } - - public boolean isDispensed() - { - return false; - } - } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java deleted file mode 100644 index 0899f25cc5..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java +++ /dev/null @@ -1,213 +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 - * - * 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.qpid.server.queue; - -import java.lang.reflect.Field; - -import junit.framework.TestCase; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.message.AMQMessage; -import org.apache.qpid.server.queue.QueueEntry.EntryState; -import org.apache.qpid.server.subscription.MockSubscription; - -/** - * Tests for {@link QueueEntryImpl} - * - */ -public class QueueEntryImplTest extends TestCase -{ - // tested entry - private QueueEntryImpl _queueEntry; - - public void setUp() throws Exception - { - AMQMessage message = new MockAMQMessage(1); - SimpleQueueEntryList queueEntryList = new SimpleQueueEntryList(new MockAMQQueue("test")); - _queueEntry = new QueueEntryImpl(queueEntryList, message, 1); - } - - public void testAquire() - { - assertTrue("Queue entry should be in AVAILABLE state before invoking of acquire method", - _queueEntry.isAvailable()); - acquire(); - } - - public void testDequeue() - { - dequeue(); - } - - public void testDelete() - { - delete(); - } - - /** - * Tests release method for entry in acquired state. - * <p> - * Entry in state ACQUIRED should be released and its status should be - * changed to AVAILABLE. - */ - public void testReleaseAquired() - { - acquire(); - _queueEntry.release(); - assertTrue("Queue entry should be in AVAILABLE state after invoking of release method", - _queueEntry.isAvailable()); - } - - /** - * Tests release method for entry in dequeued state. - * <p> - * Invoking release on dequeued entry should not have any effect on its - * state. - */ - public void testReleaseDequeued() - { - dequeue(); - _queueEntry.release(); - EntryState state = getState(); - assertEquals("Invoking of release on entry in DEQUEUED state should not have any effect", - QueueEntry.DEQUEUED_STATE, state); - } - - /** - * Tests release method for entry in deleted state. - * <p> - * Invoking release on deleted entry should not have any effect on its - * state. - */ - public void testReleaseDeleted() - { - delete(); - _queueEntry.release(); - assertTrue("Invoking of release on entry in DELETED state should not have any effect", - _queueEntry.isDeleted()); - } - - /** - * Tests if entries in DEQUQUED or DELETED state are not returned by getNext method. - */ - public void testGetNext() - { - int numberOfEntries = 5; - QueueEntryImpl[] entries = new QueueEntryImpl[numberOfEntries]; - SimpleQueueEntryList queueEntryList = new SimpleQueueEntryList(new MockAMQQueue("test")); - - // create test entries - for(int i = 0; i < numberOfEntries ; i++) - { - AMQMessage message = null;; - try - { - message = new MockAMQMessage(i); - } - catch (AMQException e) - { - fail("Failure to create a mock message:" + e.getMessage()); - } - QueueEntryImpl entry = (QueueEntryImpl)queueEntryList.add(message); - entries[i] = entry; - } - - // test getNext for not acquired entries - for(int i = 0; i < numberOfEntries ; i++) - { - QueueEntryImpl queueEntry = entries[i]; - QueueEntryImpl next = queueEntry.getNext(); - if (i < numberOfEntries - 1) - { - assertEquals("Unexpected entry from QueueEntryImpl#getNext()", entries[i + 1], next); - } - else - { - assertNull("The next entry after the last should be null", next); - } - } - - // delete second - entries[1].acquire(); - entries[1].delete(); - - // dequeue third - entries[2].acquire(); - entries[2].dequeue(); - - QueueEntryImpl next = entries[0].getNext(); - assertEquals("expected forth entry",entries[3], next); - next = next.getNext(); - assertEquals("expected fifth entry", entries[4], next); - next = next.getNext(); - assertNull("The next entry after the last should be null", next); - } - /** - * A helper method to put tested object into deleted state and assert the state - */ - private void delete() - { - _queueEntry.delete(); - assertTrue("Queue entry should be in DELETED state after invoking of delete method", - _queueEntry.isDeleted()); - } - - /** - * A helper method to put tested entry into dequeue state and assert the sate - */ - private void dequeue() - { - acquire(); - _queueEntry.dequeue(); - EntryState state = getState(); - assertEquals("Queue entry should be in DEQUEUED state after invoking of dequeue method", - QueueEntry.DEQUEUED_STATE, state); - } - - /** - * A helper method to put tested entry into acquired state and assert the sate - */ - private void acquire() - { - _queueEntry.acquire(new MockSubscription()); - assertTrue("Queue entry should be in ACQUIRED state after invoking of acquire method", - _queueEntry.isAcquired()); - } - - /** - * A helper method to get entry state - * - * @return entry state - */ - private EntryState getState() - { - EntryState state = null; - try - { - Field f = QueueEntryImpl.class.getDeclaredField("_state"); - f.setAccessible(true); - state = (EntryState) f.get(_queueEntry); - } - catch (Exception e) - { - fail("Failure to get a state field: " + e.getMessage()); - } - return state; - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java index 0e136c523f..67d093d00a 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java @@ -36,16 +36,13 @@ import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.exchange.DirectExchange; import org.apache.qpid.server.message.AMQMessage; import org.apache.qpid.server.message.MessageMetaData; -import org.apache.qpid.server.message.ServerMessage; import org.apache.qpid.server.queue.BaseQueue.PostEnqueueAction; -import org.apache.qpid.server.queue.SimpleAMQQueue.QueueEntryFilter; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.store.StoredMessage; import org.apache.qpid.server.store.TestableMemoryMessageStore; import org.apache.qpid.server.subscription.MockSubscription; import org.apache.qpid.server.subscription.Subscription; import org.apache.qpid.server.txn.AutoCommitTransaction; -import org.apache.qpid.server.txn.LocalTransaction; import org.apache.qpid.server.txn.ServerTransaction; import org.apache.qpid.server.util.InternalBrokerBaseCase; import org.apache.qpid.server.virtualhost.VirtualHost; @@ -54,8 +51,6 @@ import org.apache.qpid.server.virtualhost.VirtualHostImpl; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; public class SimpleAMQQueueTest extends InternalBrokerBaseCase { @@ -232,10 +227,10 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase } /** - * Tests that a released queue entry is resent to the subscriber. Verifies also that the + * Tests that a re-queued message is resent to the subscriber. Verifies also that the * QueueContext._releasedEntry is reset to null after the entry has been reset. */ - public void testReleasedMessageIsResentToSubscriber() throws Exception + public void testRequeuedMessageIsResentToSubscriber() throws Exception { _queue.registerSubscription(_subscription, false); @@ -258,18 +253,19 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase _queue.enqueue(messageB, postEnqueueAction); _queue.enqueue(messageC, postEnqueueAction); - Thread.sleep(150); // Work done by SubFlushRunner/QueueRunner Threads + Thread.sleep(150); // Work done by SubFlushRunner Thread assertEquals("Unexpected total number of messages sent to subscription", 3, _subscription.getMessages().size()); assertFalse("Redelivery flag should not be set", queueEntries.get(0).isRedelivered()); assertFalse("Redelivery flag should not be set", queueEntries.get(1).isRedelivered()); assertFalse("Redelivery flag should not be set", queueEntries.get(2).isRedelivered()); - /* Now release the first message only, causing it to be requeued */ + /* Now requeue the first message only */ queueEntries.get(0).release(); + _queue.requeue(queueEntries.get(0)); - Thread.sleep(150); // Work done by SubFlushRunner/QueueRunner Threads + Thread.sleep(150); // Work done by SubFlushRunner Thread assertEquals("Unexpected total number of messages sent to subscription", 4, _subscription.getMessages().size()); assertTrue("Redelivery flag should now be set", queueEntries.get(0).isRedelivered()); @@ -279,11 +275,11 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase } /** - * Tests that a released message that becomes expired is not resent to the subscriber. + * Tests that a re-queued message that becomes expired is not resent to the subscriber. * This tests ensures that SimpleAMQQueueEntry.getNextAvailableEntry avoids expired entries. * Verifies also that the QueueContext._releasedEntry is reset to null after the entry has been reset. */ - public void testReleaseMessageThatBecomesExpiredIsNotRedelivered() throws Exception + public void testRequeuedMessageThatBecomesExpiredIsNotRedelivered() throws Exception { _queue.registerSubscription(_subscription, false); @@ -305,16 +301,17 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase _queue.enqueue(messageA, postEnqueueAction); int subFlushWaitTime = 150; - Thread.sleep(subFlushWaitTime); // Work done by SubFlushRunner/QueueRunner Threads + Thread.sleep(subFlushWaitTime); // Work done by SubFlushRunner Thread assertEquals("Unexpected total number of messages sent to subscription", 1, _subscription.getMessages().size()); assertFalse("Redelivery flag should not be set", queueEntries.get(0).isRedelivered()); - /* Wait a little more to be sure that message will have expired, then release the first message only, causing it to be requeued */ + /* Wait a little more to be sure that message will have expired, then requeue it */ Thread.sleep(messageExpirationOffset - subFlushWaitTime + 10); queueEntries.get(0).release(); + _queue.requeue(queueEntries.get(0)); - Thread.sleep(subFlushWaitTime); // Work done by SubFlushRunner/QueueRunner Threads + Thread.sleep(subFlushWaitTime); // Work done by SubFlushRunner Thread assertTrue("Expecting the queue entry to be now expired", queueEntries.get(0).expired()); assertEquals("Total number of messages sent should not have changed", 1, _subscription.getMessages().size()); @@ -324,12 +321,12 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase } /** - * Tests that if a client releases entries 'out of order' (the order + * Tests that if a client requeues messages 'out of order' (the order * used by QueueEntryImpl.compareTo) that messages are still resent * successfully. Specifically this test ensures the {@see SimpleAMQQueue#requeue()} * can correctly move the _releasedEntry to an earlier position in the QueueEntry list. */ - public void testReleasedOutOfComparableOrderAreRedelivered() throws Exception + public void testMessagesRequeuedOutOfComparableOrderAreDelivered() throws Exception { _queue.registerSubscription(_subscription, false); @@ -352,19 +349,21 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase _queue.enqueue(messageB, postEnqueueAction); _queue.enqueue(messageC, postEnqueueAction); - Thread.sleep(150); // Work done by SubFlushRunner/QueueRunner Threads + Thread.sleep(150); // Work done by SubFlushRunner Thread assertEquals("Unexpected total number of messages sent to subscription", 3, _subscription.getMessages().size()); assertFalse("Redelivery flag should not be set", queueEntries.get(0).isRedelivered()); assertFalse("Redelivery flag should not be set", queueEntries.get(1).isRedelivered()); assertFalse("Redelivery flag should not be set", queueEntries.get(2).isRedelivered()); - /* Now release the third and first message only, causing it to be requeued */ + /* Now requeue the third and first message only */ queueEntries.get(2).release(); queueEntries.get(0).release(); + _queue.requeue(queueEntries.get(2)); + _queue.requeue(queueEntries.get(0)); - Thread.sleep(150); // Work done by SubFlushRunner/QueueRunner Threads + Thread.sleep(150); // Work done by SubFlushRunner Thread assertEquals("Unexpected total number of messages sent to subscription", 5, _subscription.getMessages().size()); assertTrue("Redelivery flag should now be set", queueEntries.get(0).isRedelivered()); @@ -375,10 +374,10 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase /** - * Tests that a release requeues an entry for a queue with multiple subscriptions. Verifies that a + * Tests a requeue for a queue with multiple subscriptions. Verifies that a * requeue resends a message to a <i>single</i> subscriber. */ - public void testReleaseForQueueWithMultipleSubscriptions() throws Exception + public void testRequeueForQueueWithMultipleSubscriptions() throws Exception { MockSubscription subscription1 = new MockSubscription(); MockSubscription subscription2 = new MockSubscription(); @@ -403,16 +402,66 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase _queue.enqueue(messageA, postEnqueueAction); _queue.enqueue(messageB, postEnqueueAction); - Thread.sleep(150); // Work done by SubFlushRunner/QueueRunner Threads + Thread.sleep(150); // Work done by SubFlushRunner Thread - assertEquals("Unexpected total number of messages sent to both after enqueue", 2, subscription1.getMessages().size() + subscription2.getMessages().size()); + assertEquals("Unexpected total number of messages sent to subscription1 after enqueue", 1, subscription1.getMessages().size()); + assertEquals("Unexpected total number of messages sent to subscription2 after enqueue", 1, subscription2.getMessages().size()); - /* Now release the first message only, causing it to be requeued */ - queueEntries.get(0).release(); + /* Now requeue a message (for any subscription) */ - Thread.sleep(150); // Work done by SubFlushRunner/QueueRunner Threads + queueEntries.get(0).release(); + _queue.requeue((QueueEntryImpl)queueEntries.get(0)); + + Thread.sleep(150); // Work done by SubFlushRunner Thread - assertEquals("Unexpected total number of messages sent to both subscriptions after release", 3, subscription1.getMessages().size() + subscription2.getMessages().size()); + assertEquals("Unexpected total number of messages sent to all subscriptions after requeue", 3, subscription1.getMessages().size() + subscription2.getMessages().size()); + assertNull("releasedEntry should be cleared after requeue processed", ((QueueContext)subscription1.getQueueContext())._releasedEntry); + assertNull("releasedEntry should be cleared after requeue processed", ((QueueContext)subscription2.getQueueContext())._releasedEntry); + } + + /** + * Tests a requeue for a queue with multiple subscriptions. Verifies that a + * subscriber specific requeue resends the message to <i>that</i> subscriber. + */ + public void testSubscriptionSpecificRequeueForQueueWithMultipleSubscriptions() throws Exception + { + MockSubscription subscription1 = new MockSubscription(); + MockSubscription subscription2 = new MockSubscription(); + + _queue.registerSubscription(subscription1, false); + _queue.registerSubscription(subscription2, false); + + final ArrayList<QueueEntry> queueEntries = new ArrayList<QueueEntry>(); + PostEnqueueAction postEnqueueAction = new PostEnqueueAction() + { + public void onEnqueue(QueueEntry entry) + { + queueEntries.add(entry); + } + }; + + AMQMessage messageA = createMessage(new Long(24)); + AMQMessage messageB = createMessage(new Long(25)); + + /* Enqueue two messages */ + + _queue.enqueue(messageA, postEnqueueAction); + _queue.enqueue(messageB, postEnqueueAction); + + Thread.sleep(150); // Work done by SubFlushRunner Thread + + assertEquals("Unexpected total number of messages sent to subscription1 after enqueue", 1, subscription1.getMessages().size()); + assertEquals("Unexpected total number of messages sent to subscription2 after enqueue", 1, subscription2.getMessages().size()); + + /* Now requeue a message (for first subscription) */ + + queueEntries.get(0).release(); + _queue.requeue((QueueEntryImpl)queueEntries.get(0), subscription1); + + Thread.sleep(150); // Work done by SubFlushRunner Thread + + assertEquals("Unexpected total number of messages sent to subscription1 after requeue", 2, subscription1.getMessages().size()); + assertEquals("Unexpected total number of messages sent to subscription2 after requeue", 1, subscription2.getMessages().size()); assertNull("releasedEntry should be cleared after requeue processed", ((QueueContext)subscription1.getQueueContext())._releasedEntry); assertNull("releasedEntry should be cleared after requeue processed", ((QueueContext)subscription2.getQueueContext())._releasedEntry); } @@ -611,8 +660,8 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase // Create IncomingMessage and nondurable queue final IncomingMessage msg = new IncomingMessage(info); ContentHeaderBody contentHeaderBody = new ContentHeaderBody(); - contentHeaderBody.setProperties(new BasicContentHeaderProperties()); - ((BasicContentHeaderProperties) contentHeaderBody.getProperties()).setDeliveryMode((byte) 2); + contentHeaderBody.properties = new BasicContentHeaderProperties(); + ((BasicContentHeaderProperties) contentHeaderBody.properties).setDeliveryMode((byte) 2); msg.setContentHeaderBody(contentHeaderBody); final ArrayList<BaseQueue> qs = new ArrayList<BaseQueue>(); @@ -658,635 +707,6 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase } - /** - * processQueue() is used when asynchronously delivering messages to - * subscriptions which could not be delivered immediately during the - * enqueue() operation. - * - * A defect within the method would mean that delivery of these messages may - * not occur should the Runner stop before all messages have been processed. - * Such a defect was discovered when Selectors were used such that one and - * only one subscription can/will accept any given messages, but multiple - * subscriptions are present, and one of the earlier subscriptions receives - * more messages than the others. - * - * This test is to validate that the processQueue() method is able to - * correctly deliver all of the messages present for asynchronous delivery - * to subscriptions in such a scenario. - */ - public void testProcessQueueWithUniqueSelectors() throws Exception - { - TestSimpleQueueEntryListFactory factory = new TestSimpleQueueEntryListFactory(); - SimpleAMQQueue testQueue = new SimpleAMQQueue("testQueue", false, "testOwner",false, - false, _virtualHost, factory, null) - { - @Override - public void deliverAsync(Subscription sub) - { - // do nothing, i.e prevent deliveries by the SubFlushRunner - // when registering the new subscriptions - } - }; - - // retrieve the QueueEntryList the queue creates and insert the test - // messages, thus avoiding straight-through delivery attempts during - //enqueue() process. - QueueEntryList list = factory.getQueueEntryList(); - assertNotNull("QueueEntryList should have been created", list); - - QueueEntry msg1 = list.add(createMessage(1L)); - QueueEntry msg2 = list.add(createMessage(2L)); - QueueEntry msg3 = list.add(createMessage(3L)); - QueueEntry msg4 = list.add(createMessage(4L)); - QueueEntry msg5 = list.add(createMessage(5L)); - - // Create lists of the entries each subscription should be interested - // in.Bias over 50% of the messages to the first subscription so that - // the later subscriptions reject them and report being done before - // the first subscription as the processQueue method proceeds. - List<QueueEntry> msgListSub1 = createEntriesList(msg1, msg2, msg3); - List<QueueEntry> msgListSub2 = createEntriesList(msg4); - List<QueueEntry> msgListSub3 = createEntriesList(msg5); - - MockSubscription sub1 = new MockSubscription(msgListSub1); - MockSubscription sub2 = new MockSubscription(msgListSub2); - MockSubscription sub3 = new MockSubscription(msgListSub3); - - // register the subscriptions - testQueue.registerSubscription(sub1, false); - testQueue.registerSubscription(sub2, false); - testQueue.registerSubscription(sub3, false); - - //check that no messages have been delivered to the - //subscriptions during registration - assertEquals("No messages should have been delivered yet", 0, sub1.getMessages().size()); - assertEquals("No messages should have been delivered yet", 0, sub2.getMessages().size()); - assertEquals("No messages should have been delivered yet", 0, sub3.getMessages().size()); - - // call processQueue to deliver the messages - testQueue.processQueue(new QueueRunner(testQueue, 1) - { - @Override - public void run() - { - // we dont actually want/need this runner to do any work - // because we we are already doing it! - } - }); - - // check expected messages delivered to correct consumers - verifyRecievedMessages(msgListSub1, sub1.getMessages()); - verifyRecievedMessages(msgListSub2, sub2.getMessages()); - verifyRecievedMessages(msgListSub3, sub3.getMessages()); - } - - /** - * Tests that dequeued message is not present in the list returned form - * {@link SimpleAMQQueue#getMessagesOnTheQueue()} - */ - public void testGetMessagesOnTheQueueWithDequeuedEntry() - { - int messageNumber = 4; - int dequeueMessageIndex = 1; - - // send test messages into a test queue - enqueueGivenNumberOfMessages(_queue, messageNumber); - - // dequeue message - dequeueMessage(_queue, dequeueMessageIndex); - - // get messages on the queue - List<QueueEntry> entries = _queue.getMessagesOnTheQueue(); - - // assert queue entries - assertEquals(messageNumber - 1, entries.size()); - int expectedId = 0; - for (int i = 0; i < messageNumber - 1; i++) - { - Long id = ((AMQMessage) entries.get(i).getMessage()).getMessageId(); - if (i == dequeueMessageIndex) - { - assertFalse("Message with id " + dequeueMessageIndex - + " was dequeued and should not be returned by method getMessagesOnTheQueue!", - new Long(expectedId).equals(id)); - expectedId++; - } - assertEquals("Expected message with id " + expectedId + " but got message with id " + id, - new Long(expectedId), id); - expectedId++; - } - } - - /** - * Tests that dequeued message is not present in the list returned form - * {@link SimpleAMQQueue#getMessagesOnTheQueue(QueueEntryFilter)} - */ - public void testGetMessagesOnTheQueueByQueueEntryFilterWithDequeuedEntry() - { - int messageNumber = 4; - int dequeueMessageIndex = 1; - - // send test messages into a test queue - enqueueGivenNumberOfMessages(_queue, messageNumber); - - // dequeue message - dequeueMessage(_queue, dequeueMessageIndex); - - // get messages on the queue with filter accepting all available messages - List<QueueEntry> entries = _queue.getMessagesOnTheQueue(new QueueEntryFilter() - { - public boolean accept(QueueEntry entry) - { - return true; - } - - public boolean filterComplete() - { - return false; - } - }); - - // assert entries on the queue - assertEquals(messageNumber - 1, entries.size()); - int expectedId = 0; - for (int i = 0; i < messageNumber - 1; i++) - { - Long id = ((AMQMessage) entries.get(i).getMessage()).getMessageId(); - if (i == dequeueMessageIndex) - { - assertFalse("Message with id " + dequeueMessageIndex - + " was dequeued and should not be returned by method getMessagesOnTheQueue!", - new Long(expectedId).equals(id)); - expectedId++; - } - assertEquals("Expected message with id " + expectedId + " but got message with id " + id, - new Long(expectedId), id); - expectedId++; - } - } - - /** - * Tests that dequeued message is not copied as part of invocation of - * {@link SimpleAMQQueue#copyMessagesToAnotherQueue(long, long, String, StoreContext)} - */ - public void testCopyMessagesWithDequeuedEntry() - { - int messageNumber = 4; - int dequeueMessageIndex = 1; - String anotherQueueName = "testQueue2"; - - // put test messages into a test queue - enqueueGivenNumberOfMessages(_queue, messageNumber); - - // dequeue message - dequeueMessage(_queue, dequeueMessageIndex); - - // create another queue - SimpleAMQQueue queue = createQueue(anotherQueueName); - - // create transaction - ServerTransaction txn = new LocalTransaction(_queue.getVirtualHost().getTransactionLog()); - - // copy messages into another queue - _queue.copyMessagesToAnotherQueue(0, messageNumber, anotherQueueName, txn); - - // commit transaction - txn.commit(); - - // get messages on another queue - List<QueueEntry> entries = queue.getMessagesOnTheQueue(); - - // assert another queue entries - assertEquals(messageNumber - 1, entries.size()); - int expectedId = 0; - for (int i = 0; i < messageNumber - 1; i++) - { - Long id = ((AMQMessage)entries.get(i).getMessage()).getMessageId(); - if (i == dequeueMessageIndex) - { - assertFalse("Message with id " + dequeueMessageIndex - + " was dequeued and should not been copied into another queue!", - new Long(expectedId).equals(id)); - expectedId++; - } - assertEquals("Expected message with id " + expectedId + " but got message with id " + id, - new Long(expectedId), id); - expectedId++; - } - } - - /** - * Tests that dequeued message is not moved as part of invocation of - * {@link SimpleAMQQueue#moveMessagesToAnotherQueue(long, long, String, StoreContext)} - */ - public void testMovedMessagesWithDequeuedEntry() - { - int messageNumber = 4; - int dequeueMessageIndex = 1; - String anotherQueueName = "testQueue2"; - - // put messages into a test queue - enqueueGivenNumberOfMessages(_queue, messageNumber); - - // dequeue message - dequeueMessage(_queue, dequeueMessageIndex); - - // create another queue - SimpleAMQQueue queue = createQueue(anotherQueueName); - - // create transaction - ServerTransaction txn = new LocalTransaction(_queue.getVirtualHost().getTransactionLog()); - - // move messages into another queue - _queue.moveMessagesToAnotherQueue(0, messageNumber, anotherQueueName, txn); - - // commit transaction - txn.commit(); - - // get messages on another queue - List<QueueEntry> entries = queue.getMessagesOnTheQueue(); - - // assert another queue entries - assertEquals(messageNumber - 1, entries.size()); - int expectedId = 0; - for (int i = 0; i < messageNumber - 1; i++) - { - Long id = ((AMQMessage)entries.get(i).getMessage()).getMessageId(); - if (i == dequeueMessageIndex) - { - assertFalse("Message with id " + dequeueMessageIndex - + " was dequeued and should not been copied into another queue!", - new Long(expectedId).equals(id)); - expectedId++; - } - assertEquals("Expected message with id " + expectedId + " but got message with id " + id, - new Long(expectedId), id); - expectedId++; - } - } - - /** - * Tests that messages in given range including dequeued one are deleted - * from the queue on invocation of - * {@link SimpleAMQQueue#removeMessagesFromQueue(long, long, StoreContext)} - */ - public void testRemoveMessagesFromQueueWithDequeuedEntry() - { - int messageNumber = 4; - int dequeueMessageIndex = 1; - - // put messages into a test queue - enqueueGivenNumberOfMessages(_queue, messageNumber); - - // dequeue message - dequeueMessage(_queue, dequeueMessageIndex); - - // remove messages - _queue.removeMessagesFromQueue(0, messageNumber); - - // get queue entries - List<QueueEntry> entries = _queue.getMessagesOnTheQueue(); - - // assert queue entries - assertNotNull("Null is returned from getMessagesOnTheQueue", entries); - assertEquals("Queue should be empty", 0, entries.size()); - } - - /** - * Tests that dequeued message on the top is not accounted and next message - * is deleted from the queue on invocation of - * {@link SimpleAMQQueue#deleteMessageFromTop(StoreContext)} - */ - public void testDeleteMessageFromTopWithDequeuedEntryOnTop() - { - int messageNumber = 4; - int dequeueMessageIndex = 0; - - // put messages into a test queue - enqueueGivenNumberOfMessages(_queue, messageNumber); - - // dequeue message on top - dequeueMessage(_queue, dequeueMessageIndex); - - //delete message from top - _queue.deleteMessageFromTop(); - - //get queue netries - List<QueueEntry> entries = _queue.getMessagesOnTheQueue(); - - // assert queue entries - assertNotNull("Null is returned from getMessagesOnTheQueue", entries); - assertEquals("Expected " + (messageNumber - 2) + " number of messages but recieved " + entries.size(), - messageNumber - 2, entries.size()); - assertEquals("Expected first entry with id 2", new Long(2), - ((AMQMessage) entries.get(0).getMessage()).getMessageId()); - } - - /** - * Tests that all messages including dequeued one are deleted from the queue - * on invocation of {@link SimpleAMQQueue#clearQueue(StoreContext)} - */ - public void testClearQueueWithDequeuedEntry() - { - int messageNumber = 4; - int dequeueMessageIndex = 1; - - // put messages into a test queue - enqueueGivenNumberOfMessages(_queue, messageNumber); - - // dequeue message on a test queue - dequeueMessage(_queue, dequeueMessageIndex); - - // clean queue - try - { - _queue.clearQueue(); - } - catch (AMQException e) - { - fail("Failure to clear queue:" + e.getMessage()); - } - - // get queue entries - List<QueueEntry> entries = _queue.getMessagesOnTheQueue(); - - // assert queue entries - assertNotNull(entries); - assertEquals(0, entries.size()); - } - - /** - * Tests whether dequeued entry is sent to subscriber in result of - * invocation of {@link SimpleAMQQueue#processQueue(QueueRunner)} - */ - public void testProcessQueueWithDequeuedEntry() - { - // total number of messages to send - int messageNumber = 4; - int dequeueMessageIndex = 1; - - // create queue with overridden method deliverAsync - SimpleAMQQueue testQueue = new SimpleAMQQueue(new AMQShortString("test"), false, - new AMQShortString("testOwner"), false, false, _virtualHost, null) - { - @Override - public void deliverAsync(Subscription sub) - { - // do nothing - } - }; - - // put messages - List<QueueEntry> entries = enqueueGivenNumberOfMessages(testQueue, messageNumber); - - // dequeue message - dequeueMessage(testQueue, dequeueMessageIndex); - - // latch to wait for message receipt - final CountDownLatch latch = new CountDownLatch(messageNumber -1); - - // create a subscription - MockSubscription subscription = new MockSubscription() - { - /** - * Send a message and decrement latch - */ - public void send(QueueEntry msg) throws AMQException - { - super.send(msg); - latch.countDown(); - } - }; - - try - { - // subscribe - testQueue.registerSubscription(subscription, false); - - // process queue - testQueue.processQueue(new QueueRunner(testQueue, 1) - { - public void run() - { - // do nothing - } - }); - } - catch (AMQException e) - { - fail("Failure to process queue:" + e.getMessage()); - } - // wait up to 1 minute for message receipt - try - { - latch.await(1, TimeUnit.MINUTES); - } - catch (InterruptedException e1) - { - Thread.currentThread().interrupt(); - } - List<QueueEntry> expected = createEntriesList(entries.get(0), entries.get(2), entries.get(3)); - verifyRecievedMessages(expected, subscription.getMessages()); - } - - /** - * Tests that entry in dequeued state are not enqueued and not delivered to subscription - */ - public void testEqueueDequeuedEntry() - { - // create a queue where each even entry is considered a dequeued - SimpleAMQQueue queue = new SimpleAMQQueue(new AMQShortString("test"), false, new AMQShortString("testOwner"), - false, false, _virtualHost, new QueueEntryListFactory() - { - public QueueEntryList createQueueEntryList(AMQQueue queue) - { - /** - * Override SimpleQueueEntryList to create a dequeued - * entries for messages with even id - */ - return new SimpleQueueEntryList(queue) - { - /** - * Entries with even message id are considered - * dequeued! - */ - protected QueueEntryImpl createQueueEntry(final ServerMessage message) - { - return new QueueEntryImpl(this, message) - { - public boolean isDequeued() - { - return (((AMQMessage) message).getMessageId().longValue() % 2 == 0); - } - - public boolean isDispensed() - { - return (((AMQMessage) message).getMessageId().longValue() % 2 == 0); - } - - public boolean isAvailable() - { - return !(((AMQMessage) message).getMessageId().longValue() % 2 == 0); - } - }; - } - }; - } - }, null); - // create a subscription - MockSubscription subscription = new MockSubscription(); - - // register subscription - try - { - queue.registerSubscription(subscription, false); - } - catch (AMQException e) - { - fail("Failure to register subscription:" + e.getMessage()); - } - - // put test messages into a queue - putGivenNumberOfMessages(queue, 4); - - // assert received messages - List<QueueEntry> messages = subscription.getMessages(); - assertEquals("Only 2 messages should be returned", 2, messages.size()); - assertEquals("ID of first message should be 1", new Long(1), - ((AMQMessage) messages.get(0).getMessage()).getMessageId()); - assertEquals("ID of second message should be 3", new Long(3), - ((AMQMessage) messages.get(1).getMessage()).getMessageId()); - } - - /** - * A helper method to create a queue with given name - * - * @param name - * queue name - * @return queue - */ - private SimpleAMQQueue createQueue(String name) - { - SimpleAMQQueue queue = null; - try - { - AMQShortString queueName = new AMQShortString(name); - AMQShortString ownerName = new AMQShortString(name + "Owner"); - queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(queueName, false, ownerName, false, false, - _virtualHost, _arguments); - } - catch (AMQException e) - { - fail("Failure to create a queue:" + e.getMessage()); - } - assertNotNull("Queue was not created", queue); - return queue; - } - - /** - * A helper method to put given number of messages into queue - * <p> - * All messages are asserted that they are present on queue - * - * @param queue - * queue to put messages into - * @param messageNumber - * number of messages to put into queue - */ - private List<QueueEntry> enqueueGivenNumberOfMessages(AMQQueue queue, int messageNumber) - { - putGivenNumberOfMessages(queue, messageNumber); - - // make sure that all enqueued messages are on the queue - List<QueueEntry> entries = queue.getMessagesOnTheQueue(); - assertEquals(messageNumber, entries.size()); - for (int i = 0; i < messageNumber; i++) - { - assertEquals(new Long(i), ((AMQMessage)entries.get(i).getMessage()).getMessageId()); - } - return entries; - } - - /** - * A helper method to put given number of messages into queue - * <p> - * Queue is not checked if messages are added into queue - * - * @param queue - * queue to put messages into - * @param messageNumber - * number of messages to put into queue - * @param queue - * @param messageNumber - */ - private void putGivenNumberOfMessages(AMQQueue queue, int messageNumber) - { - for (int i = 0; i < messageNumber; i++) - { - // Create message - Long messageId = new Long(i); - AMQMessage message = null; - try - { - message = createMessage(messageId); - } - catch (AMQException e) - { - fail("Failure to create a test message:" + e.getMessage()); - } - // Put message on queue - try - { - queue.enqueue(message); - } - catch (AMQException e) - { - fail("Failure to put message on queue:" + e.getMessage()); - } - } - } - - /** - * A helper method to dequeue an entry on queue with given index - * - * @param queue - * queue to dequeue message on - * @param dequeueMessageIndex - * entry index to dequeue. - */ - private QueueEntry dequeueMessage(AMQQueue queue, int dequeueMessageIndex) - { - List<QueueEntry> entries = queue.getMessagesOnTheQueue(); - QueueEntry entry = entries.get(dequeueMessageIndex); - entry.acquire(); - entry.dequeue(); - assertTrue(entry.isDequeued()); - return entry; - } - - private List<QueueEntry> createEntriesList(QueueEntry... entries) - { - ArrayList<QueueEntry> entriesList = new ArrayList<QueueEntry>(); - for (QueueEntry entry : entries) - { - entriesList.add(entry); - } - return entriesList; - } - - private void verifyRecievedMessages(List<QueueEntry> expected, - List<QueueEntry> delivered) - { - assertEquals("Consumer did not receive the expected number of messages", - expected.size(), delivered.size()); - - for (QueueEntry msg : expected) - { - assertTrue("Consumer did not recieve msg: " - + msg.getMessage().getMessageNumber(), delivered.contains(msg)); - } - } - public class TestMessage extends AMQMessage { private final long _tag; @@ -1327,20 +747,4 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase AMQMessage messageA = new TestMessage(id, id, info); return messageA; } - - class TestSimpleQueueEntryListFactory implements QueueEntryListFactory - { - QueueEntryList _list; - - public QueueEntryList createQueueEntryList(AMQQueue queue) - { - _list = new SimpleQueueEntryList(queue); - return _list; - } - - public QueueEntryList getQueueEntryList() - { - return _list; - } - } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleQueueEntryListTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleQueueEntryListTest.java index 7136f07ca5..320a75045a 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleQueueEntryListTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleQueueEntryListTest.java @@ -23,7 +23,6 @@ package org.apache.qpid.server.queue; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.qpid.AMQException; import org.apache.qpid.server.message.AMQMessage; import junit.framework.TestCase; @@ -156,55 +155,5 @@ public class SimpleQueueEntryListTest extends TestCase assertEquals("Count should have been equal",count,remainingMessages.size()); } - - public void testDequedMessagedNotPresentInIterator() - { - int numberOfMessages = 10; - SimpleQueueEntryList entryList = new SimpleQueueEntryList(new MockAMQQueue("test")); - QueueEntry[] entries = new QueueEntry[numberOfMessages]; - - for(int i = 0; i < numberOfMessages ; i++) - { - AMQMessage message = null;; - try - { - message = new MockAMQMessage(i); - } - catch (AMQException e) - { - fail("Failure to create a mock message:" + e.getMessage()); - } - QueueEntry entry = entryList.add(message); - assertNotNull("QE should not be null", entry); - entries[i]= entry; - } - - // dequeue all even messages - for (QueueEntry queueEntry : entries) - { - long i = ((AMQMessage)queueEntry.getMessage()).getMessageId().longValue(); - if (i%2 == 0) - { - queueEntry.acquire(); - queueEntry.dequeue(); - } - } - - // iterate and check that dequeued messages are not returned by iterator - QueueEntryIterator it = entryList.iterator(); - int counter = 0; - int i = 1; - while (it.advance()) - { - QueueEntry entry = it.getNode(); - Long id = ((AMQMessage)entry.getMessage()).getMessageId(); - assertEquals("Expected message with id " + i + " but got message with id " - + id, new Long(i), id); - counter++; - i += 2; - } - int expectedNumber = numberOfMessages / 2; - assertEquals("Expected " + expectedNumber + " number of entries in iterator but got " + counter, - expectedNumber, counter); - } + } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java deleted file mode 100644 index b10442d7db..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java +++ /dev/null @@ -1,358 +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 - * - * 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.qpid.server.security.auth.manager; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.security.Provider; -import java.security.Security; - -import javax.security.auth.Subject; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.XMLConfiguration; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; -import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; -import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal; -import org.apache.qpid.server.util.InternalBrokerBaseCase; - -/** - * - * Tests the public methods of PrincipalDatabaseAuthenticationManager. - * - */ -public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBaseCase -{ - private AuthenticationManager _manager = null; // Class under test - private String TEST_USERNAME = "guest"; - private String TEST_PASSWORD = "guest"; - - /** - * @see org.apache.qpid.server.util.InternalBrokerBaseCase#tearDown() - */ - @Override - public void tearDown() throws Exception - { - super.tearDown(); - if (_manager != null) - { - _manager.close(); - } - } - - /** - * @see org.apache.qpid.server.util.InternalBrokerBaseCase#setUp() - */ - @Override - public void setUp() throws Exception - { - super.setUp(); - - final String passwdFilename = createPasswordFile().getCanonicalPath(); - final ConfigurationPlugin config = getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), - "passwordFile", passwdFilename); - - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(config); - } - - /** - * Tests where the case where the config specifies a PD implementation - * that is not found. - */ - public void testPrincipalDatabaseImplementationNotFound() throws Exception - { - try - { - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig("not.Found", null, null)); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - // PASS - } - } - - /** - * Tests where the case where the config specifies a PD implementation - * of the wrong type. - */ - public void testPrincipalDatabaseImplementationWrongType() throws Exception - { - try - { - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(String.class.getName(), null, null)); // Not a PrincipalDatabase implementation - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - // PASS - } - } - - /** - * Tests the case where a setter with the desired name cannot be found. - */ - public void testPrincipalDatabaseSetterNotFound() throws Exception - { - try - { - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "noMethod", "test")); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - // PASS - } - } - - /** - * QPID-1347. Make sure the exception message and stack trace is reasonable for an absent password file. - */ - public void testPrincipalDatabaseThrowsSetterFileNotFound() throws Exception - { - try - { - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "passwordFile", "/not/found")); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - // PASS - assertNotNull("Expected an underlying cause", ce.getCause()); - assertEquals(FileNotFoundException.class, ce.getCause().getClass()); - } - } - - /** - * Tests that the PDAM registers SASL mechanisms correctly with the runtime. - */ - public void testRegisteredMechanisms() throws Exception - { - assertNotNull(_manager.getMechanisms()); - // relies on those mechanisms attached to PropertiesPrincipalDatabaseManager - assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms()); - - Provider qpidProvider = Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME); - assertNotNull(qpidProvider); - } - - /** - * Tests that the SASL factory method createSaslServer correctly - * returns a non-null implementation. - */ - public void testSaslMechanismCreation() throws Exception - { - SaslServer server = _manager.createSaslServer("CRAM-MD5", "localhost"); - assertNotNull(server); - // Merely tests the creation of the mechanism. Mechanisms themselves are tested - // by their own tests. - } - - /** - * Tests that the authenticate method correctly interprets an - * authentication success. - * - */ - public void testSaslAuthenticationSuccess() throws Exception - { - SaslServer testServer = createTestSaslServer(true, false); - - AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes()); - final Subject subject = result.getSubject(); - assertTrue(subject.getPrincipals().contains(new UsernamePrincipal("guest"))); - assertEquals(AuthenticationStatus.SUCCESS, result.getStatus()); - } - - /** - * - * Tests that the authenticate method correctly interprets an - * authentication not complete. - * - */ - public void testSaslAuthenticationNotCompleted() throws Exception - { - SaslServer testServer = createTestSaslServer(false, false); - - AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes()); - assertNull(result.getSubject()); - assertEquals(AuthenticationStatus.CONTINUE, result.getStatus()); - } - - /** - * - * Tests that the authenticate method correctly interprets an - * authentication error. - * - */ - public void testSaslAuthenticationError() throws Exception - { - SaslServer testServer = createTestSaslServer(false, true); - - AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes()); - assertNull(result.getSubject()); - assertEquals(AuthenticationStatus.ERROR, result.getStatus()); - } - - /** - * Tests that the authenticate method correctly interprets an - * authentication success. - * - */ - public void testNonSaslAuthenticationSuccess() throws Exception - { - AuthenticationResult result = _manager.authenticate("guest", "guest"); - final Subject subject = result.getSubject(); - assertFalse("Subject should not be set read-only", subject.isReadOnly()); - assertTrue(subject.getPrincipals().contains(new UsernamePrincipal("guest"))); - assertEquals(AuthenticationStatus.SUCCESS, result.getStatus()); - } - - /** - * Tests that the authenticate method correctly interprets an - * authentication success. - * - */ - public void testNonSaslAuthenticationNotCompleted() throws Exception - { - AuthenticationResult result = _manager.authenticate("guest", "wrongpassword"); - assertNull(result.getSubject()); - assertEquals(AuthenticationStatus.CONTINUE, result.getStatus()); - } - - /** - * Tests the ability to de-register the provider. - */ - public void testClose() throws Exception - { - assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms()); - assertNotNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME)); - - _manager.close(); - - // Check provider has been removed. - assertNull(_manager.getMechanisms()); - assertNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME)); - _manager = null; - } - - /** - * Test SASL implementation used to test the authenticate() method. - */ - private SaslServer createTestSaslServer(final boolean complete, final boolean throwSaslException) - { - return new SaslServer() - { - public String getMechanismName() - { - return null; - } - - public byte[] evaluateResponse(byte[] response) throws SaslException - { - if (throwSaslException) - { - throw new SaslException("Mocked exception"); - } - return null; - } - - public boolean isComplete() - { - return complete; - } - - public String getAuthorizationID() - { - return complete ? "guest" : null; - } - - public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException - { - return null; - } - - public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException - { - return null; - } - - public Object getNegotiatedProperty(String propName) - { - return null; - } - - public void dispose() throws SaslException - { - } - }; - } - - private ConfigurationPlugin getConfig(final String clazz, final String argName, final String argValue) throws Exception - { - final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration(); - - XMLConfiguration xmlconfig = new XMLConfiguration(); - xmlconfig.addProperty("pd-auth-manager.principal-database.class", clazz); - - if (argName != null) - { - xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.name", argName); - xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.value", argValue); - } - - // Create a CompositeConfiguration as this is what the broker uses - CompositeConfiguration composite = new CompositeConfiguration(); - composite.addConfiguration(xmlconfig); - config.setConfiguration("security", xmlconfig); - return config; - } - - private File createPasswordFile() throws Exception - { - BufferedWriter writer = null; - try - { - File testFile = File.createTempFile(this.getClass().getName(),"tmp"); - testFile.deleteOnExit(); - - writer = new BufferedWriter(new FileWriter(testFile)); - writer.write(TEST_USERNAME + ":" + TEST_PASSWORD); - writer.newLine(); - - return testFile; - - } - finally - { - if (writer != null) - { - writer.close(); - } - } - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java index 6dc7b19d3d..e8c24da68d 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java @@ -20,125 +20,188 @@ */ package org.apache.qpid.server.security.auth.rmi; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.Collections; import javax.management.remote.JMXPrincipal; import javax.security.auth.Subject; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import junit.framework.TestCase; +import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase; +import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; +import junit.framework.TestCase; -/** - * Tests the RMIPasswordAuthenticator and its collaboration with the AuthenticationManager. - * - */ public class RMIPasswordAuthenticatorTest extends TestCase { private final String USERNAME = "guest"; private final String PASSWORD = "guest"; + private final String B64_MD5HASHED_PASSWORD = "CE4DQ6BIb/BVMN9scFyLtA=="; private RMIPasswordAuthenticator _rmipa; - private String[] _credentials; + + private Base64MD5PasswordFilePrincipalDatabase _md5Pd; + private File _md5PwdFile; + + private PlainPasswordFilePrincipalDatabase _plainPd; + private File _plainPwdFile; + + private Subject testSubject; protected void setUp() throws Exception { _rmipa = new RMIPasswordAuthenticator(); - _credentials = new String[] {USERNAME, PASSWORD}; - } - - /** - * Tests a successful authentication. Ensures that a populated read-only subject it returned. - */ - public void testAuthenticationSuccess() - { - final Subject expectedSubject = new Subject(true, + _md5Pd = new Base64MD5PasswordFilePrincipalDatabase(); + _md5PwdFile = createTempPasswordFile(this.getClass().getName()+"md5pwd", USERNAME, B64_MD5HASHED_PASSWORD); + _md5Pd.setPasswordFile(_md5PwdFile.getAbsolutePath()); + + _plainPd = new PlainPasswordFilePrincipalDatabase(); + _plainPwdFile = createTempPasswordFile(this.getClass().getName()+"plainpwd", USERNAME, PASSWORD); + _plainPd.setPasswordFile(_plainPwdFile.getAbsolutePath()); + + testSubject = new Subject(true, Collections.singleton(new JMXPrincipal(USERNAME)), Collections.EMPTY_SET, Collections.EMPTY_SET); + } + + private File createTempPasswordFile(String filenamePrefix, String user, String password) + { + try + { + File testFile = File.createTempFile(filenamePrefix,"tmp"); + testFile.deleteOnExit(); + + BufferedWriter writer = new BufferedWriter(new FileWriter(testFile)); - _rmipa.setAuthenticationManager(createTestAuthenticationManager(true, null)); + writer.write(user + ":" + password); + writer.newLine(); + writer.flush(); + writer.close(); - Subject newSubject = _rmipa.authenticate(_credentials); - assertTrue("Subject must be readonly", newSubject.isReadOnly()); - assertTrue("Returned subject does not equal expected value", - newSubject.equals(expectedSubject)); + return testFile; + } + catch (IOException e) + { + fail("Unable to create temporary test password file." + e.getMessage()); + } + return null; } + + + //********** Test Methods *********// + - /** - * Tests a unsuccessful authentication. - */ - public void testUsernameOrPasswordInvalid() + public void testAuthenticate() { - _rmipa.setAuthenticationManager(createTestAuthenticationManager(false, null)); - + String[] credentials; + Subject newSubject; + + // Test when no PD has been set try { - _rmipa.authenticate(_credentials); - fail("Exception not thrown"); + credentials = new String[]{USERNAME, PASSWORD}; + newSubject = _rmipa.authenticate(credentials); + fail("SecurityException expected due to lack of principal database"); } catch (SecurityException se) { assertEquals("Unexpected exception message", - RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage()); - + RMIPasswordAuthenticator.UNABLE_TO_LOOKUP, se.getMessage()); } - } - /** - * Tests case where authentication system itself fails. - */ - public void testAuthenticationFailure() - { - final Exception mockAuthException = new Exception("Mock Auth system failure"); - _rmipa.setAuthenticationManager(createTestAuthenticationManager(false, mockAuthException)); + //The PrincipalDatabase's are tested primarily by their own tests, but + //minimal tests are done here to exercise their usage in this area. + + // Test correct passwords are verified with an MD5 PD + try + { + _rmipa.setPrincipalDatabase(_md5Pd); + credentials = new String[]{USERNAME, PASSWORD}; + newSubject = _rmipa.authenticate(credentials); + assertTrue("Returned subject does not equal expected value", + newSubject.equals(testSubject)); + } + catch (Exception e) + { + fail("Unexpected Exception:" + e.getMessage()); + } + // Test incorrect passwords are not verified with an MD5 PD try { - _rmipa.authenticate(_credentials); - fail("Exception not thrown"); + credentials = new String[]{USERNAME, PASSWORD+"incorrect"}; + newSubject = _rmipa.authenticate(credentials); + fail("SecurityException expected due to incorrect password"); } catch (SecurityException se) { - assertEquals("Initial cause not found", mockAuthException, se.getCause()); + assertEquals("Unexpected exception message", + RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage()); + } + + // Test non-existent accounts are not verified with an MD5 PD + try + { + credentials = new String[]{USERNAME+"invalid", PASSWORD}; + newSubject = _rmipa.authenticate(credentials); + fail("SecurityException expected due to non-existant account"); + } + catch (SecurityException se) + { + assertEquals("Unexpected exception message", + RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage()); } - } + // Test correct passwords are verified with a Plain PD + try + { + _rmipa.setPrincipalDatabase(_plainPd); + credentials = new String[]{USERNAME, PASSWORD}; + newSubject = _rmipa.authenticate(credentials); + assertTrue("Returned subject does not equal expected value", + newSubject.equals(testSubject)); + } + catch (Exception e) + { + fail("Unexpected Exception"); + } - /** - * Tests case where authentication manager is not set. - */ - public void testNullAuthenticationManager() - { + // Test incorrect passwords are not verified with a Plain PD try { - _rmipa.authenticate(_credentials); - fail("SecurityException expected due to lack of authentication manager"); + credentials = new String[]{USERNAME, PASSWORD+"incorrect"}; + newSubject = _rmipa.authenticate(credentials); + fail("SecurityException expected due to incorrect password"); } catch (SecurityException se) { assertEquals("Unexpected exception message", - RMIPasswordAuthenticator.UNABLE_TO_LOOKUP, se.getMessage()); + RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage()); + } + + // Test non-existent accounts are not verified with an Plain PD + try + { + credentials = new String[]{USERNAME+"invalid", PASSWORD}; + newSubject = _rmipa.authenticate(credentials); + fail("SecurityException expected due to non existant account"); + } + catch (SecurityException se) + { + assertEquals("Unexpected exception message", + RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage()); } - } - /** - * Tests case where arguments are non-Strings.. - */ - public void testWithNonStringArrayArgument() - { // Test handling of non-string credential's - final Object[] objCredentials = new Object[]{USERNAME, PASSWORD}; try { - _rmipa.authenticate(objCredentials); + Object[] objCredentials = new Object[]{USERNAME, PASSWORD}; + newSubject = _rmipa.authenticate(objCredentials); fail("SecurityException expected due to non string[] credentials"); } catch (SecurityException se) @@ -146,18 +209,12 @@ public class RMIPasswordAuthenticatorTest extends TestCase assertEquals("Unexpected exception message", RMIPasswordAuthenticator.SHOULD_BE_STRING_ARRAY, se.getMessage()); } - } - - /** - * Tests case where there are too many, too few or null arguments. - */ - public void testWithIllegalNumberOfArguments() - { - // Test handling of incorrect number of credentials + + // Test handling of incorrect number of credential's try { - _credentials = new String[]{USERNAME, PASSWORD, PASSWORD}; - _rmipa.authenticate(_credentials); + credentials = new String[]{USERNAME, PASSWORD, PASSWORD}; + newSubject = _rmipa.authenticate(credentials); fail("SecurityException expected due to supplying wrong number of credentials"); } catch (SecurityException se) @@ -166,12 +223,12 @@ public class RMIPasswordAuthenticatorTest extends TestCase RMIPasswordAuthenticator.SHOULD_HAVE_2_ELEMENTS, se.getMessage()); } - // Test handling of null credentials + // Test handling of null credential's try { //send a null array - _credentials = null; - _rmipa.authenticate(_credentials); + credentials = null; + newSubject = _rmipa.authenticate(credentials); fail("SecurityException expected due to not supplying an array of credentials"); } catch (SecurityException se) @@ -183,8 +240,8 @@ public class RMIPasswordAuthenticatorTest extends TestCase try { //send a null password - _credentials = new String[]{USERNAME, null}; - _rmipa.authenticate(_credentials); + credentials = new String[]{USERNAME, null}; + newSubject = _rmipa.authenticate(credentials); fail("SecurityException expected due to sending a null password"); } catch (SecurityException se) @@ -196,8 +253,8 @@ public class RMIPasswordAuthenticatorTest extends TestCase try { //send a null username - _credentials = new String[]{null, PASSWORD}; - _rmipa.authenticate(_credentials); + credentials = new String[]{null, PASSWORD}; + newSubject = _rmipa.authenticate(credentials); fail("SecurityException expected due to sending a null username"); } catch (SecurityException se) @@ -207,54 +264,4 @@ public class RMIPasswordAuthenticatorTest extends TestCase } } - private AuthenticationManager createTestAuthenticationManager(final boolean successfulAuth, final Exception exception) - { - return new AuthenticationManager() - { - public void configure(ConfigurationPlugin config) - { - throw new UnsupportedOperationException(); - } - - public void initialise() - { - throw new UnsupportedOperationException(); - } - - public void close() - { - throw new UnsupportedOperationException(); - } - - public String getMechanisms() - { - throw new UnsupportedOperationException(); - } - - public SaslServer createSaslServer(String mechanism, String localFQDN) throws SaslException - { - throw new UnsupportedOperationException(); - } - - public AuthenticationResult authenticate(SaslServer server, byte[] response) - { - throw new UnsupportedOperationException(); - } - - public AuthenticationResult authenticate(String username, String password) - { - if (exception != null) { - return new AuthenticationResult(AuthenticationStatus.ERROR, exception); - } - else if (successfulAuth) - { - return new AuthenticationResult(new Subject()); - } - else - { - return new AuthenticationResult(AuthenticationStatus.CONTINUE); - } - } - }; - } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java deleted file mode 100644 index 86e4e23750..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java +++ /dev/null @@ -1,228 +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 - * - * 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.qpid.server.security.auth.sasl; - -import java.io.File; -import java.io.IOException; -import java.security.MessageDigest; -import java.security.Principal; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; -import javax.security.auth.login.AccountNotFoundException; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import junit.framework.TestCase; - -import org.apache.commons.codec.binary.Hex; -import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5HexInitialiser; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5HexSaslServer; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5HexServerFactory; - -/** - * Test for the CRAM-MD5-HEX SASL mechanism. - * - * This test case focuses on testing {@link CRAMMD5HexSaslServer} but also exercises - * collaborators {@link CRAMMD5HexInitialiser} and {@link Base64MD5PasswordFilePrincipalDatabase} - */ -public class CRAMMD5HexServerTest extends TestCase -{ - - private SaslServer _saslServer; // Class under test - private CRAMMD5HexServerFactory _saslFactory; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - CRAMMD5HexInitialiser _initializer = new CRAMMD5HexInitialiser(); - - //Use properties to create a PrincipalDatabase - Base64MD5PasswordFilePrincipalDatabase db = createTestPrincipalDatabase(); - assertEquals("Unexpected number of test users in the db", 2, db.getUsers().size()); - - _initializer.initialise(db); - - _saslFactory = new CRAMMD5HexServerFactory(); - - _saslServer = _saslFactory.createSaslServer(CRAMMD5HexSaslServer.MECHANISM, - "AMQP", - "localhost", - _initializer.getProperties(), - _initializer.getCallbackHandler()); - assertNotNull("Unable to create saslServer with mechanism type " + CRAMMD5HexSaslServer.MECHANISM, _saslServer); - - } - - public void testSuccessfulAuth() throws Exception - { - - final byte[] serverChallenge = _saslServer.evaluateResponse(new byte[0]); - - // Generate client response - final byte[] clientResponse = generateClientResponse("knownuser", "guest", serverChallenge); - - - byte[] nextServerChallenge = _saslServer.evaluateResponse(clientResponse); - assertTrue("Exchange must be flagged as complete after successful authentication", _saslServer.isComplete()); - assertNull("Next server challenge must be null after successful authentication", nextServerChallenge); - - } - - public void testKnownUserPresentsWrongPassword() throws Exception - { - byte[] serverChallenge = _saslServer.evaluateResponse(new byte[0]); - - - final byte[] clientResponse = generateClientResponse("knownuser", "wrong!", serverChallenge); - try - { - _saslServer.evaluateResponse(clientResponse); - fail("Exception not thrown"); - } - catch (SaslException se) - { - // PASS - } - assertFalse("Exchange must not be flagged as complete after unsuccessful authentication", _saslServer.isComplete()); - } - - public void testUnknownUser() throws Exception - { - final byte[] serverChallenge = _saslServer.evaluateResponse(new byte[0]); - - - final byte[] clientResponse = generateClientResponse("unknownuser", "guest", serverChallenge); - - try - { - _saslServer.evaluateResponse(clientResponse); - fail("Exception not thrown"); - } - catch (SaslException se) - { - assertExceptionHasUnderlyingAsCause(AccountNotFoundException.class, se); - // PASS - } - assertFalse("Exchange must not be flagged as complete after unsuccessful authentication", _saslServer.isComplete()); - } - - /** - * - * Demonstrates QPID-3158. A defect meant that users with some valid password were failing to - * authenticate when using the .NET 0-8 client (uses this SASL mechanism). - * It so happens that password "guest2" was one of the affected passwords. - * - * @throws Exception - */ - public void testSuccessfulAuthReproducingQpid3158() throws Exception - { - byte[] serverChallenge = _saslServer.evaluateResponse(new byte[0]); - - // Generate client response - byte[] resp = generateClientResponse("qpid3158user", "guest2", serverChallenge); - - byte[] nextServerChallenge = _saslServer.evaluateResponse(resp); - assertTrue("Exchange must be flagged as complete after successful authentication", _saslServer.isComplete()); - assertNull("Next server challenge must be null after successful authentication", nextServerChallenge); - } - - /** - * Since we don't have a CRAM-MD5-HEX implementation client implementation in Java, this method - * provides the implementation for first principals. - * - * @param userId user id - * @param clearTextPassword clear text password - * @param serverChallenge challenge from server - * - * @return challenge response - */ - private byte[] generateClientResponse(final String userId, final String clearTextPassword, final byte[] serverChallenge) throws Exception - { - byte[] digestedPasswordBytes = MessageDigest.getInstance("MD5").digest(clearTextPassword.getBytes()); - char[] hexEncodedDigestedPassword = Hex.encodeHex(digestedPasswordBytes); - byte[] hexEncodedDigestedPasswordBytes = new String(hexEncodedDigestedPassword).getBytes(); - - - Mac hmacMd5 = Mac.getInstance("HmacMD5"); - hmacMd5.init(new SecretKeySpec(hexEncodedDigestedPasswordBytes, "HmacMD5")); - final byte[] messageAuthenticationCode = hmacMd5.doFinal(serverChallenge); - - // Build client response - String responseAsString = userId + " " + new String(Hex.encodeHex(messageAuthenticationCode)); - byte[] resp = responseAsString.getBytes(); - return resp; - } - - /** - * Creates a test principal database. - * - * @return - * @throws IOException - */ - private Base64MD5PasswordFilePrincipalDatabase createTestPrincipalDatabase() throws IOException - { - Base64MD5PasswordFilePrincipalDatabase db = new Base64MD5PasswordFilePrincipalDatabase(); - File file = File.createTempFile("passwd", "db"); - file.deleteOnExit(); - db.setPasswordFile(file.getCanonicalPath()); - db.createPrincipal( createTestPrincipal("knownuser"), "guest".toCharArray()); - db.createPrincipal( createTestPrincipal("qpid3158user"), "guest2".toCharArray()); - return db; - } - - private Principal createTestPrincipal(final String name) - { - return new Principal() - { - public String getName() - { - return name; - } - }; - } - - private void assertExceptionHasUnderlyingAsCause(final Class<? extends Throwable> expectedUnderlying, Throwable e) - { - assertNotNull(e); - int infiniteLoopGuard = 0; // Guard against loops in the cause chain - boolean foundExpectedUnderlying = false; - while (e.getCause() != null && infiniteLoopGuard++ < 10) - { - if (expectedUnderlying.equals(e.getCause().getClass())) - { - foundExpectedUnderlying = true; - break; - } - e = e.getCause(); - } - - if (!foundExpectedUnderlying) - { - fail("Not found expected underlying exception " + expectedUnderlying + " as underlying cause of " + e.getClass()); - } - } - -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipalTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipalTest.java deleted file mode 100644 index 076b7c9248..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipalTest.java +++ /dev/null @@ -1,86 +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 - * - * 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.qpid.server.security.auth.sasl; - -import junit.framework.TestCase; - -public class GroupPrincipalTest extends TestCase -{ - public void testGetName() - { - final GroupPrincipal principal = new GroupPrincipal("group"); - assertEquals("group", principal.getName()); - } - - public void testAddRejected() - { - final GroupPrincipal principal = new GroupPrincipal("group"); - final UsernamePrincipal user = new UsernamePrincipal("name"); - - try - { - principal.addMember(user); - fail("Exception not thrown"); - } - catch (UnsupportedOperationException uso) - { - // PASS - } - } - - public void testEqualitySameName() - { - final String string = "string"; - final GroupPrincipal principal1 = new GroupPrincipal(string); - final GroupPrincipal principal2 = new GroupPrincipal(string); - assertTrue(principal1.equals(principal2)); - } - - public void testEqualityEqualName() - { - final GroupPrincipal principal1 = new GroupPrincipal(new String("string")); - final GroupPrincipal principal2 = new GroupPrincipal(new String("string")); - assertTrue(principal1.equals(principal2)); - } - - public void testInequalityDifferentGroupPrincipals() - { - GroupPrincipal principal1 = new GroupPrincipal("string1"); - GroupPrincipal principal2 = new GroupPrincipal("string2"); - assertFalse(principal1.equals(principal2)); - } - - public void testInequalityNonGroupPrincipal() - { - GroupPrincipal principal = new GroupPrincipal("string"); - assertFalse(principal.equals(new UsernamePrincipal("string"))); - } - - public void testInequalityNull() - { - GroupPrincipal principal = new GroupPrincipal("string"); - assertFalse(principal.equals(null)); - } - - - - -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalUtils.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalUtils.java deleted file mode 100644 index 8b9b2df5a3..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalUtils.java +++ /dev/null @@ -1,49 +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 - * - * 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.qpid.server.security.auth.sasl; - -import java.security.Principal; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import javax.security.auth.Subject; - -public class TestPrincipalUtils -{ - - /** - * Creates a test subject, with exactly one UsernamePrincipal and zero or more GroupPrincipals. - */ - public static Subject createTestSubject(final String username, final String... groups) - { - final Set<Principal> principals = new HashSet<Principal>(1 + groups.length); - principals.add(new UsernamePrincipal(username)); - for (String group : groups) - { - principals.add(new GroupPrincipal(group)); - } - - final Subject subject = new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET); - return subject; - } - -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java deleted file mode 100644 index 541f14d923..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java +++ /dev/null @@ -1,122 +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 - * - * 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.qpid.server.security.auth.sasl; - -import java.security.Principal; -import javax.security.auth.Subject; -import junit.framework.TestCase; - -/** - * Tests the UsernamePrincipal. - * - */ -public class UsernamePrincipalTest extends TestCase -{ - public void testEqualitySameObject() - { - final UsernamePrincipal principal = new UsernamePrincipal("string"); - assertTrue(principal.equals(principal)); - } - - public void testEqualitySameName() - { - final String string = "string"; - final UsernamePrincipal principal1 = new UsernamePrincipal(string); - final UsernamePrincipal principal2 = new UsernamePrincipal(string); - assertTrue(principal1.equals(principal2)); - } - - public void testEqualityEqualName() - { - final UsernamePrincipal principal1 = new UsernamePrincipal(new String("string")); - final UsernamePrincipal principal2 = new UsernamePrincipal(new String("string")); - assertTrue(principal1.equals(principal2)); - } - - public void testInequalityDifferentUserPrincipals() - { - UsernamePrincipal principal1 = new UsernamePrincipal("string1"); - UsernamePrincipal principal2 = new UsernamePrincipal("string2"); - assertFalse(principal1.equals(principal2)); - } - - public void testInequalityNonUserPrincipal() - { - UsernamePrincipal principal = new UsernamePrincipal("string"); - assertFalse(principal.equals(new String("string"))); - } - - public void testInequalityNull() - { - UsernamePrincipal principal = new UsernamePrincipal("string"); - assertFalse(principal.equals(null)); - } - - public void testGetUsernamePrincipalFromSubject() - { - final UsernamePrincipal expected = new UsernamePrincipal("name"); - final Principal other = new Principal() - { - public String getName() - { - return "otherprincipal"; - } - }; - - final Subject subject = new Subject(); - subject.getPrincipals().add(expected); - subject.getPrincipals().add(other); - - final UsernamePrincipal actual = UsernamePrincipal.getUsernamePrincipalFromSubject(subject); - assertSame(expected, actual); - } - - public void testUsernamePrincipalNotInSubject() - { - try - { - UsernamePrincipal.getUsernamePrincipalFromSubject(new Subject()); - fail("Exception not thrown"); - } - catch (IllegalArgumentException iae) - { - // PASS - } - } - - public void testTooManyUsernamePrincipalInSubject() - { - final Subject subject = new Subject(); - subject.getPrincipals().add(new UsernamePrincipal("name1")); - subject.getPrincipals().add(new UsernamePrincipal("name2")); - try - { - - UsernamePrincipal.getUsernamePrincipalFromSubject(subject); - fail("Exception not thrown"); - } - catch (IllegalArgumentException iae) - { - // PASS - } - } - -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/stats/StatisticsCounterTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/stats/StatisticsCounterTest.java deleted file mode 100644 index fbaa1342c9..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/stats/StatisticsCounterTest.java +++ /dev/null @@ -1,144 +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 - * - * 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.qpid.server.stats; - -import junit.framework.TestCase; - -/** - * Unit tests for the {@link StatisticsCounter} class. - */ -public class StatisticsCounterTest extends TestCase -{ - /** - * Check that statistics counters are created correctly. - */ - public void testCreate() - { - long before = System.currentTimeMillis(); - StatisticsCounter counter = new StatisticsCounter("name", 1234L); - long after = System.currentTimeMillis(); - - assertTrue(before <= counter.getStart()); - assertTrue(after >= counter.getStart()); - assertTrue(counter.getName().startsWith("name-")); - assertEquals(1234L, counter.getPeriod()); - } - - /** - * Check that totals add up correctly. - */ - public void testTotal() - { - StatisticsCounter counter = new StatisticsCounter("test", 1000L); - long start = counter.getStart(); - for (int i = 0; i < 100; i++) - { - counter.registerEvent(i, start + i); - } - assertEquals(99 * 50, counter.getTotal()); // cf. Gauss - } - - /** - * Test totals add up correctly even when messages are delivered - * out-of-order. - */ - public void testTotalOutOfOrder() - { - StatisticsCounter counter = new StatisticsCounter("test", 1000L); - long start = counter.getStart(); - assertEquals(0, counter.getTotal()); - counter.registerEvent(10, start + 2500); - assertEquals(10, counter.getTotal()); - counter.registerEvent(20, start + 1500); - assertEquals(30, counter.getTotal()); - counter.registerEvent(10, start + 500); - assertEquals(40, counter.getTotal()); - } - - /** - * Test that the peak rate is reported correctly. - */ - public void testPeak() throws Exception - { - StatisticsCounter counter = new StatisticsCounter("test", 1000L); - long start = counter.getStart(); - assertEquals(0.0, counter.getPeak()); - Thread.sleep(500); - counter.registerEvent(1000, start + 500); - Thread.sleep(1000); - assertEquals(1000.0, counter.getPeak()); - counter.registerEvent(2000, start + 1500); - Thread.sleep(1000); - assertEquals(2000.0, counter.getPeak()); - counter.registerEvent(1000, start + 2500); - Thread.sleep(1000); - assertEquals(2000.0, counter.getPeak()); - } - - /** - * Test that peak rate is reported correctly for out-of-order messages, - * and the total is also unaffected. - */ - public void testPeakOutOfOrder() throws Exception - { - StatisticsCounter counter = new StatisticsCounter("test", 1000L); - long start = counter.getStart(); - assertEquals(0.0, counter.getPeak()); - counter.registerEvent(1000, start + 2500); - Thread.sleep(1500); - assertEquals(0.0, counter.getPeak()); - counter.registerEvent(2000, start + 1500); - Thread.sleep(1000L); - assertEquals(0.0, counter.getPeak()); - counter.registerEvent(1000, start + 500); - Thread.sleep(1500); - assertEquals(4000.0, counter.getPeak()); - Thread.sleep(2000); - assertEquals(4000.0, counter.getPeak()); - counter.registerEvent(1000, start + 500); - assertEquals(4000.0, counter.getPeak()); - Thread.sleep(2000); - counter.registerEvent(1000); - assertEquals(4000.0, counter.getPeak()); - assertEquals(6000, counter.getTotal()); - } - - /** - * Test the current rate is generated correctly. - */ - public void testRate() throws Exception - { - StatisticsCounter counter = new StatisticsCounter("test", 1000L); - assertEquals(0.0, counter.getRate()); - Thread.sleep(500); - counter.registerEvent(1000); - Thread.sleep(1000); - assertEquals(1000.0, counter.getRate()); - counter.registerEvent(2000); - Thread.sleep(1000); - assertEquals(2000.0, counter.getRate()); - counter.registerEvent(1000); - Thread.sleep(1000); - assertEquals(1000.0, counter.getRate()); - Thread.sleep(1000); - assertEquals(0.0, counter.getRate()); - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java index 3acd064fd7..3ebe631f62 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java @@ -122,7 +122,6 @@ public class MessageStoreTest extends InternalBrokerBaseCase } catch (Exception e) { - e.printStackTrace(); fail(e.getMessage()); } } @@ -590,7 +589,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase headerBody.classId = BasicConsumeBodyImpl.CLASS_ID; headerBody.bodySize = 0; - headerBody.setProperties(properties); + headerBody.properties = properties; try { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java index 2d41eb9899..a75cbe8662 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java @@ -102,7 +102,7 @@ public class ReferenceCountingTest extends QpidTestCase ContentHeaderBody chb = new ContentHeaderBody(); BasicContentHeaderProperties bchp = new BasicContentHeaderProperties(); bchp.setDeliveryMode((byte)2); - chb.setProperties(bchp); + chb.properties = bchp; return chb; } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java index 6fbc627d8c..1ec134e90e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java @@ -22,7 +22,6 @@ package org.apache.qpid.server.subscription; */ import java.util.ArrayList; -import java.util.List; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -46,7 +45,6 @@ public class MockSubscription implements Subscription private State _state = State.ACTIVE; private ArrayList<QueueEntry> messages = new ArrayList<QueueEntry>(); private final Lock _stateChangeLock = new ReentrantLock(); - private List<QueueEntry> _acceptEntries = null; private final QueueEntry.SubscriptionAcquiredState _owningState = new QueueEntry.SubscriptionAcquiredState(this); private final QueueEntry.SubscriptionAssignedState _assignedState = new QueueEntry.SubscriptionAssignedState(this); @@ -56,15 +54,6 @@ public class MockSubscription implements Subscription // Create a simple ID that increments for ever new Subscription private final long _subscriptionID = idGenerator.getAndIncrement(); - public MockSubscription() - { - } - - public MockSubscription(List<QueueEntry> acceptEntries) - { - _acceptEntries = acceptEntries; - } - public void close() { _closed = true; @@ -130,15 +119,8 @@ public class MockSubscription implements Subscription _stateChangeLock.lock(); } - public boolean hasInterest(QueueEntry entry) + public boolean hasInterest(QueueEntry msg) { - if(_acceptEntries != null) - { - //simulate selector behaviour, only signal - //interest in the dictated queue entries - return _acceptEntries.contains(entry); - } - return true; } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionListTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionListTest.java deleted file mode 100644 index c4d1a1e614..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionListTest.java +++ /dev/null @@ -1,429 +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 - * - * 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.qpid.server.subscription; - -import org.apache.qpid.server.subscription.SubscriptionList.SubscriptionNode; -import org.apache.qpid.server.subscription.SubscriptionList.SubscriptionNodeIterator; -import org.apache.qpid.test.utils.QpidTestCase; - -public class SubscriptionListTest extends QpidTestCase -{ - private SubscriptionList _subList; - private MockSubscription _sub1; - private MockSubscription _sub2; - private MockSubscription _sub3; - private SubscriptionNode _node; - - protected void setUp() - { - _subList = new SubscriptionList(); - - _sub1 = new MockSubscription(); - _sub2 = new MockSubscription(); - _sub3 = new MockSubscription(); - - _subList.add(_sub1); - _subList.add(_sub2); - _subList.add(_sub3); - - _node = _subList.getHead(); - } - - /** - * Test that if the first (non-head) node in the list is deleted (but is still present), - * it is not returned when searching through the list for the next viable node, and the - * subsequent viable node is returned instead. - */ - public void testFindNextSkipsFirstDeletedNode() - { - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub1).delete()); - - assertNotNull("Returned node should not be null", _node = _node.findNext()); - assertEquals("Should have returned node for 2nd subscription", _sub2, _node.getSubscription()); - - assertNotNull("Returned node should not be null", _node = _node.findNext()); - assertEquals("Should have returned node for 3rd subscription", _sub3, _node.getSubscription()); - } - - /** - * Test that if a central node in the list is deleted (but is still present), - * it is not returned when searching through the list for the next viable node, - * and the subsequent viable node is returned instead. - */ - public void testFindNextSkipsCentralDeletedNode() - { - assertNotNull("Returned node should not be null", _node = _node.findNext()); - - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub2).delete()); - - assertNotNull("Returned node should not be null", _node = _node.findNext()); - assertEquals("Should have returned node for 3rd subscription", _sub3, _node.getSubscription()); - } - - /** - * Test that if the last node in the list is deleted (but is still present), - * it is not returned when searching through the list for the next viable node, - * and null is returned instead. - */ - public void testFindNextSkipsLastDeletedNode() - { - assertNotNull("Returned node should not be null", _node = _node.findNext()); - assertEquals("Should have returned node for 1st subscription", _sub1, _node.getSubscription()); - - assertNotNull("Returned node should not be null", _node = _node.findNext()); - assertEquals("Should have returned node for 2nd subscription", _sub2, _node.getSubscription()); - - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub3).delete()); - - assertNull("Returned node should be null", _node = _node.findNext()); - } - - /** - * Test that if multiple nodes in the list are deleted (but still present), they - * are not returned when searching through the list for the next viable node, - * and the subsequent viable node is returned instead. - */ - public void testFindNextSkipsMultipleDeletedNode() - { - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub1).delete()); - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub2).delete()); - - assertNotNull("Returned node should not be null", _node = _node.findNext()); - assertEquals("Should have returned node for 3rd subscription", _sub3, _node.getSubscription()); - } - - /** - * Test that if a node in the list is marked 'deleted' it is still present in the list - * until actually removed. counter-test to verify above testing of getNext() method. - */ - public void testDeletedNodeStillPresent() - { - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub1).delete()); - - assertNotNull("Node marked deleted should still be present", getNodeForSubscription(_subList, _sub1)); - assertEquals("All 3 nodes are still expected to be present", 3, countNodes(_subList)); - } - - /** - * Traverses the list nodes in a non-mutating fashion, returning the first node which matches the given - * Subscription, or null if none is found. - */ - private SubscriptionNode getNodeForSubscription(final SubscriptionList list, final Subscription sub) - { - SubscriptionNode node = list.getHead(); - while (node != null && node.getSubscription() != sub) - { - node = node.nextNode(); - } - - return node; - } - - /** - * Counts the number of (non-head) nodes in the list. - */ - private int countNodes(final SubscriptionList list) - { - SubscriptionNode node = list.getHead(); - int count; - for(count = -1; node != null; count++) - { - node = node.nextNode(); - } - - return count; - } - - /** - * Tests that the head is returned as expected, and isn't the node for the first subscription. - */ - public void testGetHead() - { - assertNotNull("List head should be non null", _node); - assertNotSame("Head should not be node for first subscription", - _node, getNodeForSubscription(_subList, _sub1)); - } - - /** - * Tests that the size is returned correctly in the face of additions and removals. - */ - public void testGetSize() - { - SubscriptionList subList = new SubscriptionList(); - - assertEquals("Unexpected size result", 0, subList.size()); - - Subscription sub1 = new MockSubscription(); - Subscription sub2 = new MockSubscription(); - Subscription sub3 = new MockSubscription(); - - subList.add(sub1); - assertEquals("Unexpected size result", 1, subList.size()); - - subList.add(sub2); - assertEquals("Unexpected size result", 2, subList.size()); - - subList.add(sub3); - assertEquals("Unexpected size result", 3, subList.size()); - - assertTrue("Removing subscription from list should have succeeded", subList.remove(sub1)); - assertEquals("Unexpected size result", 2, subList.size()); - - assertTrue("Removing subscription from list should have succeeded", subList.remove(sub2)); - assertEquals("Unexpected size result", 1, subList.size()); - - assertTrue("Removing subscription from list should have succeeded", subList.remove(sub3)); - assertEquals("Unexpected size result", 0, subList.size()); - } - - /** - * Test that if the first (non-head) node in the list is removed it is no longer - * present in the node structure of the list at all. - */ - public void testRemoveFirstNode() - { - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub1)); - assertTrue("Removing subscription node should have succeeded", _subList.remove(_sub1)); - assertNull("Should not have been a node present for the removed subscription", getNodeForSubscription(_subList, _sub1)); - assertEquals("Unexpected number of nodes", 2, countNodes(_subList)); - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub2)); - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub3)); - } - - /** - * Test that if a central node in the list is removed it is no longer - * present in the node structure of the list at all. - */ - public void testRemoveCentralNode() - { - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub2)); - assertTrue("Removing subscription node should have succeeded", _subList.remove(_sub2)); - assertNull("Should not have been a node present for the removed subscription", getNodeForSubscription(_subList, _sub2)); - assertEquals("Unexpected number of nodes", 2, countNodes(_subList)); - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub1)); - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub3)); - } - - /** - * Test that if the subscription contained in the last node of the list is removed - * it is no longer present in the node structure of the list at all. However, - * as the last node in the structure can't actually be removed a dummy will instead - * be present. - */ - public void testRemoveLastNode() - { - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub3)); - assertTrue("Removing subscription node should have succeeded", _subList.remove(_sub3)); - assertNull("Should not have been a node present for the removed subscription", getNodeForSubscription(_subList, _sub3)); - - //We actually expect 3 nodes to remain this time, because the last node cant be removed for thread safety reasons, - //however a dummy final node can be used as substitute to allow removal of the subscription node. - assertEquals("Unexpected number of nodes", 2 + 1, countNodes(_subList)); - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub1)); - assertNotNull("Should have been a node present for the subscription", getNodeForSubscription(_subList, _sub2)); - } - - /** - * Test that if the subscription not contained in the list is requested to be removed - * that the removal fails - */ - public void testRemoveNonExistantNode() - { - Subscription sub4 = new MockSubscription(); - assertNull("Should not have been a node present for the subscription", getNodeForSubscription(_subList, sub4)); - assertFalse("Removing subscription node should not have succeeded", _subList.remove(sub4)); - assertEquals("Unexpected number of nodes", 3, countNodes(_subList)); - } - - /** - * Test that if a subscription node which occurs later in the main list than the marked node is - * removed from the list after the marked node is also removed, then the marker node doesn't - * serve to retain the subsequent nodes in the list structure (and thus memory) despite their - * removal. - */ - public void testDeletedMarkedNodeDoesntLeakSubsequentlyDeletedNodes() - { - //get the nodes out the list for the 1st and 3rd subscriptions - SubscriptionNode sub1Node = getNodeForSubscription(_subList, _sub1); - assertNotNull("Should have been a node present for the subscription", sub1Node); - SubscriptionNode sub3Node = getNodeForSubscription(_subList, _sub3); - assertNotNull("Should have been a node present for the subscription", sub3Node); - - //mark the first subscription node - assertTrue("should have succeeded in updating the marked node", - _subList.updateMarkedNode(_subList.getMarkedNode(), sub1Node)); - - //remove the 1st subscription from the list - assertTrue("Removing subscription node should have succeeded", _subList.remove(_sub1)); - //verify the 1st subscription is no longer the marker node (replaced by a dummy), or in the main list structure - assertNotSame("Unexpected marker node", sub1Node, _subList.getMarkedNode()); - assertNull("Should not have been a node present in the list structure for the marked-but-removed sub1 node", - getNodeForSubscription(_subList, _sub1)); - - //remove the 2nd subscription from the list - assertTrue("Removing subscription node should have succeeded", _subList.remove(_sub2)); - - //verify the marker node isn't leaking subsequently removed nodes, by ensuring the very next node - //in its list structure is now the 3rd subscription (since the 2nd was removed too) - assertEquals("Unexpected next node", sub3Node, _subList.getMarkedNode().nextNode()); - - //remove the 3rd and final/tail subscription - assertTrue("Removing subscription node should have succeeded", _subList.remove(_sub3)); - - //verify the marker node isn't leaking subsequently removed nodes, by ensuring the very next node - //in its list structure is now the dummy tail (since the 3rd subscription was removed, and a dummy - //tail was inserted) and NOT the 3rd sub node. - assertNotSame("Unexpected next node", sub3Node, _subList.getMarkedNode().nextNode()); - assertTrue("Unexpected next node", _subList.getMarkedNode().nextNode().isDeleted()); - assertNull("Next non-deleted node from the marker should now be the list end, i.e. null", _subList.getMarkedNode().findNext()); - } - - /** - * Test that the marked node 'findNext' behaviour is as expected after a subscription is added - * to the list following the tail subscription node being removed while it is the marked node. - * That is, that the new subscriptions node is returned by getMarkedNode().findNext(). - */ - public void testMarkedNodeFindsNewSubscriptionAfterRemovingTailWhilstMarked() - { - //get the node out the list for the 3rd subscription - SubscriptionNode sub3Node = getNodeForSubscription(_subList, _sub3); - assertNotNull("Should have been a node present for the subscription", sub3Node); - - //mark the 3rd subscription node - assertTrue("should have succeeded in updating the marked node", - _subList.updateMarkedNode(_subList.getMarkedNode(), sub3Node)); - - //verify calling findNext on the marked node returns null, i.e. the end of the list has been reached - assertEquals("Unexpected node after marked node", null, _subList.getMarkedNode().findNext()); - - //remove the 3rd(marked) subscription from the list - assertTrue("Removing subscription node should have succeeded", _subList.remove(_sub3)); - - //add a new 4th subscription to the list - Subscription sub4 = new MockSubscription(); - _subList.add(sub4); - - //get the node out the list for the 4th subscription - SubscriptionNode sub4Node = getNodeForSubscription(_subList, sub4); - assertNotNull("Should have been a node present for the subscription", sub4Node); - - //verify the marked node (which is now a dummy substitute for the 3rd subscription) returns - //the 4th subscriptions node as the next non-deleted node. - assertEquals("Unexpected next node", sub4Node, _subList.getMarkedNode().findNext()); - } - - /** - * Test that setting the marked node to null doesn't cause problems during remove operations - */ - public void testRemoveWithNullMarkedNode() - { - //set the marker to null - assertTrue("should have succeeded in updating the marked node", - _subList.updateMarkedNode(_subList.getMarkedNode(), null)); - - //remove the 1st subscription from the main list - assertTrue("Removing subscription node should have succeeded", _subList.remove(_sub1)); - - //verify the 1st subscription is no longer in the main list structure - assertNull("Should not have been a node present in the main list structure for sub1", - getNodeForSubscription(_subList, _sub1)); - assertEquals("Unexpected number of nodes", 2, countNodes(_subList)); - } - - /** - * Tests that after the first (non-head) node of the list is marked deleted but has not - * yet been removed, the iterator still skips it. - */ - public void testIteratorSkipsFirstDeletedNode() - { - //'delete' but dont remove the node for the 1st subscription - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub1).delete()); - assertNotNull("Should still have been a node present for the deleted subscription", - getNodeForSubscription(_subList, _sub1)); - - SubscriptionNodeIterator iter = _subList.iterator(); - - //verify the iterator returns the 2nd subscriptions node - assertTrue("Iterator should have been able to advance", iter.advance()); - assertEquals("Iterator returned unexpected SubscriptionNode", _sub2, iter.getNode().getSubscription()); - - //verify the iterator returns the 3rd subscriptions node and not the 2nd. - assertTrue("Iterator should have been able to advance", iter.advance()); - assertEquals("Iterator returned unexpected SubscriptionNode", _sub3, iter.getNode().getSubscription()); - } - - /** - * Tests that after a central node of the list is marked deleted but has not yet been removed, - * the iterator still skips it. - */ - public void testIteratorSkipsCentralDeletedNode() - { - //'delete' but dont remove the node for the 2nd subscription - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub2).delete()); - assertNotNull("Should still have been a node present for the deleted subscription", - getNodeForSubscription(_subList, _sub2)); - - SubscriptionNodeIterator iter = _subList.iterator(); - - //verify the iterator returns the 1st subscriptions node - assertTrue("Iterator should have been able to advance", iter.advance()); - assertEquals("Iterator returned unexpected SubscriptionNode", _sub1, iter.getNode().getSubscription()); - - //verify the iterator returns the 3rd subscriptions node and not the 2nd. - assertTrue("Iterator should have been able to advance", iter.advance()); - assertEquals("Iterator returned unexpected SubscriptionNode", _sub3, iter.getNode().getSubscription()); - } - - /** - * Tests that after the last node of the list is marked deleted but has not yet been removed, - * the iterator still skips it. - */ - public void testIteratorSkipsDeletedFinalNode() - { - //'delete' but dont remove the node for the 3rd subscription - assertTrue("Deleting subscription node should have succeeded", - getNodeForSubscription(_subList, _sub3).delete()); - assertNotNull("Should still have been a node present for the deleted 3rd subscription", - getNodeForSubscription(_subList, _sub3)); - - SubscriptionNodeIterator iter = _subList.iterator(); - - //verify the iterator returns the 1st subscriptions node - assertTrue("Iterator should have been able to advance", iter.advance()); - assertEquals("Iterator returned unexpected SubscriptionNode", _sub1, iter.getNode().getSubscription()); - - //verify the iterator returns the 2nd subscriptions node - assertTrue("Iterator should have been able to advance", iter.advance()); - assertEquals("Iterator returned unexpected SubscriptionNode", _sub2, iter.getNode().getSubscription()); - - //verify the iterator can no longer advance and does not return a subscription node - assertFalse("Iterator should not have been able to advance", iter.advance()); - assertEquals("Iterator returned unexpected SubscriptionNode", null, iter.getNode()); - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockAction.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockAction.java index 15c135ea2c..975e3e91b9 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockAction.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockAction.java @@ -32,11 +32,13 @@ class MockAction implements Action private boolean _rollbackFired = false; private boolean _postCommitFired = false; + @Override public void postCommit() { _postCommitFired = true; } + @Override public void onRollback() { _rollbackFired = true; diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java index 422105e410..64c62fd029 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java @@ -46,56 +46,67 @@ class MockServerMessage implements ServerMessage this.persistent = persistent; } + @Override public boolean isPersistent() { return persistent; } + @Override public MessageReference newReference() { throw new NotImplementedException(); } + @Override public boolean isImmediate() { throw new NotImplementedException(); } + @Override public long getSize() { throw new NotImplementedException(); } + @Override public SessionConfig getSessionConfig() { throw new NotImplementedException(); } + @Override public String getRoutingKey() { throw new NotImplementedException(); } + @Override public AMQMessageHeader getMessageHeader() { throw new NotImplementedException(); } + @Override public long getExpiration() { throw new NotImplementedException(); } + @Override public int getContent(ByteBuffer buf, int offset) { throw new NotImplementedException(); } + @Override public long getArrivalTime() { throw new NotImplementedException(); } + @Override public Long getMessageNumber() { return 0L; diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockStoreTransaction.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockStoreTransaction.java index ff372532ac..5700bba9f8 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockStoreTransaction.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockStoreTransaction.java @@ -61,6 +61,7 @@ class MockStoreTransaction implements Transaction return _state; } + @Override public void enqueueMessage(TransactionLogResource queue, Long messageId) throws AMQStoreException { if (_throwExceptionOnQueueOp) @@ -82,6 +83,8 @@ class MockStoreTransaction implements Transaction return _numberOfEnqueuedMessages; } + + @Override public void dequeueMessage(TransactionLogResource queue, Long messageId) throws AMQStoreException { if (_throwExceptionOnQueueOp) @@ -92,16 +95,19 @@ class MockStoreTransaction implements Transaction _numberOfDequeuedMessages++; } + @Override public void commitTran() throws AMQStoreException { _state = TransactionState.COMMITTED; } + @Override public StoreFuture commitTranAsync() throws AMQStoreException { throw new NotImplementedException(); } + @Override public void abortTran() throws AMQStoreException { _state = TransactionState.ABORTED; @@ -111,11 +117,14 @@ class MockStoreTransaction implements Transaction { return new TransactionLog() { + + @Override public void configureTransactionLog(String name, TransactionLogRecoveryHandler recoveryHandler, Configuration storeConfiguration, LogSubject logSubject) throws Exception { } - + + @Override public Transaction newTransaction() { storeTransaction.setState(TransactionState.STARTED); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java index ff94942457..925b161118 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java @@ -243,7 +243,7 @@ public class InternalBrokerBaseCase extends QpidTestCase //Make Message Persistent properties.setDeliveryMode((byte) 2); - _headerBody.setProperties(properties); + _headerBody.properties = properties; channel.publishContentHeader(_headerBody); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java index 8fa820ad95..af8997cf40 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java @@ -20,70 +20,27 @@ */ package org.apache.qpid.server.util; -import java.util.Properties; - import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.configuration.ServerConfiguration; -import org.apache.qpid.server.logging.NullRootMessageLogger; -import org.apache.qpid.server.logging.actors.BrokerActor; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabase; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; -import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager; +import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabaseManager; + +import java.util.Properties; + public class TestApplicationRegistry extends ApplicationRegistry { - public TestApplicationRegistry(ServerConfiguration config) throws ConfigurationException { super(config); } - @Override - public void initialise() throws Exception - { - CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger())); - super.initialise(); - } - - /** - * @see org.apache.qpid.server.registry.ApplicationRegistry#createAuthenticationManager() - */ - @Override - protected AuthenticationManager createAuthenticationManager() throws ConfigurationException + protected void createDatabaseManager(ServerConfiguration configuration) throws Exception { - final Properties users = new Properties(); + Properties users = new Properties(); users.put("guest","guest"); users.put("admin","admin"); - - final PropertiesPrincipalDatabase ppd = new PropertiesPrincipalDatabase(users); - - AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager() - { - - /** - * @see org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager#configure(org.apache.qpid.server.configuration.plugins.ConfigurationPlugin) - */ - @Override - public void configure(ConfigurationPlugin config) throws ConfigurationException - { - // We don't pass configuration to this test instance. - } - - @Override - public void initialise() - { - setPrincipalDatabase(ppd); - - super.initialise(); - } - }; - - pdam.initialise(); - - return pdam; + _databaseManager = new PropertiesPrincipalDatabaseManager("testPasswordFile", users); } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java deleted file mode 100644 index 98bf381712..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java +++ /dev/null @@ -1,67 +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 - * - * 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.qpid.server.virtualhost; - -import java.util.concurrent.CountDownLatch; - -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.logging.NullRootMessageLogger; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.actors.TestLogActor; -import org.apache.qpid.test.utils.QpidTestCase; - -public class HouseKeepingTaskTest extends QpidTestCase -{ - /** - * Tests that the abstract HouseKeepingTask properly cleans up any LogActor - * it adds to the CurrentActor stack by verifying the CurrentActor set - * before task execution is the CurrentActor after execution. - */ - public void testCurrentActorStackBalance() throws Exception - { - //create and set a test actor - LogActor testActor = new TestLogActor(new NullRootMessageLogger()); - CurrentActor.set(testActor); - - //verify it is returned correctly before executing a HouseKeepingTask - assertEquals("Expected LogActor was not returned", testActor, CurrentActor.get()); - - final CountDownLatch latch = new CountDownLatch(1); - HouseKeepingTask testTask = new HouseKeepingTask(new MockVirtualHost("HouseKeepingTaskTestVhost")) - { - @Override - public void execute() - { - latch.countDown(); - } - }; - - //run the test HouseKeepingTask using the current Thread to influence its CurrentActor stack - testTask.run(); - - assertEquals("The expected LogActor was not returned, the CurrentActor stack has become unbalanced", - testActor, CurrentActor.get()); - assertEquals("HouseKeepingTask execute() method was not run", 0, latch.getCount()); - - //clean up the test actor - CurrentActor.remove(); - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java deleted file mode 100644 index 7aa314bf22..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java +++ /dev/null @@ -1,271 +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 - * - * 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.qpid.server.virtualhost; - -import java.util.UUID; - -import org.apache.qpid.server.binding.BindingFactory; -import org.apache.qpid.server.configuration.BrokerConfig; -import org.apache.qpid.server.configuration.ConfigStore; -import org.apache.qpid.server.configuration.ConfiguredObject; -import org.apache.qpid.server.configuration.VirtualHostConfig; -import org.apache.qpid.server.configuration.VirtualHostConfigType; -import org.apache.qpid.server.configuration.VirtualHostConfiguration; -import org.apache.qpid.server.connection.IConnectionRegistry; -import org.apache.qpid.server.exchange.ExchangeFactory; -import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.federation.BrokerLink; -import org.apache.qpid.server.management.ManagedObject; -import org.apache.qpid.server.queue.QueueRegistry; -import org.apache.qpid.server.registry.IApplicationRegistry; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; -import org.apache.qpid.server.stats.StatisticsCounter; -import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.TransactionLog; - -public class MockVirtualHost implements VirtualHost -{ - private String _name; - - public MockVirtualHost(String name) - { - _name = name; - } - - public void close() - { - - } - - public void createBrokerConnection(String transport, String host, int port, - String vhost, boolean durable, String authMechanism, - String username, String password) - { - - } - - public IApplicationRegistry getApplicationRegistry() - { - return null; - } - - public AuthenticationManager getAuthenticationManager() - { - return null; - } - - public BindingFactory getBindingFactory() - { - return null; - } - - public UUID getBrokerId() - { - return null; - } - - public ConfigStore getConfigStore() - { - return null; - } - - public VirtualHostConfiguration getConfiguration() - { - return null; - } - - public IConnectionRegistry getConnectionRegistry() - { - return null; - } - - public DurableConfigurationStore getDurableConfigurationStore() - { - return null; - } - - public ExchangeFactory getExchangeFactory() - { - return null; - } - - public ExchangeRegistry getExchangeRegistry() - { - return null; - } - - public int getHouseKeepingActiveCount() - { - return 0; - } - - public long getHouseKeepingCompletedTaskCount() - { - return 0; - } - - public int getHouseKeepingPoolSize() - { - return 0; - } - - public long getHouseKeepingTaskCount() - { - return 0; - } - - public ManagedObject getManagedObject() - { - return null; - } - - public MessageStore getMessageStore() - { - return null; - } - - public String getName() - { - return _name; - } - - public QueueRegistry getQueueRegistry() - { - return null; - } - - public SecurityManager getSecurityManager() - { - return null; - } - - public TransactionLog getTransactionLog() - { - return null; - } - - public void removeBrokerConnection(BrokerLink brokerLink) - { - - } - - public void scheduleHouseKeepingTask(long period, HouseKeepingTask task) - { - - } - - public void setHouseKeepingPoolSize(int newSize) - { - - } - - public BrokerConfig getBroker() - { - return null; - } - - public String getFederationTag() - { - return null; - } - - public void setBroker(BrokerConfig brokerConfig) - { - - } - - public VirtualHostConfigType getConfigType() - { - return null; - } - - public long getCreateTime() - { - return 0; - } - - public UUID getId() - { - return null; - } - - public ConfiguredObject<VirtualHostConfigType, VirtualHostConfig> getParent() - { - return null; - } - - public boolean isDurable() - { - return false; - } - - public StatisticsCounter getDataDeliveryStatistics() - { - return null; - } - - public StatisticsCounter getDataReceiptStatistics() - { - return null; - } - - public StatisticsCounter getMessageDeliveryStatistics() - { - return null; - } - - public StatisticsCounter getMessageReceiptStatistics() - { - return null; - } - - public void initialiseStatistics() - { - - } - - public boolean isStatisticsEnabled() - { - return false; - } - - public void registerMessageDelivered(long messageSize) - { - - } - - public void registerMessageReceived(long messageSize, long timestamp) - { - - } - - public void resetStatistics() - { - - } - - public void setStatisticsEnabled(boolean enabled) - { - - } -}
\ No newline at end of file |