diff options
| author | Keith Wall <kwall@apache.org> | 2011-11-11 09:45:26 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2011-11-11 09:45:26 +0000 |
| commit | e76a7d8a309ab70a7abbdc780d0f5f58bc851c30 (patch) | |
| tree | 672b73ce17c3133fdf1c572e87c4d778fd9b8f17 /qpid/java/systests | |
| parent | 728dbc9c8e3b38634b2f0cbb6e7d9b8caeb1efc3 (diff) | |
| download | qpid-python-e76a7d8a309ab70a7abbdc780d0f5f58bc851c30.tar.gz | |
QPID-3490: creating queue via JMX now binds the queue to the default exchange; prevented unregistration of the default exchange.
Applied patch from Oleksandr Rudyy<orudyy@gmail.com> and myself.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1200790 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/systests')
9 files changed, 174 insertions, 25 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedBrokerMBeanTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedBrokerMBeanTest.java new file mode 100644 index 0000000000..390a7b55e4 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedBrokerMBeanTest.java @@ -0,0 +1,139 @@ +/* + * 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.management.jmx; + +import javax.management.JMException; +import javax.management.MBeanException; +import javax.management.ObjectName; + +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.management.common.mbeans.ManagedBroker; +import org.apache.qpid.management.common.mbeans.ManagedExchange; +import org.apache.qpid.test.utils.JMXTestUtils; +import org.apache.qpid.test.utils.QpidBrokerTestCase; + +/** + * Tests the JMX API for the Managed Broker. + * + */ +public class ManagedBrokerMBeanTest extends QpidBrokerTestCase +{ + /** + * Test virtual host + */ + private static final String VIRTUAL_HOST = "test"; + + /** + * Test exchange type + */ + private static final String EXCHANGE_TYPE = "topic"; + + /** + * JMX helper. + */ + private JMXTestUtils _jmxUtils; + private ManagedBroker _managedBroker; + + public void setUp() throws Exception + { + _jmxUtils = new JMXTestUtils(this); + _jmxUtils.setUp(); + super.setUp(); + _jmxUtils.open(); + _managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST); + } + + public void tearDown() throws Exception + { + if (_jmxUtils != null) + { + _jmxUtils.close(); + } + super.tearDown(); + } + + /** + * Tests queue creation/deletion also verifying the automatic binding to the default exchange. + */ + public void testCreateQueueAndDeletion() throws Exception + { + final String queueName = getTestQueueName(); + final ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString()); + + // Check that bind does not exist before queue creation + assertFalse("Binding to " + queueName + " should not exist in default exchange before queue creation", + defaultExchange.bindings().containsKey(new String[] {queueName})); + + _managedBroker.createNewQueue(queueName, "testowner", true); + + // Ensure the queue exists + assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName("test", queueName)); + assertNotNull("Manager queue expected to be available", _jmxUtils.getManagedQueue(queueName)); + + // Now verify that the default exchange has been bound. + assertTrue("Binding to " + queueName + " should exist in default exchange after queue creation", + defaultExchange.bindings().containsKey(new String[] {queueName})); + + // Now delete the queue + _managedBroker.deleteQueue(queueName); + + // Finally ensure that the binding has been removed. + assertFalse("Binding to " + queueName + " should not exist in default exchange after queue deletion", + defaultExchange.bindings().containsKey(new String[] {queueName})); + } + + /** + * Tests exchange creation/deletion via JMX API. + */ + public void testCreateExchangeAndUnregister() throws Exception + { + String exchangeName = getTestName(); + _managedBroker.createNewExchange(exchangeName, "topic", true); + String queryString = "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost=" + + ObjectName.quote(VIRTUAL_HOST) + ",name=" + ObjectName.quote(exchangeName) + ",ExchangeType=" + + EXCHANGE_TYPE; + ManagedExchange exchange = _jmxUtils.getManagedObject(ManagedExchange.class, queryString); + assertNotNull("Exchange should exist", exchange); + + _managedBroker.unregisterExchange(exchangeName); + assertFalse("Exchange should have been removed", _jmxUtils.isManagedObjectExist(queryString)); + } + + /** + * Tests that it is disallowed to unregister the default exchange. + */ + public void testUnregisterOfDefaultExchangeDisallowed() throws Exception + { + String defaultExchangeName = ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString(); + + try + { + _managedBroker.unregisterExchange(defaultExchangeName); + fail("Exception not thrown"); + } + catch (MBeanException mbe) + { + // PASS + assertEquals("Error in unregistering exchange " + defaultExchangeName, mbe.getMessage()); + assertTrue(mbe.getCause().getMessage().contains("Cannot unregister the default exchange")); + } + final ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName); + assertNotNull("Exchange should exist", defaultExchange); + } +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java index 12a1682212..0e2875235f 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java @@ -45,12 +45,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging { private JMXTestUtils _jmxUtils; private boolean _closed = false; - private static final String USER = "admin"; @Override public void setUp() throws Exception { - _jmxUtils = new JMXTestUtils(this, USER, USER); + _jmxUtils = new JMXTestUtils(this); _jmxUtils.setUp(); super.setUp(); _jmxUtils.open(); @@ -364,7 +363,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging List<String> results = waitAndFindMatches("BND-1001"); - assertEquals("More than one bind creation found", 1, results.size()); + assertEquals("Unexpected number of bindings logged", 2, results.size()); String log = getLogMessage(results, 0); @@ -391,7 +390,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging List<String> results = waitAndFindMatches("BND-1001"); - assertEquals("More than one bind creation found", 1, results.size()); + assertEquals("Unexpected number of bindings logged", 2, results.size()); String log = getLogMessage(results, 0); @@ -418,7 +417,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging List<String> results = waitAndFindMatches("BND-1001"); - assertEquals("More than one bind creation found", 1, results.size()); + assertEquals("Unexpected number of bindings logged", 2, results.size()); String log = getLogMessage(results, 0); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ModelTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ModelTest.java index e3fd042560..ddc51f69bd 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ModelTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ModelTest.java @@ -60,7 +60,6 @@ import java.lang.reflect.UndeclaredThrowableException; public class ModelTest extends QpidBrokerTestCase { - private static final String USER = "admin"; private JMXTestUtils _jmxUtils; private static final String VIRTUALHOST_NAME = "test"; @@ -68,7 +67,7 @@ public class ModelTest extends QpidBrokerTestCase public void setUp() throws Exception { // Create a JMX Helper - _jmxUtils = new JMXTestUtils(this, USER, USER); + _jmxUtils = new JMXTestUtils(this); _jmxUtils.setUp(); super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java index a724e6c66e..775d2c3eb0 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java @@ -55,11 +55,10 @@ public class ProducerFlowControlTest extends AbstractTestLogging private JMXTestUtils _jmxUtils; private boolean _jmxUtilConnected; - private static final String USER = "admin"; public void setUp() throws Exception { - _jmxUtils = new JMXTestUtils(this, USER , USER); + _jmxUtils = new JMXTestUtils(this); _jmxUtils.setUp(); _jmxUtilConnected=false; super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java index b823690002..4552cf7004 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java @@ -52,7 +52,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase @Override public void setUp() throws Exception { - _jmx = new JMXTestUtils(this, "admin", "admin"); + _jmx = new JMXTestUtils(this); _jmx.setUp(); super.setUp(); _jmx.open(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalAdminACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalAdminACLTest.java index 290cbfdc14..b0bc4fd946 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalAdminACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalAdminACLTest.java @@ -63,7 +63,7 @@ public class ExternalAdminACLTest extends AbstractACLTestCase { _testConfigFile = createTempTestLog4JConfig(); - _jmx = new JMXTestUtils(this, "admin", "admin"); + _jmx = new JMXTestUtils(this); _jmx.setUp(); super.setUp(); _jmx.open(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java index a7efe4922b..2d326d73b8 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java @@ -58,7 +58,6 @@ public class JMSDestinationTest extends QpidBrokerTestCase private Connection _connection; private Session _session; - private static final String USER = "admin"; private CountDownLatch _receiveMessage; private Message _message; @@ -143,7 +142,7 @@ public class JMSDestinationTest extends QpidBrokerTestCase public void testMovedToQueue() throws Exception { // Setup JMXUtils - JMXTestUtils jmxUtils = new JMXTestUtils(this, USER, USER); + JMXTestUtils jmxUtils = new JMXTestUtils(this); jmxUtils.setUp(); // Open the JMX Connection jmxUtils.open(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java index 1fde6c7c73..3a1710671c 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java @@ -51,18 +51,26 @@ import org.apache.qpid.management.common.mbeans.UserManagement; */ public class JMXTestUtils { - QpidBrokerTestCase _test; - MBeanServerConnection _mbsc; - JMXConnector _jmxc; + private static final String DEFAULT_PASSWORD = "admin"; + private static final String DEFAULT_USERID = "admin"; - private String USER; - private String PASSWORD; + private MBeanServerConnection _mbsc; + private JMXConnector _jmxc; + + private final String _user; + private final String _password; + private final QpidBrokerTestCase _test; public JMXTestUtils(QpidBrokerTestCase test, String user, String password) { _test = test; - USER = user; - PASSWORD = password; + _user = user; + _password = password; + } + + public JMXTestUtils(QpidBrokerTestCase test) + { + this(test, DEFAULT_USERID, DEFAULT_PASSWORD); } public void setUp() throws IOException, ConfigurationException, Exception @@ -73,7 +81,7 @@ public class JMXTestUtils public void open() throws Exception { _jmxc = JMXConnnectionFactory.getJMXConnection(5000, "127.0.0.1", - _test.getManagementPort(_test.getPort()), USER, PASSWORD); + _test.getManagementPort(_test.getPort()), _user, _password); _mbsc = _jmxc.getMBeanServerConnection(); } @@ -319,6 +327,12 @@ public class JMXTestUtils return getManagedObject(managedClass, objectName); } + public boolean isManagedObjectExist(String query) + { + return !queryObjects(query).isEmpty(); + + } + public <T> T getManagedObject(Class<T> managedClass, ObjectName objectName) { return MBeanServerInvocationHandler.newProxyInstance(_mbsc, objectName, managedClass, false); @@ -370,7 +384,7 @@ public class JMXTestUtils } /** - * Retrive {@link ServerInformation} JMX MBean. + * Retrieve {@link ServerInformation} JMX MBean. */ public ServerInformation getServerInformation() { @@ -387,7 +401,7 @@ public class JMXTestUtils } /** - * Retrive all {@link ManagedConnection} objects. + * Retrieve all {@link ManagedConnection} objects. */ public List<ManagedConnection> getAllManagedConnections() { @@ -402,7 +416,7 @@ public class JMXTestUtils } /** - * Retrive all {@link ManagedConnection} objects for a particular virtual host. + * Retrieve all {@link ManagedConnection} objects for a particular virtual host. */ public List<ManagedConnection> getManagedConnections(String vhost) { diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java index bb44aea659..71fbf4cc81 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java @@ -1326,7 +1326,7 @@ public class QpidBrokerTestCase extends QpidTestCase */ public void reloadBrokerSecurityConfig() throws Exception { - JMXTestUtils jmxu = new JMXTestUtils(this, "admin" , "admin"); + JMXTestUtils jmxu = new JMXTestUtils(this); jmxu.open(); try |
