You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2009/08/06 18:57:51 UTC
svn commit: r801720 - in /qpid/trunk/qpid/java:
broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java
Author: ritchiem
Date: Thu Aug 6 16:57:50 2009
New Revision: 801720
URL: http://svn.apache.org/viewvc?rev=801720&view=rev
Log:
QPID-2002: Added Exchange Logging and test
Added:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java
Modified:
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java?rev=801720&r1=801719&r2=801720&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java Thu Aug 6 16:57:50 2009
@@ -41,6 +41,10 @@
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 @@
*/
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 @@
_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 @@
{
_exchangeMbean.unregister();
}
+
+ CurrentActor.get().message(_logSubject, ExchangeMessages.EXH_1002());
}
public String toString()
Added: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java?rev=801720&view=auto
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java (added)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java Thu Aug 6 16:57:50 2009
@@ -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);
+
+ }
+
+}
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org