diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2009-08-06 16:57:50 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2009-08-06 16:57:50 +0000 |
| commit | 9129f2a0b1011347c8e0d35a1d24d65f2a934252 (patch) | |
| tree | 3f5b1cc2c2ed130d9c1158f1a07f6839a0774d5b /qpid/java | |
| parent | 2961082abeeeaae95c18c1714368012c0b640b76 (diff) | |
| download | qpid-python-9129f2a0b1011347c8e0d35a1d24d65f2a934252.tar.gz | |
QPID-2002: Added Exchange Logging and test
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@801720 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
| -rw-r--r-- | qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java | 13 | ||||
| -rw-r--r-- | qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java | 204 |
2 files changed, 217 insertions, 0 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java index 247558bb34..bb70ce556b 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java @@ -41,6 +41,10 @@ import org.apache.qpid.server.management.ManagedObjectRegistry; import org.apache.qpid.server.queue.QueueRegistry; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.qpid.server.logging.actors.CurrentActor; +import org.apache.qpid.server.logging.messages.ExchangeMessages; +import org.apache.qpid.server.logging.subjects.ExchangeLogSubject; +import org.apache.qpid.server.logging.LogSubject; public abstract class AbstractExchange implements Exchange, Managable { @@ -61,6 +65,9 @@ public abstract class AbstractExchange implements Exchange, Managable */ protected boolean _autoDelete; + //The logSubject for ths exchange + private LogSubject _logSubject; + /** * Abstract MBean class. This has some of the methods implemented from * management intrerface for exchanges. Any implementaion of an @@ -160,6 +167,10 @@ public abstract class AbstractExchange implements Exchange, Managable _ticket = ticket; _exchangeMbean = createMBean(); _exchangeMbean.register(); + _logSubject = new ExchangeLogSubject(this, this.getVirtualHost()); + + // Log Exchange creation + CurrentActor.get().message(ExchangeMessages.EXH_1001(String.valueOf(getType()), String.valueOf(name), durable)); } public boolean isDurable() @@ -183,6 +194,8 @@ public abstract class AbstractExchange implements Exchange, Managable { _exchangeMbean.unregister(); } + + CurrentActor.get().message(_logSubject, ExchangeMessages.EXH_1002()); } public String toString() diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java new file mode 100644 index 0000000000..3571f24fef --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java @@ -0,0 +1,204 @@ +/* + * + * 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.client.AMQConnection; +import org.apache.qpid.framing.AMQFrame; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.framing.ExchangeDeleteBody; +import org.apache.qpid.framing.ExchangeDeleteOkBody; +import org.apache.qpid.framing.amqp_8_0.MethodRegistry_8_0; + +import javax.jms.Connection; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Session; +import java.io.IOException; +import java.util.List; + +/** + * Exchange + * + * The Exchange test suite validates that the follow log messages as specified in the Functional Specification. + * + * This suite of tests validate that the Exchange messages occur correctly and according to the following format: + * + * EXH-1001 : Create : [Durable] Type:<value> Name:<value> + * EXH-1002 : Deleted + */ +public class ExchangeLoggingTest extends AbstractTestLogging +{ + + static final String EXH_PREFIX = "EXH-"; + + Connection _connection; + Session _session; + Queue _queue; + String _name; + String _type; + + @Override + public void setUp() throws Exception + { + super.setUp(); + + _connection = getConnection(); + + _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + _type = "direct"; + _name = "testName"; + + _queue = _session.createQueue(_type + "://" + _name + "/queue/queue"); + + } + + /** + * Description: + * When a durable exchange is created an EXH-1001 message is logged with the Durable tag. This will be the first message from this exchange. + * Input: + * + * 1. Running broker + * 2. Client requests a durable exchange be created. + * Output: + * + * <date> EXH-1001 : Create : Durable Type:<value> Name:<value> + * + * Validation Steps: + * 3. The EXH ID is correct + * 4. The Durable tag is present in the message + */ + + public void testExchangeCreateDurable() throws JMSException, IOException + { + // The client cannot create durable exchanges lets just look at the + // ones the broker creates at startup. + + // They should all be durable + + List<String> results = _monitor.findMatches(EXH_PREFIX); + + for (String rawLog : results) + { + String log = getLog(rawLog); + + validateMessageID("EXH-1001", log); + + String message = getMessageString(fromMessage(log)); + assertTrue("Log Message does not start with create:" + message, + message.startsWith("Create")); + + assertTrue("Log Message does not contain Durable:" + message, + message.contains("Durable")); + } + + } + + /** + * Description: + * When an exchange is created an EXH-1001 message is logged. This will be the first message from this exchange. + * Input: + * + * 1. Running broker + * 2. Client requests an exchange be created. + * Output: + * + * <date> EXH-1001 : Create : Type:<value> Name:<value> + * + * Validation Steps: + * 3. The EXH ID is correct + */ + public void testExchangeCreate() throws JMSException, IOException + { + //Ignore broker startup messages + _monitor.reset(); + + _session.createConsumer(_queue); + + List<String> results = _monitor.findMatches(EXH_PREFIX); + + assertEquals("Result set larger than expected.", 1, results.size()); + + String log = getLog(results.get(0)); + + validateMessageID("EXH-1001", log); + + String message = getMessageString(fromMessage(log)); + assertTrue("Log Message does not start with create:" + message, + message.startsWith("Create")); + assertTrue("Log Message does not contain Type:" + message, + message.contains("Type: " + _type)); + assertTrue("Log Message does not contain Name:" + message, + message.contains("Name: " + _name)); + } + + /** + * Description: + * An Exchange can be deleted through an AMQP ExchangeDelete method. When this is successful an EXH-1002 Delete message will be logged. This will be the last message from this exchange. + * Input: + * + * 1. Running broker + * 2. A new Exchange has been created + * 3. Client requests that the new exchange be deleted. + * Output: + * + * <date> EXH-1002 : Deleted + * + * Validation Steps: + * 4. The EXH ID is correct + * 5. There is a corresponding EXH-1001 Create message logged. + */ + public void testExchangeDelete() throws Exception, IOException + { + //Ignore broker startup messages + _monitor.reset(); + + _session.createConsumer(_queue); + + MethodRegistry_8_0 registry = new MethodRegistry_8_0(); + + ExchangeDeleteBody body = registry.createExchangeDeleteBody(0, new AMQShortString(_name), false, true); + + AMQFrame exchangeDeclare = body.generateFrame(0); + + ((AMQConnection) _connection).getProtocolHandler().syncWrite(exchangeDeclare, ExchangeDeleteOkBody.class); + + List<String> results = _monitor.findMatches(EXH_PREFIX); + + assertEquals("Result set larger than expected.", 2, results.size()); + + String log = getLog(results.get(0)); + + validateMessageID("EXH-1001", log); + + String message = getMessageString(fromMessage(log)); + assertTrue("Log Message does start with Create", + message.startsWith("Create")); + + log = getLog(results.get(1)); + validateMessageID("EXH-1002", log); + + message = getMessageString(fromMessage(log)); + assertEquals("Log Message not as expected", "Deleted", message); + + } + +} |
