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 19:00:05 UTC

svn commit: r801723 - in /qpid/trunk/qpid/java: broker/src/main/java/org/apache/qpid/server/queue/ systests/src/main/java/org/apache/qpid/server/logging/

Author: ritchiem
Date: Thu Aug  6 17:00:04 2009
New Revision: 801723

URL: http://svn.apache.org/viewvc?rev=801723&view=rev
Log:
QPID-2002 : Add Binding Logging Messages with test

Added:
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java
Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBinding.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBindings.java
    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/queue/ExchangeBinding.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBinding.java?rev=801723&r1=801722&r2=801723&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBinding.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBinding.java Thu Aug  6 17:00:04 2009
@@ -21,6 +21,10 @@
 package org.apache.qpid.server.queue;
 
 import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.messages.BindingMessages;
+import org.apache.qpid.server.logging.subjects.BindingLogSubject;
+import org.apache.qpid.server.logging.LogSubject;
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.framing.FieldTable;
 import org.apache.qpid.AMQException;
@@ -31,23 +35,26 @@
     private final AMQShortString _routingKey;
     private final FieldTable _arguments;
 
-    private static final FieldTable EMPTY_ARGUMENTS = new FieldTable();    
+    private static final FieldTable EMPTY_ARGUMENTS = new FieldTable();
+    private LogSubject _logSubject;
 
-    ExchangeBinding(AMQShortString routingKey, Exchange exchange)
-    {
-        this(routingKey, exchange, EMPTY_ARGUMENTS);
-    }
-
-    ExchangeBinding(AMQShortString routingKey, Exchange exchange, FieldTable arguments)
+    ExchangeBinding(AMQShortString routingKey, Exchange exchange, AMQQueue queue, FieldTable arguments)
     {
         _routingKey = routingKey == null ? AMQShortString.EMPTY_STRING : routingKey;
         _exchange = exchange;
         _arguments = arguments == null ? EMPTY_ARGUMENTS : arguments;
+        _logSubject = new BindingLogSubject(routingKey,exchange,queue);
+
+        CurrentActor.get().message(_logSubject, BindingMessages.BND_1001(_arguments.toString(), arguments != null));
     }
 
+
+
     void unbind(AMQQueue queue) throws AMQException
     {
         _exchange.deregisterQueue(_routingKey, queue, _arguments);
+
+        CurrentActor.get().message(_logSubject, BindingMessages.BND_1002());
     }
 
     public Exchange getExchange()

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBindings.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBindings.java?rev=801723&r1=801722&r2=801723&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBindings.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ExchangeBindings.java Thu Aug  6 17:00:04 2009
@@ -52,13 +52,13 @@
      */
     void addBinding(AMQShortString routingKey, FieldTable arguments, Exchange exchange)
     {
-        _bindings.add(new ExchangeBinding(routingKey, exchange, arguments));
+        _bindings.add(new ExchangeBinding(routingKey, exchange, _queue, arguments));
     }
 
 
     public boolean remove(AMQShortString routingKey, FieldTable arguments, Exchange exchange)
     {
-        return _bindings.remove(new ExchangeBinding(routingKey, exchange, arguments));
+        return _bindings.remove(new ExchangeBinding(routingKey, exchange, _queue, arguments));
     }
 
 

Added: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java?rev=801723&view=auto
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java (added)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java Thu Aug  6 17:00:04 2009
@@ -0,0 +1,268 @@
+/*
+ *
+ * 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.server.logging.subjects.AbstractTestLogSubject;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Topic;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Binding
+ *
+ * The Binding test suite validates that the follow log messages as specified in the Functional Specification.
+ *
+ * This suite of tests validate that the Binding messages occur correctly and according to the following format:
+ *
+ * BND-1001 : Create [: Arguments : <key=value>]
+ * BND-1002 : Deleted
+ */
+public class BindingLoggingTest extends AbstractTestLogging
+{
+
+    static final String BND_PREFIX = "BND-";
+
+    Connection _connection;
+    Session _session;
+    Queue _queue;
+    Topic _topic;
+
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        //Ignore broker startup messages
+        _monitor.reset();
+
+        _connection = getConnection();
+
+        _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        _queue = _session.createQueue(getName());
+        _topic = (Topic) getInitialContext().lookup(TOPIC);
+    }
+
+    private void validateLogMessage(String log, String messageID, String exchange, String message)
+    {
+        validateMessageID(messageID, log);
+
+        String subject = fromSubject(log);
+
+        assertEquals("Queue not correct.", getName(),
+                     AbstractTestLogSubject.getSlice("qu", subject));
+        assertEquals("Routing Key not correct.", getName(),
+                     AbstractTestLogSubject.getSlice("rk", subject));
+        assertEquals("Virtualhost not correct.", "/test",
+                     AbstractTestLogSubject.getSlice("vh", subject));
+        assertEquals("Exchange not correct.", exchange,
+                     AbstractTestLogSubject.getSlice("ex", subject));
+
+        assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log)));
+    }
+
+    /**
+     * testBindingCreate
+     *
+     * Description:
+     * The binding of a Queue and an Exchange is done via a Binding. When this Binding is created a BND-1001 Create message will be logged.
+     * Input:
+     *
+     * 1. Running Broker
+     * 2. New Client requests that a Queue is bound to a new exchange.
+     * Output:
+     *
+     * <date> BND-1001 : Create
+     *
+     * Validation Steps:
+     * 3. The BND ID is correct
+     * 4. This will be the first message for the given binding
+     */
+    public void testBindingCreate() throws JMSException, IOException
+    {
+        _session.createConsumer(_queue).close();
+
+        List<String> results = _monitor.findMatches(BND_PREFIX);
+
+        // We will have two binds as we bind all queues to the default exchange
+        assertEquals("Result set larger than expected.", 2, results.size());
+
+        String exchange = "direct/<<default>>";
+        String messageID = "BND-1001";
+        String message = "Create";
+
+        validateLogMessage(getLog(results.get(0)), messageID, exchange, message);
+
+        exchange = "direct/amq.direct";
+        validateLogMessage(getLog(results.get(1)), messageID, exchange, message);
+    }
+
+    /**
+     * Description:
+     * A Binding can be made with a set of arguments. When this occurs we logged the key,value pairs as part of the Binding log message. When the subscriber with a JMS Selector consumes from an exclusive queue such as a topic. The binding is made with the JMS Selector as an argument.
+     * Input:
+     *
+     * 1. Running Broker
+     * 2. Java Client consumes from a topic with a JMS selector.
+     * Output:
+     *
+     * <date> BND-1001 : Create : Arguments : <key=value>
+     *
+     * Validation Steps:
+     * 3. The BND ID is correct
+     * 4. The JMS Selector argument is present in the message
+     * 5. This will be the first message for the given binding
+     */
+    public void testBindingCreateWithArguments() throws JMSException, IOException
+    {
+        final String SELECTOR = "Selector='True'";
+
+        _session.createDurableSubscriber(_topic, getName(), SELECTOR, false).close();
+
+        List<String> results = _monitor.findMatches(BND_PREFIX);
+
+        // We will have two binds as we bind all queues to the default exchange
+        assertEquals("Result set larger than expected.", 2, results.size());
+
+        String log = getLog(results.get(0));
+
+        //Verify the first entry is the default binding
+        validateMessageID("BND-1001", log);
+
+        String subject = fromSubject(log);
+
+        assertEquals("Queue not correct.", "clientid:" + getName(),
+                     AbstractTestLogSubject.getSlice("qu", subject));
+        // NOTE default binding is the queue name
+        assertEquals("Routing Key not correct.", "clientid:" + getName(),
+                     AbstractTestLogSubject.getSlice("rk", subject));
+        assertEquals("Virtualhost not correct.", "/test",
+                     AbstractTestLogSubject.getSlice("vh", subject));
+        assertEquals("Exchange not correct.", "direct/<<default>>",
+                     AbstractTestLogSubject.getSlice("ex", fromSubject(log)));
+
+        String message = getMessageString(log);
+
+        //Default binding will be without the selector
+        assertTrue("JMSSelector identified in binding:"+message, !message.contains("jms-selector"));
+
+        // Perform full testing on the second non default binding
+        log = getLog(results.get(1));
+        validateMessageID("BND-1001", log);
+
+        subject = fromSubject(log);
+
+        assertEquals("Queue not correct.", "clientid:" + getName(),
+                     AbstractTestLogSubject.getSlice("qu", subject));
+        assertEquals("Routing Key not correct.", "topic",
+                     AbstractTestLogSubject.getSlice("rk", subject));
+        assertEquals("Virtualhost not correct.", "/test",
+                     AbstractTestLogSubject.getSlice("vh", subject));
+        assertEquals("Exchange not correct.", "topic/amq.topic",
+                     AbstractTestLogSubject.getSlice("ex", subject));
+
+        message = getMessageString(log);
+
+        assertTrue("JMSSelector not identified in binding:"+message, message.contains("jms-selector"));
+        assertTrue("Selector not part of binding.:"+message, message.contains(SELECTOR));
+
+    }
+
+    /**
+     * Description:
+     * Bindings can be deleted so that a queue can be rebound with a different set of values.
+     * Input:
+     *
+     * 1. Running Broker
+     * 2. AMQP UnBind Request is made
+     * Output:
+     *
+     * <date> BND-1002 : Deleted
+     *
+     * Validation Steps:
+     * 3. The BND ID is correct
+     * 4. There must have been a BND-1001 Create message first.
+     * 5. This will be the last message for the given binding
+     */
+    public void testBindingDelete() throws JMSException, IOException
+    {
+        //Closing a consumer on a temporary queue will cause it to autodelete
+        // and so unbind.
+        _session.createConsumer(_session.createTemporaryQueue()).close();
+
+        List<String> results = _monitor.findMatches(BND_PREFIX);
+
+        // We will have two binds as we bind all queues to the default exchange
+        assertEquals("Result set larger than expected.", 4, results.size());
+
+
+        String messageID = "BND-1001";
+        String message = "Create";
+
+        String log = getLog(results.get(0));
+        validateMessageID(messageID, log);
+        assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log)));
+
+        log = getLog(results.get(1));
+        validateMessageID(messageID, log);
+        assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log)));
+
+
+        String exchange = "direct/<<default>>";
+        messageID = "BND-1002";
+        message = "Deleted";
+
+        log = getLog(results.get(2));
+        validateMessageID(messageID, log);
+
+        String subject = fromSubject(log);
+
+        assertTrue("Routing Key does not start with TempQueue:"+AbstractTestLogSubject.getSlice("rk", subject), 
+                     AbstractTestLogSubject.getSlice("rk", subject).startsWith("TempQueue"));
+        assertEquals("Virtualhost not correct.", "/test",
+                     AbstractTestLogSubject.getSlice("vh", subject));
+        assertEquals("Exchange not correct.", exchange,
+                     AbstractTestLogSubject.getSlice("ex", subject));
+
+        assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log)));
+
+        exchange = "direct/amq.direct";
+        log = getLog(results.get(3));
+
+        validateMessageID(messageID, log);
+
+        subject = fromSubject(log);
+
+        assertTrue("Routing Key does not start with TempQueue:"+AbstractTestLogSubject.getSlice("rk", subject),
+                     AbstractTestLogSubject.getSlice("rk", subject).startsWith("TempQueue"));
+        assertEquals("Virtualhost not correct.", "/test",
+                     AbstractTestLogSubject.getSlice("vh", subject));
+        assertEquals("Exchange not correct.", exchange,
+                     AbstractTestLogSubject.getSlice("ex", subject));
+
+        assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log)));
+
+    }
+}

Modified: 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=801723&r1=801722&r2=801723&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java Thu Aug  6 17:00:04 2009
@@ -96,19 +96,18 @@
 
         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"));
-        }
+        assertTrue("No Results found for Exchange.", results.size()>0);
+
+        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 Durable:" + message,
+                   message.contains("Durable"));
 
     }
 



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org