diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2009-08-06 09:29:07 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2009-08-06 09:29:07 +0000 |
| commit | bb4f5e794da724e2d971a6c2813c71dbdfe747cc (patch) | |
| tree | 5a65d5f371eff6e1e5f9ad0c5c37321d62077f96 | |
| parent | cf1d99773dbfb66c7d0b3c141530b01b69fa0576 (diff) | |
| download | qpid-python-bb4f5e794da724e2d971a6c2813c71dbdfe747cc.tar.gz | |
QPID-2002 : Add Queue Logging Tests.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@801564 13f79535-47bb-0310-9956-ffa450edef68
5 files changed, 568 insertions, 3 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java index 47a0a1d830..763a0506e3 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java @@ -160,10 +160,9 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener // Extract the number of priorities for this Queue. // Leave it as 0 if we are a SimpleQueueEntryList int priorities = 0; - if (entryListFactory instanceof PriorityQueueList) + if (entryListFactory instanceof PriorityQueueList.Factory) { - PriorityQueueList priorityFactory = (PriorityQueueList) entryListFactory; - priorities = priorityFactory.getPriorities(); + priorities = ((PriorityQueueList)_entries).getPriorities(); } // Log the creation of this Queue. @@ -1165,6 +1164,10 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener _deleteTaskList.clear(); stop(); + + //Log Queue Deletion + CurrentActor.get().message(_logSubject, QueueMessages.QUE_1002()); + } return getMessageCount(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java index 82c53aefa7..c5a2f499f0 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java @@ -175,6 +175,20 @@ public class AbstractTestLogging extends QpidTestCase } /** + * Return the message String from the given message section + * @param log the Message Section + * @return the Message String. + */ + protected String getMessageString(String log) + { + // Remove the Log ID from the returned String + int start = log.indexOf(":") + 1; + + return log.substring(start).trim(); + } + + + /** * Given our log message extract the connection ID: * * The log string will contain the connectionID identified by 'con:' diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java new file mode 100644 index 0000000000..b83c284ef4 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java @@ -0,0 +1,346 @@ +/* + * + * 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.logging; + +import org.apache.qpid.AMQException; +import org.apache.qpid.client.AMQSession; +import org.apache.qpid.framing.AMQShortString; + +import javax.jms.Connection; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Session; +import javax.naming.NamingException; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * The Queue test suite validates that the follow log messages as specified in + * the Functional Specification. + * + * This suite of tests validate that the Queue messages occur correctly and + * according to the following format: + * + * QUE-1001 : Create : [AutoDelete] [Durable|Transient] [Priority:<levels>] [Owner:<name>] + */ +public class DurableQueueLoggingTest extends AbstractTestLogging +{ + + protected String DURABLE = "Durable"; + protected String TRANSIENT = "Transient"; + protected boolean _durable; + + protected Connection _connection; + protected Session _session; + private static final String QUEUE_PREFIX = "QUE-"; + + public void setUp() throws Exception + { + super.setUp(); + _connection = getConnection(); + _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + _durable = true; + //Ensure we only have logs from our + _monitor.reset(); + } + + /** + * Description: + * When a simple transient queue is created then a QUE-1001 create message + * is expected to be logged. + * Input: + * 1. Running broker + * 2. Persistent Queue is created from a client + * Output: + * + * <date> QUE-1001 : Create : Owner: '<name>' Durable + * + * Validation Steps: + * 3. The QUE ID is correct + * 4. The Durable tag is present in the message + * 5. The Owner is as expected + * + * @throws javax.jms.JMSException + * @throws javax.naming.NamingException + * @throws java.io.IOException + */ + public void testQueueCreateDurableExclusive() throws NamingException, JMSException, IOException + { + // To force a queue Creation Event we need to create a consumer. + Queue queue = (Queue) _session.createQueue("direct://amq.direct/testQueue/testQueue?durable='"+_durable+"'&exclusive='true'"); + + _session.createConsumer(queue); + + // Validation + List<String> results = _monitor.findMatches(QUEUE_PREFIX); + + // Only 1 Queue message should hav been logged + assertEquals("Result set size not as expected", 1, results.size()); + + String log = getLog(results.get(0)); + + // Message Should be a QUE-1001 + validateMessageID("QUE-1001", log); + + // Queue is Durable + assertEquals(DURABLE + " keyword not correct in log entry", + _durable, fromMessage(log).contains(DURABLE)); + + assertEquals(TRANSIENT + " keyword not correct in log entry.", + !_durable, fromMessage(log).contains(TRANSIENT)); + + assertTrue("Queue does not have correct owner value:" + fromMessage(log), + fromMessage(log).contains("Owner: " + _connection.getClientID())); + } + + /** + * Description: + * When a simple transient queue is created then a QUE-1001 create message + * is expected to be logged. + * Input: + * 1. Running broker + * 2. Persistent Queue is created from a client + * Output: + * + * <date> QUE-1001 : Create : Owner: '<name>' Durable + * + * Validation Steps: + * 3. The QUE ID is correct + * 4. The Durable tag is present in the message + * 5. The Owner is as expected + * + * @throws javax.jms.JMSException + * @throws javax.naming.NamingException + * @throws java.io.IOException + */ + public void testQueueCreateDurable() throws NamingException, JMSException, IOException + { + // To force a queue Creation Event we need to create a consumer. + + Queue queue = (Queue) _session.createQueue("direct://amq.direct/testQueue/testQueue?durable='"+_durable+"'"); + + _session.createConsumer(queue); + + // Validation + List<String> results = _monitor.findMatches(QUEUE_PREFIX); + + // Only 1 Queue message should hav been logged + assertEquals("Result set size not as expected", 1, results.size()); + + String log = getLog(results.get(0)); + + // Message Should be a QUE-1001 + validateMessageID("QUE-1001", log); + + // Queue is Durable + assertEquals(DURABLE + " keyword not correct in log entry", + _durable, fromMessage(log).contains(DURABLE)); + + assertEquals(TRANSIENT + " keyword not correct in log entry.", + !_durable, fromMessage(log).contains(TRANSIENT)); + + assertTrue("Queue does not have correct owner value:" + fromMessage(log), + fromMessage(log).contains("Owner: null")); + } + + /** + * Description: + * When a simple transient queue is created then a QUE-1001 create message + * is expected to be logged. + * Input: + * 1. Running broker + * 2. AutoDelete Persistent Queue is created from a client + * Output: + * + * <date> QUE-1001 : Create : Owner: '<name>' AutoDelete Durable + * + * Validation Steps: + * 3. The QUE ID is correct + * 4. The Durable tag is present in the message + * 5. The Owner is as expected + * 6. The AutoDelete tag is present in the message + * + * @throws javax.jms.JMSException + * @throws javax.naming.NamingException + * @throws java.io.IOException + */ + public void testQueueCreatePersistentAutoDelete() throws NamingException, JMSException, IOException + { + // To force a queue Creation Event we need to create a consumer. + + Queue queue = (Queue) _session.createQueue("direct://amq.direct/testQueue/testQueue?durable='"+_durable+"'&autodelete='true'"); + + _session.createConsumer(queue); + + // Validation + List<String> results = _monitor.findMatches(QUEUE_PREFIX); + + // Only 1 Queue message should hav been logged + assertEquals("Result set size not as expected", 1, results.size()); + + String log = getLog(results.get(0)); + + // Message Should be a QUE-1001 + validateMessageID("QUE-1001", log); + + // Queue is Durable + assertEquals(DURABLE + " keyword not correct in log entry", + _durable, fromMessage(log).contains(DURABLE)); + + assertEquals(TRANSIENT + " keyword not correct in log entry.", + !_durable, fromMessage(log).contains(TRANSIENT)); + + // Queue is AutoDelete + assertTrue("Queue does not have the AutoDelete keyword in log:" + fromMessage(log), + fromMessage(log).contains("AutoDelete")); + + assertTrue("Queue does not have correct owner value:" + fromMessage(log), + fromMessage(log).contains("Owner: null")); + } + + /** + * Description: + * When a simple transient queue is created then a QUE-1001 create message + * is expected to be logged. + * Input: + * 1. Running broker + * 2. Persistent Queue is created from a client + * Output: + * + * <date> QUE-1001 : Create : Owner: '<name>' Durable Priority:<levels> + * + * Validation Steps: + * 3. The QUE ID is correct + * 4. The Durable tag is present in the message + * 5. The Owner is as expected + * 6. The Priority level is correctly set + * + * @throws javax.jms.JMSException + * @throws javax.naming.NamingException + * @throws java.io.IOException + */ + public void testCreateQueuePersistentPriority() throws NamingException, JMSException, IOException, AMQException + { + // To Create a Priority queue we need to use AMQSession specific code + int PRIORITIES = 6; + final Map<String, Object> arguments = new HashMap<String, Object>(); + arguments.put("x-qpid-priorities", PRIORITIES); + // Need to create a queue that does not exist so use test name + ((AMQSession) _session).createQueue(new AMQShortString(getName()), false, _durable, false, arguments); + + //Need to create a Consumer to ensure that the log has had time to write + // as the above Create is Asynchronous + _session.createConsumer(_session.createQueue(getName())); + + // Validation + List<String> results = _monitor.findMatches(QUEUE_PREFIX); + + // Only 1 Queue message should hav been logged + assertEquals("Result set size not as expected", 1, results.size()); + + String log = getLog(results.get(0)); + + // Message Should be a QUE-1001 + validateMessageID("QUE-1001", log); + + // Queue is Durable + assertEquals(DURABLE + " keyword not correct in log entry", + _durable, fromMessage(log).contains(DURABLE)); + + assertEquals(TRANSIENT + " keyword not correct in log entry.", + !_durable, fromMessage(log).contains(TRANSIENT)); + + // Queue is AutoDelete + assertTrue("Queue does not have the right Priority value keyword in log:" + fromMessage(log), + fromMessage(log).contains("Priority: " + PRIORITIES)); + + assertTrue("Queue does not have correct owner value:" + fromMessage(log), + fromMessage(log).contains("Owner: null")); + } + + /** + * Description: + * When a simple transient queue is created then a QUE-1001 create message + * is expected to be logged. + * Input: + * 1. Running broker + * 2. AutoDelete Persistent Queue is created from a client + * Output: + * + * <date> QUE-1001 : Create : Owner: '<name>' Durable Priority:<levels> + * + * Validation Steps: + * 3. The QUE ID is correct + * 4. The Durable tag is present in the message + * 5. The Owner is as expected + * 6. The AutoDelete tag is present in the message + * 7. The Priority level is correctly set + * + * @throws javax.jms.JMSException + * @throws javax.naming.NamingException + * @throws java.io.IOException + */ + public void testCreateQueuePersistentAutoDeletePriority() throws NamingException, JMSException, IOException, AMQException + { + // To Create a Priority queue we need to use AMQSession specific code + int PRIORITIES = 6; + final Map<String, Object> arguments = new HashMap<String, Object>(); + arguments.put("x-qpid-priorities", PRIORITIES); + // Need to create a queue that does not exist so use test name + ((AMQSession) _session).createQueue(new AMQShortString(getName()), true, _durable, false, arguments); + + //Need to create a Consumer to ensure that the log has had time to write + // as the above Create is Asynchronous + _session.createConsumer(_session.createQueue(getName())); + + // Validation + List<String> results = _monitor.findMatches(QUEUE_PREFIX); + + // Only 1 Queue message should hav been logged + assertEquals("Result set size not as expected", 1, results.size()); + + String log = getLog(results.get(0)); + + // Message Should be a QUE-1001 + validateMessageID("QUE-1001", log); + + // Queue is Durable + assertEquals(DURABLE + " keyword not correct in log entry", + _durable, fromMessage(log).contains(DURABLE)); + + assertEquals(TRANSIENT + " keyword not correct in log entry.", + !_durable, fromMessage(log).contains(TRANSIENT)); + + // Queue is AutoDelete + assertTrue("Queue does not have the right Priority value keyword in log:" + fromMessage(log), + fromMessage(log).contains("Priority: " + PRIORITIES)); + + // Queue is AutoDelete + assertTrue("Queue does not have the AutoDelete keyword in log:" + fromMessage(log), + fromMessage(log).contains("AutoDelete")); + + assertTrue("Queue does not have correct owner value:" + fromMessage(log), + fromMessage(log).contains("Owner: null")); + } + +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java new file mode 100644 index 0000000000..1b154f70ac --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java @@ -0,0 +1,172 @@ +/* + * + * 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.logging; + +import org.omg.CORBA.TRANSIENT; +import org.apache.qpid.client.AMQSession; +import org.apache.qpid.client.failover.FailoverException; +import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.AMQException; + +import javax.jms.Connection; +import javax.jms.Session; +import javax.jms.Queue; +import javax.jms.JMSException; +import javax.naming.NamingException; +import java.util.List; +import java.io.IOException; + +/** + * The Queue test suite validates that the follow log messages as specified in + * the Functional Specification. + * + * This suite of tests validate that the Queue messages occur correctly and + * according to the following format: + * + * QUE-1002 : Deleted + */ +public class QueueLoggingTest extends AbstractTestLogging +{ + protected Connection _connection; + protected Session _session; + private static final String QUEUE_PREFIX = "QUE-"; + + public void setUp() throws Exception + { + super.setUp(); + _connection = getConnection(); + _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + //Remove broker startup logging messages + _monitor.reset(); + } + + /** + * Description: + * An explict QueueDelete request must result in a QUE-1002 Deleted message + * being logged. This can be done via an explict AMQP QueueDelete method. + * Input: + * + * 1. Running Broker + * 2. Queue created on the broker with no subscribers + * 3. Client requests the queue be deleted via a QueueDelete + * Output: + * + * <date> QUE-1002 : Deleted + * + * Validation Steps: + * + * 4. The QUE ID is correct + * + * @throws java.io.IOException + * @throws javax.jms.JMSException + * @throws javax.naming.NamingException + */ + public void testQueueDelete() throws NamingException, JMSException, IOException, FailoverException, AMQException + { + // To force a queue Creation Event we need to create a consumer. + Queue queue = (Queue) getInitialContext().lookup(QUEUE); + + _session.createConsumer(queue); + + // Delete Queue + ((AMQSession)_session).sendQueueDelete(new AMQShortString(queue.getQueueName())); + + //Perform a synchronous action to ensure that the above log will be on disk + _session.close(); + + // Validation + List<String> results = _monitor.findMatches(QUEUE_PREFIX); + + // Only 1 Queue message should hav been logged + assertEquals("Result set size not as expected", 2, results.size()); + + String log = getLog(results.get(0)); + + // Message Should be a QUE-1001 + validateMessageID("QUE-1001", log); + + String createdQueueName = AbstractTestLogSubject.getSlice("qu", fromSubject(log)); + + log = getLog(results.get(1)); + // Message Should be a QUE-1002 + validateMessageID("QUE-1002", log); + + assertEquals("Log Message is incorrect ", "Deleted", getMessageString(fromMessage(log))); + + assertEquals("Queue Delete not for created queue:", createdQueueName, + AbstractTestLogSubject.getSlice("qu", fromSubject(log))); + } + + + /** + * Description: + * An explict QueueDelete request must result in a QUE-1002 Deleted message + * being logged. This can be done via an explict AMQP QueueDelete method. + * Input: + * + * 1. Running Broker + * 2. Queue created on the broker with no subscribers + * 3. Client creates a temporary queue then disconnects + * Output: + * + * <date> QUE-1002 : Deleted + * + * Validation Steps: + * + * 4. The QUE ID is correct + * + * @throws java.io.IOException + * @throws javax.jms.JMSException + * @throws javax.naming.NamingException + */ + public void testQueueAutoDelete() throws NamingException, JMSException, IOException + { + // Create a temporary queue so that when we consume from it and + // then close the consumer it will be autoDeleted. + _session.createConsumer(_session.createTemporaryQueue()).close(); + + // Validation + List<String> results = _monitor.findMatches(QUEUE_PREFIX); + + // Only 1 Queue message should hav been logged + assertEquals("Result set size not as expected", 2, results.size()); + + String log = getLog(results.get(0)); + + // Message Should be a QUE-1001 + validateMessageID("QUE-1001", log); + + String createdQueueName = AbstractTestLogSubject.getSlice("qu", fromSubject(log)); + + log = getLog(results.get(1)); + // Message Should be a QUE-1002 + validateMessageID("QUE-1002", log); + + assertEquals("Log Message is incorrect ", "Deleted", getMessageString(fromMessage(log))); + + assertEquals("Queue Delete not for created queue:", createdQueueName, + AbstractTestLogSubject.getSlice("qu", fromSubject(log))); + + } + +}
\ No newline at end of file diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/TransientQueueLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/TransientQueueLoggingTest.java new file mode 100644 index 0000000000..29f74c5818 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/TransientQueueLoggingTest.java @@ -0,0 +1,30 @@ +/* + * + * 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.logging; + +public class TransientQueueLoggingTest extends DurableQueueLoggingTest +{ + public void setUp() throws Exception + { + super.setUp(); + _durable = false; + } +} |
