Author: ritchiem
Date: Fri Aug  7 18:10:52 2009
New Revision: 802123

URL: http://svn.apache.org/viewvc?rev=802123&view=rev
Log:
QPID-2002 : Add ability to filter log messages by virtualhost to 
AbstractTestLogging so that DerbyMessageStore can use it to filter out all the 
items created in the test vhost.

Modified:
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java

Modified: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java?rev=802123&r1=802122&r2=802123&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
 (original)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
 Fri Aug  7 18:10:52 2009
@@ -20,13 +20,15 @@
  */
 package org.apache.qpid.server.logging;
 
+import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject;
 import org.apache.qpid.test.utils.QpidTestCase;
 import org.apache.qpid.util.LogMonitor;
 
 import java.io.IOException;
-import java.util.List;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.List;
 
 public class AbstractTestLogging extends QpidTestCase
 {
@@ -38,7 +40,7 @@
         super.setUp();
         _monitor = new LogMonitor(_outputFile);
     }
-    
+
     @Override
     public void tearDown() throws Exception
     {
@@ -46,7 +48,6 @@
         super.tearDown();
     }
 
-
     /**
      * assert that the requested log message has not occured
      *
@@ -61,10 +62,9 @@
                      _monitor.findMatches(log).size());
     }
 
-
     protected void validateMessageID(String id, String log)
     {
-        assertEquals("Incorrect message",id, getMessageID(log));
+        assertEquals("Incorrect message", id, getMessageID(log));
     }
 
     protected String getMessageID(String log)
@@ -131,6 +131,7 @@
      * The brackets '[ ]' are not included in the returned String.
      *
      * @param log The log message to process
+     *
      * @return the Subject string or the empty string ("") if the subject 
can't be identified.
      */
     protected String fromSubject(String log)
@@ -166,6 +167,7 @@
      * The brackets '[ ]' are not included in the returned String.
      *
      * @param log the Log Message
+     *
      * @return the Actor segment or "" if unable to locate '[ ]' section
      */
     protected String fromActor(String log)
@@ -184,7 +186,9 @@
 
     /**
      * Return the message String from the given message section
+     *
      * @param log the Message Section
+     *
      * @return the Message String.
      */
     protected String getMessageString(String log)
@@ -195,7 +199,6 @@
         return log.substring(start).trim();
     }
 
-
     /**
      * Given our log message extract the connection ID:
      *
@@ -211,6 +214,7 @@
      * Integer then return -1.
      *
      * @param log the log String to process
+     *
      * @return the connection ID or -1.
      */
     protected int getConnectionID(String log)
@@ -235,7 +239,9 @@
      * as we know it to be formatted.
      *
      * This starts with the string MESSAGE
+     *
      * @param rawLog the raw log
+     *
      * @return the log we are expecting to be printed without the log4j 
prefixes
      */
     protected String getLog(String rawLog)
@@ -245,40 +251,70 @@
     }
 
     /**
-       * Given a list of messages that have been pulled out of a log file
-       * Process the results splitting the log statements in to lists based on 
the
-       * actor's connection ID.
-       *
-       * So for each log entry extract the Connecition ID from the Actor of 
the log
-       *
-       * Then use that as a key to a HashMap storing the list of log messages 
for
-       * that connection.
-       *
-       * @param logMessages The list of mixed connection log messages
-       * @return Map indexed by connection id to a list of log messages just 
for that connection.
-       */
-      protected HashMap<Integer,List<String>> 
splitResultsOnConnectionID(List<String> logMessages)
-      {
-          HashMap<Integer,List<String>> connectionSplitList = new 
HashMap<Integer, List<String>>();
-
-          for (String log : logMessages)
-          {
-              // Get the connectionID from the Actor in the Message Log.
-              int cID = getConnectionID(fromActor(getLog(log)));
-
-              List<String> connectionData = connectionSplitList.get(cID);
-
-              // Create the initial List if we don't have one already
-              if (connectionData == null)
-              {
-                  connectionData = new LinkedList<String>();
-                  connectionSplitList.put(cID, connectionData);
-              }
-
-              // Store the log
-              connectionData.add(log);
-          }
+     * Given a list of messages that have been pulled out of a log file
+     * Process the results splitting the log statements in to lists based on 
the
+     * actor's connection ID.
+     *
+     * So for each log entry extract the Connecition ID from the Actor of the 
log
+     *
+     * Then use that as a key to a HashMap storing the list of log messages for
+     * that connection.
+     *
+     * @param logMessages The list of mixed connection log messages
+     *
+     * @return Map indexed by connection id to a list of log messages just for 
that connection.
+     */
+    protected HashMap<Integer, List<String>> 
splitResultsOnConnectionID(List<String> logMessages)
+    {
+        HashMap<Integer, List<String>> connectionSplitList = new 
HashMap<Integer, List<String>>();
+
+        for (String log : logMessages)
+        {
+            // Get the connectionID from the Actor in the Message Log.
+            int cID = getConnectionID(fromActor(getLog(log)));
+
+            List<String> connectionData = connectionSplitList.get(cID);
+
+            // Create the initial List if we don't have one already
+            if (connectionData == null)
+            {
+                connectionData = new LinkedList<String>();
+                connectionSplitList.put(cID, connectionData);
+            }
+
+            // Store the log
+            connectionData.add(log);
+        }
+
+        return connectionSplitList;
+    }
+
+    /**
+     * Filter the give result set by the specficifed virtualhost.
+     * This is done using the getSlice to identify the virtualhost (vh) in the
+     * log message
+     *
+     * @param results         full list of logs
+     * @param virtualHostName the virtualhostName to filter on
+     *
+     * @return the list of messages only for that virtualhost
+     */
+    protected List<String> filterResultsByVirtualHost(List<String> results, 
String virtualHostName)
+    {
+        List<String> filteredResults = new LinkedList<String>();
+        Iterator<String> iterator = results.iterator();
+
+        while (iterator.hasNext())
+        {
+            String log = iterator.next();
+
+            if (AbstractTestLogSubject.getSlice("vh", 
log).equals(virtualHostName))
+            {
+                filteredResults.add(log);
+            }
+        }
+
+        return filteredResults;
+    }
 
-          return connectionSplitList;
-      }
 }

Modified: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java?rev=802123&r1=802122&r2=802123&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java
 (original)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java
 Fri Aug  7 18:10:52 2009
@@ -28,6 +28,8 @@
 import javax.jms.Queue;
 import javax.jms.Session;
 import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
 
 /**
  * The MessageStore test suite validates that the follow log messages as
@@ -299,6 +301,11 @@
         //Validate each vhost logs a creation
         results = _monitor.findMatches("MST-1004 : Recovery Start :");
 
+        // We are only looking for the default queue defined in local host 
being
+        // recovered. If other tests have made queues in test then we want to
+        // exclude them here.
+        results = filterResultsByVirtualHost(results, "/localhost");
+
         assertEquals("Recovered test queue not found.", 1, results.size());
 
         String result = getLog(results.get(0));
@@ -359,6 +366,12 @@
         //Validate each vhost logs a creation
         results = _monitor.findMatches("MST-1006 : Recovery Complete :");
 
+        // We are only looking for the default queue defined in local host 
being
+        // recovered. If other tests have made queues in test then we want to
+        // exclude them here.
+        results = filterResultsByVirtualHost(results, "/localhost");
+
+
         assertEquals("Recovered test queue not found.", 1, results.size());
 
         String result = getLog(results.get(0));
@@ -409,7 +422,7 @@
     {
         assertLoggingNotYetOccured(MESSAGES_STORE_PREFIX);
 
-        String queueName = "queueCountTest";
+        String queueName = getTestQueueName();
 
         startBroker();
         Connection connetion = getConnection();



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

Reply via email to