You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2010/05/31 18:03:44 UTC
svn commit: r949781 [5/5] - in /qpid/trunk/qpid/java: broker/etc/
broker/src/main/java/org/apache/qpid/qmf/
broker/src/main/java/org/apache/qpid/server/
broker/src/main/java/org/apache/qpid/server/binding/
broker/src/main/java/org/apache/qpid/server/co...
Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java?rev=949781&r1=949780&r2=949781&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java Mon May 31 16:03:41 2010
@@ -4,7 +4,7 @@
* 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
+ * "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
@@ -15,28 +15,13 @@
* 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.acl;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.AMQConnectionFailureException;
-import org.apache.qpid.client.AMQAuthenticationException;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.jms.ConnectionListener;
-import org.apache.qpid.jms.ConnectionURL;
-import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.url.URLSyntaxException;
+import java.io.IOException;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
-import javax.jms.ExceptionListener;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
import javax.jms.Message;
@@ -45,71 +30,45 @@ import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicSubscriber;
import javax.naming.NamingException;
-import java.io.File;
-import java.io.IOException;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-public class SimpleACLTest extends QpidTestCase implements ConnectionListener
-{
- public void setUp() throws Exception
- {
- //Performing setUp here would result in a broker with the default ACL test config
-
- //Each test now calls the private setUpACLTest to allow them to make
- //individual customisations to the base ACL settings
- }
-
-
- public void tearDown() throws Exception
- {
- try
- {
- super.tearDown();
- }
- catch (JMSException e)
- {
- //we're throwing this away as it can happen in this test as the state manager remembers exceptions
- //that we provoked with authentication failures, where the test passes - we can ignore on con close
- }
- }
-
- private void setUpACLTest() throws Exception
- {
- final String QPID_HOME = System.getProperty("QPID_HOME");
-
- if (QPID_HOME == null)
- {
- fail("QPID_HOME not set");
- }
-
- // Initialise ACLs.
- _configFile = new File(QPID_HOME, "etc/config-systests-acl.xml");
- super.setUp();
- }
-
- public String createConnectionString(String username, String password)
- {
-
- return "amqp://" + username + ":" + password + "@clientid/test?brokerlist='" + getBroker() + "?retries='0''";
- }
+import org.apache.qpid.AMQException;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.url.URLSyntaxException;
+/**
+ * Basic access control list tests.
+ *
+ * These tests require an access control security plugin to be configured in the broker, and carry out various broker
+ * operations that will succeed or fail depending on the user and virtual host. See the {@code config-systests-acl-setup.xml}
+ * configuration file for the {@link SimpleXML} version of the ACLs used by the Java broker only, or the various {@code .txt}
+ * files in the system tests directory for the external version 3 ACL files used by both the Java and C++ brokers.
+ * <p>
+ * This class can be extended and the {@link #getConfig()} method overridden to run the same tests with a different type
+ * of access control mechanism. Extension classes should differ only in the configuration file used, but extra tests can be
+ * added that are specific to a particular configuration.
+ * <p>
+ * The tests perform basic AMQP operations like creating queues or excahnges and publishing and consuming messages, using
+ * JMS to contact the broker.
+ *
+ * @see ExternalACLTest
+ */
+public class SimpleACLTest extends AbstractACLTestCase
+{
public void testAccessAuthorized() throws AMQException, URLSyntaxException, Exception
{
- setUpACLTest();
-
try
{
- Connection conn = getConnection("client", "guest");
-
- Session sesh = conn.createSession(true, Session.SESSION_TRANSACTED);
-
+ Connection conn = getConnection("test", "client", "guest");
+ Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
conn.start();
//Do something to show connection is active.
- sesh.rollback();
+ sess.rollback();
conn.close();
}
@@ -125,8 +84,6 @@ public class SimpleACLTest extends QpidT
//is unable to perform actions such as connecting (and by extension, creating a queue, and consuming
//from a queue etc). In order to test the vhost-wide 'access' ACL right, the 'guest' user has been given
//this right in the 'test2' vhost.
-
- setUpACLTest();
try
{
@@ -141,16 +98,16 @@ public class SimpleACLTest extends QpidT
conn.start();
//create Queues and consumers for each
- Queue namedQueue = sesh.createQueue("vhostAccessCreatedQueue" + getTestQueueName());
- Queue tempQueue = sesh.createTemporaryQueue();
- MessageConsumer consumer = sesh.createConsumer(namedQueue);
- MessageConsumer tempConsumer = sesh.createConsumer(tempQueue);
+ Queue namedQueue = sess.createQueue("vhostAccessCreatedQueue" + getTestQueueName());
+ Queue tempQueue = sess.createTemporaryQueue();
+ MessageConsumer consumer = sess.createConsumer(namedQueue);
+ MessageConsumer tempConsumer = sess.createConsumer(tempQueue);
//send a message to each queue (also causing an exchange declare)
- MessageProducer sender = ((AMQSession)sesh).createProducer(null);
- ((org.apache.qpid.jms.MessageProducer) sender).send(namedQueue, sesh.createTextMessage("test"),
+ MessageProducer sender = ((AMQSession<?, ?>) sess).createProducer(null);
+ ((org.apache.qpid.jms.MessageProducer) sender).send(namedQueue, sess.createTextMessage("test"),
DeliveryMode.NON_PERSISTENT, 0, 0L, false, false, true);
- ((org.apache.qpid.jms.MessageProducer) sender).send(tempQueue, sesh.createTextMessage("test"),
+ ((org.apache.qpid.jms.MessageProducer) sender).send(tempQueue, sess.createTextMessage("test"),
DeliveryMode.NON_PERSISTENT, 0, 0L, false, false, true);
//consume the messages from the queues
@@ -165,47 +122,93 @@ public class SimpleACLTest extends QpidT
}
}
+ // XXX one
public void testAccessNoRights() throws Exception
{
- setUpACLTest();
-
try
{
- Connection conn = getConnection("guest", "guest");
-
- //Attempt to do do things to test connection.
- Session sesh = conn.createSession(true, Session.SESSION_TRANSACTED);
+ Connection conn = getConnection("test", "guest", "guest");
+ Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
conn.start();
- sesh.rollback();
-
+ sess.rollback();
+
fail("Connection was created.");
}
- catch (JMSException jmse)
+ catch (JMSException e)
+ {
+ // XXX JMSException -> linkedException -> cause = AMQException.403
+ Exception linkedException = e.getLinkedException();
+ assertNotNull("There was no linked exception", linkedException);
+ Throwable cause = linkedException.getCause();
+ assertNotNull("Cause was null", cause);
+ assertTrue("Wrong linked exception type",cause instanceof AMQException);
+ assertEquals("Incorrect error code received", 403, ((AMQException) cause).getErrorCode().getCode());
+ }
+ }
+
+ public void testClientDeleteQueueSuccess() throws Exception
+ {
+ try
{
- Throwable linkedException = jmse.getLinkedException();
- assertNotNull("Cause was null", linkedException);
+ Connection conn = getConnection("test", "client", "guest");
+ Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+ conn.start();
- assertEquals("Linked Exception was wrong type", AMQConnectionFailureException.class, linkedException.getClass());
+ // create kipper
+ Topic kipper = sess.createTopic("kipper");
+ TopicSubscriber subscriber = sess.createDurableSubscriber(kipper, "kipper");
- Throwable cause = linkedException.getCause();
- assertEquals("Cause was wrong type", AMQAuthenticationException.class, cause.getClass());
- assertEquals("Incorrect error code thrown", 403, ((AMQAuthenticationException) cause).getErrorCode().getCode());
+ subscriber.close();
+ sess.unsubscribe("kipper");
+
+ //Do something to show connection is active.
+ sess.rollback();
+ conn.close();
+ }
+ catch (Exception e)
+ {
+ fail("Test failed due to:" + e.getMessage());
+ }
+ }
+
+ // XXX two
+ public void testServerDeleteQueueFailure() throws Exception
+ {
+ try
+ {
+ Connection conn = getConnection("test", "server", "guest");
+ Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+ conn.start();
+
+ // create kipper
+ Topic kipper = sess.createTopic("kipper");
+ TopicSubscriber subscriber = sess.createDurableSubscriber(kipper, "kipper");
+
+ subscriber.close();
+ sess.unsubscribe("kipper");
+
+ //Do something to show connection is active.
+ sess.rollback();
+ conn.close();
+ }
+ catch (JMSException e)
+ {
+ // XXX JMSException -> linedException = AMQException.403
+ check403Exception(e.getLinkedException());
}
}
public void testClientConsumeFromTempQueueValid() throws AMQException, URLSyntaxException, Exception
{
- setUpACLTest();
-
try
{
- Connection conn = getConnection("client", "guest");
+ Connection conn = getConnection("test", "client", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- sesh.createConsumer(sesh.createTemporaryQueue());
+ sess.createConsumer(sess.createTemporaryQueue());
conn.close();
}
@@ -217,64 +220,38 @@ public class SimpleACLTest extends QpidT
public void testClientConsumeFromNamedQueueInvalid() throws NamingException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
try
{
- Connection conn = getConnection("client", "guest");
-
- //Prevent Failover
- ((AMQConnection) conn).setConnectionListener(this);
-
- conn.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
+ Connection conn = getConnection("test", "client", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- sesh.createConsumer(sesh.createQueue("IllegalQueue"));
+ sess.createConsumer(sess.createQueue("IllegalQueue"));
+
+ conn.close();
+
fail("Test failed as consumer was created.");
- //conn will be automatically closed
}
catch (JMSException e)
{
- Throwable cause = e.getLinkedException();
-
- assertNotNull("There was no liked exception", cause);
- assertEquals("Wrong linked exception type", AMQAuthenticationException.class, cause.getClass());
- assertEquals("Incorrect error code received", 403, ((AMQAuthenticationException) cause).getErrorCode().getCode());
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for conneciton to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
+ check403Exception(e.getLinkedException());
}
}
public void testClientCreateTemporaryQueue() throws JMSException, URLSyntaxException, Exception
{
- setUpACLTest();
-
try
{
- Connection conn = getConnection("client", "guest");
+ Connection conn = getConnection("test", "client", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
//Create Temporary Queue - can't use the createTempQueue as QueueName is null.
- ((AMQSession) sesh).createQueue(new AMQShortString("doesnt_matter_as_autodelete_means_tmp"),
+ ((AMQSession<?, ?>) sess).createQueue(new AMQShortString("doesnt_matter_as_autodelete_means_tmp"),
true, false, false);
conn.close();
@@ -287,66 +264,43 @@ public class SimpleACLTest extends QpidT
public void testClientCreateNamedQueue() throws NamingException, JMSException, AMQException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
try
{
- Connection conn = getConnection("client", "guest");
+ Connection conn = getConnection("test", "client", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
-
- conn.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
//Create a Named Queue
- ((AMQSession) sesh).createQueue(new AMQShortString("IllegalQueue"), false, false, false);
-
+ ((AMQSession<?, ?>) sess).createQueue(new AMQShortString("IllegalQueue"), false, false, false);
+
fail("Test failed as Queue creation succeded.");
//conn will be automatically closed
}
- catch (AMQAuthenticationException amqe)
+ catch (AMQException e)
{
- amqe.printStackTrace();
- assertEquals("Incorrect error code thrown", 403, ((AMQAuthenticationException) amqe).getErrorCode().getCode());
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for conneciton to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
+ // XXX AMQException.403
+ check403Exception(e);
}
}
public void testClientPublishUsingTransactionSuccess() throws AMQException, URLSyntaxException, Exception
{
- setUpACLTest();
-
try
{
- Connection conn = getConnection("client", "guest");
-
- ((AMQConnection) conn).setConnectionListener(this);
+ Connection conn = getConnection("test", "client", "guest");
- Session sesh = conn.createSession(true, Session.SESSION_TRANSACTED);
+ Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
conn.start();
- MessageProducer sender = sesh.createProducer(sesh.createQueue("example.RequestQueue"));
+ MessageProducer sender = sess.createProducer(sess.createQueue("example.RequestQueue"));
- sender.send(sesh.createTextMessage("test"));
+ sender.send(sess.createTextMessage("test"));
//Send the message using a transaction as this will allow us to retrieve any errors that occur on the broker.
- sesh.commit();
+ sess.commit();
conn.close();
}
@@ -358,26 +312,22 @@ public class SimpleACLTest extends QpidT
public void testClientPublishValidQueueSuccess() throws AMQException, URLSyntaxException, Exception
{
- setUpACLTest();
-
try
{
- Connection conn = getConnection("client", "guest");
-
- ((AMQConnection) conn).setConnectionListener(this);
+ Connection conn = getConnection("test", "client", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- MessageProducer sender = ((AMQSession) sesh).createProducer(null);
+ MessageProducer sender = ((AMQSession<?, ?>) sess).createProducer(null);
- Queue queue = sesh.createQueue("example.RequestQueue");
+ Queue queue = sess.createQueue("example.RequestQueue");
// Send a message that we will wait to be sent, this should give the broker time to process the msg
// before we finish this test. Message is set !immed !mand as the queue is invalid so want to test ACLs not
// queue existence.
- ((org.apache.qpid.jms.MessageProducer) sender).send(queue, sesh.createTextMessage("test"),
+ ((org.apache.qpid.jms.MessageProducer) sender).send(queue, sess.createTextMessage("test"),
DeliveryMode.NON_PERSISTENT, 0, 0L, false, false, true);
conn.close();
@@ -390,31 +340,15 @@ public class SimpleACLTest extends QpidT
public void testClientPublishInvalidQueueSuccess() throws AMQException, URLSyntaxException, JMSException, NamingException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
try
{
- Connection conn = getConnection("client", "guest");
-
- ((AMQConnection) conn).setConnectionListener(this);
-
- conn.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
+ Connection conn = getConnection("test", "client", "guest");
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- MessageProducer sender = ((AMQSession) session).createProducer(null);
+ MessageProducer sender = ((AMQSession<?, ?>) session).createProducer(null);
Queue queue = session.createQueue("Invalid");
@@ -435,53 +369,27 @@ public class SimpleACLTest extends QpidT
fail("Close is not expected to succeed.");
}
+ catch (IllegalStateException e)
+ {
+ _logger.info("QPID-2345: Session became closed and we got that error rather than the authentication error.");
+ }
catch (JMSException e)
{
- Throwable cause = e.getLinkedException();
-
- if (cause == null)
- {
- e.printStackTrace(System.out);
- if (e instanceof IllegalStateException)
- {
- System.out.println("QPID-2345: Session became closed and we got that error rather than the authentication error.");
- }
- else
- {
- fail("JMS Exception of did not have cause.:" + e.getMessage());
- }
- }
- else
- {
- if (!(cause instanceof AMQAuthenticationException))
- {
- e.printStackTrace();
- }
- assertEquals("Incorrect exception", AMQAuthenticationException.class, cause.getClass());
- assertEquals("Incorrect error code thrown", 403, ((AMQAuthenticationException) cause).getErrorCode().getCode());
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for connection to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
- }
-
+ check403Exception(e.getLinkedException());
}
}
public void testServerConsumeFromNamedQueueValid() throws AMQException, URLSyntaxException, Exception
{
- setUpACLTest();
-
try
{
- Connection conn = getConnection("server", "guest");
+ Connection conn = getConnection("test", "server", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- sesh.createConsumer(sesh.createQueue("example.RequestQueue"));
+ sess.createConsumer(sess.createQueue("example.RequestQueue"));
conn.close();
}
@@ -493,116 +401,58 @@ public class SimpleACLTest extends QpidT
public void testServerConsumeFromNamedQueueInvalid() throws AMQException, URLSyntaxException, NamingException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
try
{
- Connection conn = getConnection("client", "guest");
-
- conn.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
+ Connection conn = getConnection("test", "client", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- sesh.createConsumer(sesh.createQueue("Invalid"));
+ sess.createConsumer(sess.createQueue("Invalid"));
+
+ conn.close();
fail("Test failed as consumer was created.");
- //conn will be automatically closed
}
catch (JMSException e)
{
- Throwable cause = e.getLinkedException();
-
- assertNotNull("There was no liked exception", cause);
- assertEquals("Wrong linked exception type", AMQAuthenticationException.class, cause.getClass());
- assertEquals("Incorrect error code received", 403, ((AMQAuthenticationException) cause).getErrorCode().getCode());
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for conneciton to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
+ check403Exception(e.getLinkedException());
}
}
public void testServerConsumeFromTemporaryQueue() throws AMQException, URLSyntaxException, NamingException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
try
{
- Connection conn = getConnection("server", "guest");
-
- conn.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
+ Connection conn = getConnection("test", "server", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- sesh.createConsumer(sesh.createTemporaryQueue());
+ sess.createConsumer(sess.createTemporaryQueue());
+
fail("Test failed as consumer was created.");
- //conn will be automatically closed
}
catch (JMSException e)
{
- Throwable cause = e.getLinkedException();
-
- assertNotNull("There was no liked exception", cause);
- assertEquals("Wrong linked exception type", AMQAuthenticationException.class, cause.getClass());
- assertEquals("Incorrect error code received", 403, ((AMQAuthenticationException) cause).getErrorCode().getCode());
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for conneciton to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
+ check403Exception(e.getLinkedException());
}
}
- @Override
- public Connection getConnection(String username, String password) throws NamingException, JMSException
- {
- AMQConnection connection = (AMQConnection) super.getConnection(username, password);
-
- //Prevent Failover
- connection.setConnectionListener(this);
-
- return (Connection) connection;
- }
-
public void testServerCreateNamedQueueValid() throws JMSException, URLSyntaxException, Exception
{
- setUpACLTest();
-
try
{
- Connection conn = getConnection("server", "guest");
+ Connection conn = getConnection("test", "server", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
//Create Temporary Queue
- ((AMQSession) sesh).createQueue(new AMQShortString("example.RequestQueue"), false, false, false);
+ ((AMQSession<?, ?>) sess).createQueue(new AMQShortString("example.RequestQueue"), false, false, false);
conn.close();
}
@@ -614,65 +464,30 @@ public class SimpleACLTest extends QpidT
public void testServerCreateNamedQueueInvalid() throws JMSException, URLSyntaxException, AMQException, NamingException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
try
{
- Connection conn = getConnection("server", "guest");
-
- conn.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
+ Connection conn = getConnection("test", "server", "guest");
- Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
//Create a Named Queue
- ((AMQSession) sesh).createQueue(new AMQShortString("IllegalQueue"), false, false, false);
+ ((AMQSession<?, ?>) sess).createQueue(new AMQShortString("IllegalQueue"), false, false, false);
fail("Test failed as creation succeded.");
- //conn will be automatically closed
}
- catch (AMQAuthenticationException amqe)
+ catch (Exception e)
{
- assertEquals("Incorrect error code thrown", 403, amqe.getErrorCode().getCode());
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for conneciton to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
+ check403Exception(e);
}
}
public void testServerCreateTemporaryQueueInvalid() throws NamingException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
- Connection conn = getConnection("server", "guest");
try
{
-
- conn.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
-
+ Connection conn = getConnection("test", "server", "guest");
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
@@ -683,69 +498,28 @@ public class SimpleACLTest extends QpidT
}
catch (JMSException e)
{
- Throwable cause = e.getLinkedException();
-
- assertNotNull("There was no liked exception", cause);
- assertEquals("Wrong linked exception type", AMQAuthenticationException.class, cause.getClass());
- assertEquals("Incorrect error code received", 403, ((AMQAuthenticationException) cause).getErrorCode().getCode());
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for conneciton to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
- }
- finally
- {
- try
- {
- conn.close();
- }
- catch (Exception e)
- {
- // This normally fails because we are denied
- }
+ check403Exception(e.getLinkedException());
}
}
-
+
public void testServerCreateAutoDeleteQueueInvalid() throws NamingException, JMSException, AMQException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
- Connection connection = null;
try
{
- connection = getConnection("server", "guest");
-
- connection.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
+ Connection connection = getConnection("test", "server", "guest");
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
- ((AMQSession) session).createQueue(new AMQShortString("again_ensure_auto_delete_queue_for_temporary"),
+ ((AMQSession<?, ?>) session).createQueue(new AMQShortString("again_ensure_auto_delete_queue_for_temporary"),
true, false, false);
fail("Test failed as creation succeded.");
- //connection will be automatically closed
}
- catch (AMQAuthenticationException amqe)
+ catch (Exception e)
{
- assertEquals("Incorrect error code thrown", 403, amqe.getErrorCode().getCode());
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for conneciton to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
+ check403Exception(e);
}
}
@@ -759,12 +533,8 @@ public class SimpleACLTest extends QpidT
*/
public void testServerPublishUsingTransactionSuccess() throws AMQException, URLSyntaxException, JMSException, NamingException, Exception
{
- setUpACLTest();
-
//Set up the Server
- Connection serverConnection = getConnection("server", "guest");
-
- ((AMQConnection) serverConnection).setConnectionListener(this);
+ Connection serverConnection = getConnection("test", "server", "guest");
Session serverSession = serverConnection.createSession(true, Session.SESSION_TRANSACTED);
@@ -775,7 +545,7 @@ public class SimpleACLTest extends QpidT
serverConnection.start();
//Set up the consumer
- Connection clientConnection = getConnection("client", "guest");
+ Connection clientConnection = getConnection("test", "client", "guest");
//Send a test mesage
Session clientSession = clientConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -841,23 +611,9 @@ public class SimpleACLTest extends QpidT
public void testServerPublishInvalidQueueSuccess() throws AMQException, URLSyntaxException, JMSException, NamingException, Exception
{
- setUpACLTest();
-
- //QPID-2081: use a latch to sync on exception causing connection close, to work
- //around the connection close race during tearDown() causing sporadic failures
- final CountDownLatch exceptionReceived = new CountDownLatch(1);
-
try
{
- Connection conn = getConnection("server", "guest");
-
- conn.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exceptionReceived.countDown();
- }
- });
+ Connection conn = getConnection("test", "server", "guest");
((AMQConnection) conn).setConnectionListener(this);
@@ -865,7 +621,7 @@ public class SimpleACLTest extends QpidT
conn.start();
- MessageProducer sender = ((AMQSession) session).createProducer(null);
+ MessageProducer sender = ((AMQSession<?, ?>) session).createProducer(null);
Queue queue = session.createQueue("Invalid");
@@ -886,63 +642,13 @@ public class SimpleACLTest extends QpidT
fail("Close is not expected to succeed.");
}
+ catch (IllegalStateException e)
+ {
+ _logger.info("QPID-2345: Session became closed and we got that error rather than the authentication error.");
+ }
catch (JMSException e)
{
- Throwable cause = e.getLinkedException();
-
- if (cause == null)
- {
- e.printStackTrace(System.out);
- if (e instanceof IllegalStateException)
- {
- System.out.println("QPID-2345: Session became closed and we got that error rather than the authentication error.");
- }
- else
- {
- fail("JMS Exception of did not have cause.:" + e.getMessage());
- }
- }
- else if (!(cause instanceof AMQAuthenticationException))
- {
- cause.printStackTrace(System.out);
- assertEquals("Incorrect exception", IllegalStateException.class, cause.getClass());
- System.out.println("QPID-2345: Session became closed and we got that error rather than the authentication error.");
- }
- else
- {
- assertEquals("Incorrect exception", AMQAuthenticationException.class, cause.getClass());
- assertEquals("Incorrect error code thrown", 403, ((AMQAuthenticationException) cause).getErrorCode().getCode());
- }
-
- //use the latch to ensure the control thread waits long enough for the exception thread
- //to have done enough to mark the connection closed before teardown commences
- assertTrue("Timed out waiting for conneciton to report close",
- exceptionReceived.await(2, TimeUnit.SECONDS));
+ check403Exception(e.getLinkedException());
}
}
-
- // Connection Listener Interface - Used here to block failover
-
- public void bytesSent(long count)
- {
- }
-
- public void bytesReceived(long count)
- {
- }
-
- public boolean preFailover(boolean redirect)
- {
- //Prevent failover.
- return false;
- }
-
- public boolean preResubscribe()
- {
- return false;
- }
-
- public void failoverComplete()
- {
- }
}
Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java?rev=949781&r1=949780&r2=949781&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java Mon May 31 16:03:41 2010
@@ -1,6 +1,4 @@
-package org.apache.qpid.server.security.firewall;
/*
- *
* 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
@@ -17,9 +15,8 @@ package org.apache.qpid.server.security.
* 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.firewall;
import java.io.File;
import java.io.FileWriter;
@@ -85,7 +82,7 @@ public class FirewallConfigTest extends
}
out.close();
}
-
+
public void testVhostAllowBrokerDeny() throws Exception
{
if (_broker.equals(VM))
@@ -104,8 +101,7 @@ public class FirewallConfigTest extends
{
//Try to get a connection to the 'test2' vhost
//This is expected to fail as it is denied at the broker level
- conn = getConnection(new AMQConnectionURL(
- "amqp://username:password@clientid/test2?brokerlist='" + getBroker() + "'"));
+ conn = getConnection(new AMQConnectionURL("amqp://username:password@clientid/test2?brokerlist='" + getBroker() + "'"));
fail("We expected the connection to fail");
}
catch (JMSException e)
@@ -235,7 +231,7 @@ public class FirewallConfigTest extends
}
);
}
-
+
public void testDenyOnReloadInVhost() throws Exception
{
testDeny(true, new Runnable() {
@@ -259,7 +255,7 @@ public class FirewallConfigTest extends
{
testFirewall(true, inVhost, restartOrReload);
}
-
+
/*
* Check we can get a connection
*/
@@ -278,7 +274,7 @@ public class FirewallConfigTest extends
return conn != null;
}
-
+
private void testFirewall(boolean initial, boolean inVhost, Runnable restartOrReload) throws Exception
{
if (_broker.equals(VM))
Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java?rev=949781&r1=949780&r2=949781&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java Mon May 31 16:03:41 2010
@@ -147,13 +147,13 @@ public class TopicSessionTest extends Qp
public void testUnsubscriptionAfterConnectionClose() throws Exception
{
- AMQConnection con1 = (AMQConnection) getConnection("guest", "guest", "clientid");
+ AMQConnection con1 = (AMQConnection) getClientConnection("guest", "guest", "clientid");
AMQTopic topic = new AMQTopic(con1, "MyTopic3");
TopicSession session1 = con1.createTopicSession(true, AMQSession.AUTO_ACKNOWLEDGE);
TopicPublisher publisher = session1.createPublisher(topic);
- AMQConnection con2 = (AMQConnection) getConnection("guest", "guest", "clientid");
+ AMQConnection con2 = (AMQConnection) getClientConnection("guest", "guest", "clientid");
TopicSession session2 = con2.createTopicSession(true, AMQSession.AUTO_ACKNOWLEDGE);
TopicSubscriber sub = session2.createDurableSubscriber(topic, "subscription0");
@@ -167,7 +167,7 @@ public class TopicSessionTest extends Qp
con2.close();
publisher.publish(session1.createTextMessage("Hello2"));
session1.commit();
- con2 = (AMQConnection) getConnection("guest", "guest", "clientid");
+ con2 = (AMQConnection) getClientConnection("guest", "guest", "clientid");
session2 = con2.createTopicSession(true, AMQSession.NO_ACKNOWLEDGE);
sub = session2.createDurableSubscriber(topic, "subscription0");
con2.start();
@@ -367,7 +367,7 @@ public class TopicSessionTest extends Qp
m = (TextMessage) noLocal.receive(100);
assertNull(m);
- AMQConnection con2 = (AMQConnection) getConnection("guest", "guest", "foo");
+ AMQConnection con2 = (AMQConnection) getClientConnection("guest", "guest", "foo");
TopicSession session2 = con2.createTopicSession(true, AMQSession.AUTO_ACKNOWLEDGE);
TopicPublisher publisher2 = session2.createPublisher(topic);
Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java?rev=949781&r1=949780&r2=949781&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java Mon May 31 16:03:41 2010
@@ -20,23 +20,28 @@
*/
package org.apache.qpid.test.utils;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.commands.objects.AllObjects;
-import org.apache.qpid.management.common.JMXConnnectionFactory;
-import org.apache.qpid.management.common.mbeans.ManagedBroker;
-import org.apache.qpid.management.common.mbeans.ManagedExchange;
+import java.io.IOException;
+import java.util.Set;
import javax.management.JMException;
import javax.management.MBeanException;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
import javax.management.remote.JMXConnector;
-import java.io.IOException;
-import java.util.Set;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.commands.objects.AllObjects;
+import org.apache.qpid.management.common.JMXConnnectionFactory;
+import org.apache.qpid.management.common.mbeans.ManagedBroker;
+import org.apache.qpid.management.common.mbeans.ManagedExchange;
+import org.apache.qpid.management.common.mbeans.LoggingManagement;
+import org.apache.qpid.management.common.mbeans.ConfigurationManagement;
+import org.apache.qpid.management.common.mbeans.UserManagement;
/**
- *
+ * JMX access for tests.
*/
public class JMXTestUtils
{
@@ -61,9 +66,8 @@ public class JMXTestUtils
public void open() throws Exception
{
- _jmxc = JMXConnnectionFactory.getJMXConnection(
- 5000, "127.0.0.1",
- _test.getManagementPort(_test.getPort()), USER, PASSWORD);
+ _jmxc = JMXConnnectionFactory.getJMXConnection(5000, "127.0.0.1",
+ _test.getManagementPort(_test.getPort()), USER, PASSWORD);
_mbsc = _jmxc.getMBeanServerConnection();
}
@@ -77,12 +81,11 @@ public class JMXTestUtils
}
/**
- * Create a non-durable test exchange with the current test name
+ * Create a non-durable exchange with the requested name
*
- * @throws javax.management.JMException - is thrown if a exchange with this testName already exists
- * @throws java.io.IOException - if there is a problem with the JMX Connection
- * @throws javax.management.MBeanException
- * - if there is another problem creating the exchange
+ * @throws JMException if a exchange with this name already exists
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException if there is another problem creating the exchange
*/
public void createExchange(String virtualHostName, String name, String type, boolean durable)
throws JMException, IOException, MBeanException
@@ -96,24 +99,134 @@ public class JMXTestUtils
* Create a non-durable queue (with no owner) that is named after the
* creating test.
*
- * @throws JMException - is thrown if a queue with this testName already exists
- * @throws IOException - if there is a problem with the JMX Connection
+ * @throws JMException if a queue with this name already exists
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException if there is another problem creating the exchange
*/
public void createQueue(String virtualHostName, String name, String owner, boolean durable)
- throws JMException, IOException
+ throws JMException, MBeanException, IOException
{
ManagedBroker managedBroker = getManagedBroker(virtualHostName);
managedBroker.createNewQueue(name, owner, durable);
}
+
+ /**
+ * Unregisters all the channels, queuebindings etc and unregisters
+ * this exchange from managed objects.
+ *
+ * @throws JMException if an exchange with this name does not exist
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException if there is another problem creating the exchange
+ */
+ public void unregisterExchange(String virtualHostName, String exchange)
+ throws IOException, JMException, MBeanException
+ {
+ ManagedBroker managedBroker = getManagedBroker(virtualHostName);
+
+ managedBroker.unregisterExchange(exchange);
+ }
+
+ /**
+ * Unregisters the Queue bindings, removes the subscriptions and unregisters
+ * from the managed objects.
+ *
+ * @throws JMException if a queue with this name does not exist
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException if there is another problem creating the exchange
+ */
+ public void deleteQueue(String virtualHostName, String queueName)
+ throws IOException, JMException, MBeanException
+ {
+ ManagedBroker managedBroker = getManagedBroker(virtualHostName);
+ managedBroker.deleteQueue(queueName);
+ }
+
+ /**
+ * Sets the logging level.
+ *
+ * @throws JMException
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException
+ */
+ public void setRuntimeLoggerLevel(String logger, String level)
+ throws IOException, JMException, MBeanException
+ {
+ LoggingManagement loggingManagement = getLoggingManagement();
+
+ loggingManagement.setRuntimeLoggerLevel(logger, level);
+ }
+
+ /**
+ * Reload logging config file.
+ *
+ * @throws JMException
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException
+ */
+ public void reloadConfigFile()
+ throws IOException, JMException, MBeanException
+ {
+ LoggingManagement loggingManagement = getLoggingManagement();
+
+ loggingManagement.reloadConfigFile();
+ }
+
+ /**
+ * Get list of available logger levels.
+ *
+ * @throws JMException
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException
+ */
+ public String[] getAvailableLoggerLevels()
+ throws IOException, JMException, MBeanException
+ {
+ LoggingManagement loggingManagement = getLoggingManagement();
+
+ return loggingManagement.getAvailableLoggerLevels();
+ }
+
+ /**
+ * Set root logger level.
+ *
+ * @throws JMException
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException
+ */
+ public void setRuntimeRootLoggerLevel(String level)
+ throws IOException, JMException, MBeanException
+ {
+ LoggingManagement loggingManagement = getLoggingManagement();
+
+ loggingManagement.setRuntimeRootLoggerLevel(level);
+ }
+
+ /**
+ * Get root logger level.
+ *
+ * @throws JMException
+ * @throws IOException if there is a problem with the JMX Connection
+ * @throws MBeanException
+ */
+ public String getRuntimeRootLoggerLevel()
+ throws IOException, JMException, MBeanException
+ {
+ LoggingManagement loggingManagement = getLoggingManagement();
+
+ return loggingManagement.getRuntimeRootLoggerLevel();
+ }
+
/**
- * Retrive the ObjectName for the test Virtualhost.
+ * Retrive the ObjectName for a Virtualhost.
*
- * This is then use to create aproxy to the ManagedBroker MBean.
+ * This is then used to create a proxy to the ManagedBroker MBean.
*
- * @return the ObjectName for the 'test' VirtualHost.
+ * @param virtualHostName the VirtualHost to retrieve
+ * @return the ObjectName for the VirtualHost
*/
+ @SuppressWarnings("static-access")
public ObjectName getVirtualHostManagerObjectName(String vhostName)
{
// Get the name of the test manager
@@ -126,18 +239,21 @@ public class JMXTestUtils
_test.assertEquals("Incorrect number test vhosts returned", 1, objectNames.size());
// We have verified we have only one value in objectNames so return it
- return objectNames.iterator().next();
+ ObjectName objectName = objectNames.iterator().next();
+ _test.getLogger().info("Loading: " + objectName);
+ return objectName;
}
/**
- * Retrive the ObjectName for the given Exchange on the test Virtualhost.
+ * Retrive the ObjectName for the given Queue on a Virtualhost.
*
- * This is then use to create aproxy to the ManagedExchange MBean.
+ * This is then used to create a proxy to the ManagedQueue MBean.
*
- * @param queue The exchange to retireve e.g. 'direct'
- *
- * @return the ObjectName for the given exchange on the test VirtualHost.
+ * @param virtualHostName the VirtualHost the Queue is on
+ * @param queue The Queue to retireve
+ * @return the ObjectName for the given queue on the VirtualHost
*/
+ @SuppressWarnings("static-access")
public ObjectName getQueueObjectName(String virtualHostName, String queue)
{
// Get the name of the test manager
@@ -151,19 +267,21 @@ public class JMXTestUtils
"' returned", 1, objectNames.size());
// We have verified we have only one value in objectNames so return it
- return objectNames.iterator().next();
+ ObjectName objectName = objectNames.iterator().next();
+ _test.getLogger().info("Loading: " + objectName);
+ return objectName;
}
/**
- * Retrive the ObjectName for the given Exchange on the test Virtualhost.
+ * Retrive the ObjectName for the given Exchange on a VirtualHost.
*
- * This is then use to create aproxy to the ManagedExchange MBean.
+ * This is then used to create a proxy to the ManagedExchange MBean.
*
- * @param virtualHostName
- * @param exchange The exchange to retireve e.g. 'direct'
- *
- * @return the ObjectName for the given exchange on the test VirtualHost.
+ * @param virtualHostName the VirtualHost the Exchange is on
+ * @param exchange the Exchange to retireve e.g. 'direct'
+ * @return the ObjectName for the given Exchange on the VirtualHost
*/
+ @SuppressWarnings("static-access")
public ObjectName getExchangeObjectName(String virtualHostName, String exchange)
{
// Get the name of the test manager
@@ -173,13 +291,15 @@ public class JMXTestUtils
Set<ObjectName> objectNames = allObject.returnObjects();
_test.assertNotNull("Null ObjectName Set returned", objectNames);
- _test.assertEquals("Incorrect number of exchange with name '" + exchange +
- "' returned", 1, objectNames.size());
+ _test.assertEquals("Incorrect number of exchange with name '" + exchange + "' returned", 1, objectNames.size());
// We have verified we have only one value in objectNames so return it
- return objectNames.iterator().next();
+ ObjectName objectName = objectNames.iterator().next();
+ _test.getLogger().info("Loading: " + objectName);
+ return objectName;
}
+ @SuppressWarnings("static-access")
public <T> T getManagedObject(Class<T> managedClass, String queryString)
{
AllObjects allObject = new AllObjects(_mbsc);
@@ -191,25 +311,41 @@ public class JMXTestUtils
_test.assertEquals("More than one " + managedClass + " returned", 1, objectNames.size());
ObjectName objectName = objectNames.iterator().next();
-
+ _test.getLogger().info("Loading: " + objectName);
return getManagedObject(managedClass, objectName);
}
public <T> T getManagedObject(Class<T> managedClass, ObjectName objectName)
{
- return MBeanServerInvocationHandler.
- newProxyInstance(_mbsc, objectName, managedClass, false);
+ return MBeanServerInvocationHandler.newProxyInstance(_mbsc, objectName, managedClass, false);
}
public ManagedBroker getManagedBroker(String virtualHost)
{
- return getManagedObject(ManagedBroker.class, getVirtualHostManagerObjectName(virtualHost).toString());
+ return getManagedObject(ManagedBroker.class, getVirtualHostManagerObjectName(virtualHost));
}
-
+
public ManagedExchange getManagedExchange(String exchangeName)
{
- return MBeanServerInvocationHandler.
- newProxyInstance(_mbsc, getExchangeObjectName("test", exchangeName),
- ManagedExchange.class, false);
+ ObjectName objectName = getExchangeObjectName("test", exchangeName);
+ return MBeanServerInvocationHandler.newProxyInstance(_mbsc, objectName, ManagedExchange.class, false);
+ }
+
+ public LoggingManagement getLoggingManagement() throws MalformedObjectNameException
+ {
+ ObjectName objectName = new ObjectName("org.apache.qpid:type=LoggingManagement,name=LoggingManagement");
+ return getManagedObject(LoggingManagement.class, objectName);
+ }
+
+ public ConfigurationManagement getConfigurationManagement() throws MalformedObjectNameException
+ {
+ ObjectName objectName = new ObjectName("org.apache.qpid:type=ConfigurationManagement,name=ConfigurationManagement");
+ return getManagedObject(ConfigurationManagement.class, objectName);
+ }
+
+ public UserManagement getUserManagement() throws MalformedObjectNameException
+ {
+ ObjectName objectName = new ObjectName("org.apache.qpid:type=UserManagement,name=UserManagement");
+ return getManagedObject(UserManagement.class, objectName);
}
}
Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java?rev=949781&r1=949780&r2=949781&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java Mon May 31 16:03:41 2010
@@ -56,6 +56,7 @@ import junit.framework.TestResult;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnection;
@@ -71,26 +72,23 @@ import org.apache.qpid.server.registry.C
import org.apache.qpid.server.store.DerbyMessageStore;
import org.apache.qpid.url.URLSyntaxException;
import org.apache.qpid.util.LogMonitor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
- *
- *
+ * Qpid base class for system testing test cases.
*/
public class QpidTestCase extends TestCase
{
protected final String QpidHome = System.getProperty("QPID_HOME");
protected File _configFile = new File(System.getProperty("broker.config"));
- protected static final Logger _logger = LoggerFactory.getLogger(QpidTestCase.class);
+ protected static final Logger _logger = Logger.getLogger(QpidTestCase.class);
protected static final int LOGMONITOR_TIMEOUT = 5000;
protected long RECEIVE_TIMEOUT = 1000l;
private Map<String, String> _propertiesSetForTestOnly = new HashMap<String, String>();
private Map<String, String> _propertiesSetForBroker = new HashMap<String, String>();
- private Map<org.apache.log4j.Logger, Level> _loggerLevelSetForTest = new HashMap<org.apache.log4j.Logger, Level>();
+ private Map<Logger, Level> _loggerLevelSetForTest = new HashMap<Logger, Level>();
private XMLConfiguration _testConfiguration = new XMLConfiguration();
private XMLConfiguration _testVirtualhosts = new XMLConfiguration();
@@ -98,7 +96,6 @@ public class QpidTestCase extends TestCa
protected static final String INDEX = "index";
protected static final String CONTENT = "content";
-
/**
* Some tests are excluded when the property test.excludes is set to true.
* An exclusion list is either a file (prop test.excludesfile) which contains one test name
@@ -198,10 +195,10 @@ public class QpidTestCase extends TestCa
private String _brokerClean = System.getProperty(BROKER_CLEAN, null);
private Boolean _brokerCleanBetweenTests = Boolean.getBoolean(BROKER_CLEAN_BETWEEN_TESTS);
private String _brokerVersion = System.getProperty(BROKER_VERSION, VERSION_08);
- private String _output = System.getProperty(TEST_OUTPUT);
+ protected String _output = System.getProperty(TEST_OUTPUT);
protected Boolean _brokerPersistent = Boolean.getBoolean(BROKER_PERSITENT);
- private static String _brokerLogPrefix = System.getProperty(BROKER_LOG_PREFIX,"BROKER: ");
+ protected static String _brokerLogPrefix = System.getProperty(BROKER_LOG_PREFIX,"BROKER: ");
protected static boolean _interleaveBrokerLog = Boolean.getBoolean(BROKER_LOG_INTERLEAVE);
protected File _outputFile;
@@ -210,10 +207,10 @@ public class QpidTestCase extends TestCa
protected Map<Integer, Process> _brokers = new HashMap<Integer, Process>();
- private InitialContext _initialContext;
+ protected InitialContext _initialContext;
protected AMQConnectionFactory _connectionFactory;
- private String _testName;
+ protected String _testName;
// the connections created for a given test
protected List<Connection> _connections = new ArrayList<Connection>();
@@ -248,6 +245,11 @@ public class QpidTestCase extends TestCa
{
this("QpidTestCase");
}
+
+ public Logger getLogger()
+ {
+ return QpidTestCase._logger;
+ }
public void runBare() throws Throwable
{
@@ -287,6 +289,11 @@ public class QpidTestCase extends TestCa
{
super.runBare();
}
+ catch (Exception e)
+ {
+ _logger.error("exception", e);
+ throw e;
+ }
finally
{
try
@@ -935,7 +942,7 @@ public class QpidTestCase extends TestCa
* @param logger the logger to change
* @param level the level to set
*/
- protected void setLoggerLevel(org.apache.log4j.Logger logger, Level level)
+ protected void setLoggerLevel(Logger logger, Level level)
{
assertNotNull("Cannot set level of null logger", logger);
assertNotNull("Cannot set Logger("+logger.getName()+") to null level.",level);
@@ -954,7 +961,7 @@ public class QpidTestCase extends TestCa
*/
protected void revertLoggingLevels()
{
- for (org.apache.log4j.Logger logger : _loggerLevelSetForTest.keySet())
+ for (Logger logger : _loggerLevelSetForTest.keySet())
{
logger.setLevel(_loggerLevelSetForTest.get(logger));
}
@@ -1079,7 +1086,8 @@ public class QpidTestCase extends TestCa
public Connection getConnection(ConnectionURL url) throws JMSException
{
- Connection connection = new AMQConnectionFactory(url).createConnection("guest", "guest");
+ _logger.info(url.getURL());
+ Connection connection = new AMQConnectionFactory(url).createConnection(url.getUsername(), url.getPassword());
_connections.add(connection);
@@ -1098,14 +1106,14 @@ public class QpidTestCase extends TestCa
*/
public Connection getConnection(String username, String password) throws JMSException, NamingException
{
- _logger.info("get Connection");
+ _logger.info("get connection");
Connection con = getConnectionFactory().createConnection(username, password);
//add the connection in the lis of connections
_connections.add(con);
return con;
}
- public Connection getConnection(String username, String password, String id) throws JMSException, URLSyntaxException, AMQException, NamingException
+ public Connection getClientConnection(String username, String password, String id) throws JMSException, URLSyntaxException, AMQException, NamingException
{
_logger.info("get Connection");
Connection con;
@@ -1382,10 +1390,19 @@ public class QpidTestCase extends TestCa
/*
* Sigh, this is going to get messy. grep for BRKR and the port number
*/
-
- Process p = Runtime.getRuntime().exec("/usr/bin/pgrep -f " + getPort(port));
+ String osName = System.getProperty("os.name");
+ boolean osx = osName.equals("Mac OS X");
+
+ String cmd = osx ? "/usr/sbin/lsof -i TCP:%d -Fp" : "/usr/bin/pgrep -f %d";
+ Process p = Runtime.getRuntime().exec(String.format(cmd, getPort(port)));
BufferedReader reader = new BufferedReader (new InputStreamReader(p.getInputStream()));
- String cmd = "/bin/kill -SIGHUP " + reader.readLine();
+ String pid = reader.readLine();
+ while (reader.ready())
+ {
+ pid = reader.readLine();
+ }
+
+ cmd = "/bin/kill -SIGHUP " + (osx ? pid.substring(1) : pid);
p = Runtime.getRuntime().exec(cmd);
LogMonitor _monitor = new LogMonitor(_outputFile);
Modified: qpid/trunk/qpid/java/test-profiles/CPPExcludes
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/CPPExcludes?rev=949781&r1=949780&r2=949781&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/CPPExcludes (original)
+++ qpid/trunk/qpid/java/test-profiles/CPPExcludes Mon May 31 16:03:41 2010
@@ -1,9 +1,14 @@
org.apache.qpid.test.unit.client.channelclose.ChannelCloseTest#*
org.apache.qpid.client.ResetMessageListenerTest#*
+//These tests will not work until 0-10 exception halding is fixed
+org.apache.qpid.server.security.acl.*
+
//These tests are for the java broker
-org.apache.qpid.server.security.acl.SimpleACLTest#*
+org.apache.qpid.server.security.access.plugins.*
+org.apache.qpid.server.security.access.*
org.apache.qpid.server.security.firewall.FirewallConfigTest#*
+org.apache.qpid.server.security.firewall.FirewallConfigurationTest#*
org.apache.qpid.server.plugins.PluginTest#*
org.apache.qpid.server.BrokerStartupTest#*
Modified: qpid/trunk/qpid/java/test-profiles/JavaInVMExcludes
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/JavaInVMExcludes?rev=949781&r1=949780&r2=949781&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/JavaInVMExcludes (original)
+++ qpid/trunk/qpid/java/test-profiles/JavaInVMExcludes Mon May 31 16:03:41 2010
@@ -16,3 +16,6 @@ org.apache.qpid.test.unit.ack.RecoverTes
// related to QPID-2471. These are new test cases and fail with the Java broker.
org.apache.qpid.test.unit.ack.RecoverTest#testOderingWithAsyncConsumer
org.apache.qpid.test.unit.ack.RecoverTest#testOderingWithSyncConsumer
+
+//The VM broker does not export the logging management JMX MBean
+org.apache.qpid.server.security.acl.ExternalAdminACLTest#*
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org