Author: ritchiem
Date: Mon Aug  3 13:33:54 2009
New Revision: 800375

URL: http://svn.apache.org/viewvc?rev=800375&view=rev
Log:
QPID-2002 : Added new getLog method to AbstractTestLogging that retreives the 
string starting "MESSAGE....."
This ensures that the LoggingTests are parsing the logged message and not 
erroneously picking up a section based on the log4j format configuration. i.e. 
the [qpid.message] logger name was causing issues with searching for the first 
'[' to get Subject/Actor

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/ChannelLoggingTest.java
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.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=800375&r1=800374&r2=800375&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
 Mon Aug  3 13:33:54 2009
@@ -96,9 +96,7 @@
 
     protected String fromMessage(String log)
     {
-        int messageStart = log.indexOf("MESSAGE");
-
-        int startSubject = log.indexOf("]", messageStart) + 1;
+        int startSubject = log.indexOf("]") + 1;
         int start = log.indexOf("]", startSubject) + 1;
 
         // If we don't have a subject then the second indexOf will return 0
@@ -111,6 +109,19 @@
         return log.substring(start).trim();
     }
 
+    /**
+     * Extract the Subject from the Log Message.
+     *
+     * The subject is the second block inclosed in brackets '[ ]'.
+     *
+     * If there is no Subject or the second block of brackets '[ ]' cannot be
+     * identified then an empty String ("") is returned.
+     *
+     * 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)
     {
         int start = log.indexOf("[") + 1;
@@ -118,27 +129,94 @@
         start = log.indexOf("[", start) + 1;
 
         // There may not be a subject so in that case return nothing.
-        if (start == -1)
+        if (start == 0)
         {
             return "";
         }
 
         int end = log.indexOf("]", start);
-        return log.substring(start, end);
+        try
+        {
+            return log.substring(start, end);
+        }
+        catch (IndexOutOfBoundsException iobe)
+        {
+            return "";
+        }
     }
 
+    /**
+     * Extract the actor segment from the log message.
+     * The Actor segment is the first section enclosed in '[ ]'.
+     *
+     * No analysis is performed to ensure that the first '[ ]' section of the
+     * given log is really an Actor segment.
+     *
+     * 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)
     {
         int start = log.indexOf("[") + 1;
         int end = log.indexOf("]", start);
-        return log.substring(start, end).trim();
+        try
+        {
+            return log.substring(start, end).trim();
+        }
+        catch (IndexOutOfBoundsException iobe)
+        {
+            return "";
+        }
     }
 
+    /**
+     * Given our log message extract the connection ID:
+     *
+     * The log string will contain the connectionID identified by 'con:'
+     *
+     * So extract the value shown here by X:
+     *
+     * 'con:X('
+     *
+     * Extract the value between the ':' and '(' and process it as an Integer
+     *
+     * If we are unable to find the right index or process the substring as an
+     * Integer then return -1.
+     *
+     * @param log the log String to process
+     * @return the connection ID or -1.
+     */
     protected int extractConnectionID(String log)
     {
         int conIDStart = log.indexOf("con:") + 4;
         int conIDEnd = log.indexOf("(", conIDStart);
-        return Integer.parseInt(log.substring(conIDStart, conIDEnd));
+        try
+        {
+            return Integer.parseInt(log.substring(conIDStart, conIDEnd));
+        }
+        catch (Exception e)
+        {
+            return -1;
+        }
+    }
+
+    /**
+     * Extract the log entry from the raw log line which will contain other
+     * log4j formatting.
+     *
+     * This formatting may impead our testing process so extract the log 
message
+     * 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)
+    {
+        int start = rawLog.indexOf("MESSAGE");
+        return rawLog.substring(start);
     }
 
 }

Modified: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java?rev=800375&r1=800374&r2=800375&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java
 (original)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java
 Mon Aug  3 13:33:54 2009
@@ -75,11 +75,11 @@
 
         assertEquals("CHN messages not logged", 1, results.size());
 
-        String log = results.get(0);
+        String log = getLog(results.get(0));
         //  MESSAGE [con:0(gu...@anonymous(3273383)/test)/ch:1] CHN-1001 : 
Create
         //1 & 2
         validateMessageID("CHN-1001", log);
-        assertEquals("Incorrect Channel in actor", 1, 
getChannelID(fromActor(log)));
+        assertEquals("Incorrect Channel in actor:"+fromActor(log), 1, 
getChannelID(fromActor(log)));
 
         connection.close();
     }
@@ -125,7 +125,7 @@
 
         // Verify
         int resultSize = results.size();
-        String log = results.get(resultSize - 1);
+        String log = getLog(results.get(resultSize - 1));
 
         validateMessageID("CHN-1002", log);
         assertTrue("Message should be Flow Stopped", 
fromMessage(log).endsWith("Flow Stopped"));
@@ -178,7 +178,7 @@
         // Verify
 
         int resultSize = results.size();
-        String log = results.get(resultSize - 1);
+        String log = getLog(results.get(resultSize - 1));
 
         validateMessageID("CHN-1002", log);
         assertTrue("Message should be Flow Started", 
fromMessage(log).endsWith("Flow Started"));
@@ -225,7 +225,7 @@
         // Verify
 
         int resultSize = results.size();
-        String log = results.get(resultSize - 1);
+        String log = getLog(results.get(resultSize - 1));
 
         validateMessageID("CHN-1003", log);
         assertTrue("Message should be Close:" + fromMessage(log), 
fromMessage(log).endsWith("Close"));
@@ -270,10 +270,10 @@
         // Verify
 
         int resultSize = results.size();
-        String log = results.get(resultSize - 1);
+        String log = getLog(results.get(resultSize - 1));
 
         validateMessageID("CHN-1003", log);
-        assertTrue("Message should be Close:" + fromMessage(log), 
fromMessage(log).endsWith("Close"));
+        assertTrue("Message should be Close:" + fromMessage(getLog(log)), 
fromMessage(log).endsWith("Close"));
         assertEquals("Incorrect Channel ID closed.", 1, 
getChannelID(fromActor(log)));
         assertEquals("Incorrect Channel ID closed.", 1, 
getChannelID(fromSubject(log)));
     }

Modified: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java?rev=800375&r1=800374&r2=800375&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java
 (original)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java
 Mon Aug  3 13:33:54 2009
@@ -74,7 +74,7 @@
         // open and close messages from the failed 0-10 negotiation 
         assertTrue("CON messages not logged:" + results.size(), results.size() 
>= 3);
 
-        String log = results.get(0);
+        String log = getLog(results.get(0));
         //  MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open
         //1 & 2
         validateMessageID("CON-1001",log);
@@ -85,7 +85,7 @@
         // 0-10 negotiation messages
 
         // 3 - Assert the options are correct
-        log = results.get(resultsSize - 1);
+        log = getLog(results.get(resultsSize - 1));
         //  MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : 
clientid : Protocol Version : 0-9
         validateMessageID("CON-1001",log);
         assertTrue("Client ID option is not present", 
fromMessage(log).contains("Client ID :"));
@@ -95,7 +95,7 @@
         //fixme there is no way currently to find out the negotiated protocol 
version
         // The delegate is the versioned class 
((AMQConnection)connection)._delegate
 
-        log = results.get(resultsSize - 2);
+        log = getLog(results.get(resultsSize - 2));
         //  MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Protocol 
Version : 0-9
         validateMessageID("CON-1001",log);
         assertTrue("Protocol Version option is not present", 
fromMessage(log).contains("Protocol Version :"));
@@ -103,7 +103,7 @@
         // Check that client ID is not present in log
         assertTrue("Client ID option is present", 
!fromMessage(log).contains("Client ID :"));
 
-        log = results.get(resultsSize - 3);
+        log = getLog(results.get(resultsSize - 3));
         validateMessageID("CON-1001",log);
         // Check that PV is not present in log
         assertTrue("Protocol Version option is present", 
!fromMessage(log).contains("Protocol Version :"));
@@ -147,7 +147,7 @@
         int resultsSize = results.size();
 
         // Validate Close message occurs
-        String log = results.get(resultsSize - 1);
+        String log = getLog(results.get(resultsSize - 1));
         validateMessageID("CON-1002",log);
         assertTrue("Message does not end with close:" + log, 
log.endsWith("Close"));
 
@@ -155,7 +155,7 @@
         int connectionID = extractConnectionID(log);
 
         //Previous log message should be the open
-        log = results.get(resultsSize - 2);
+        log = getLog(results.get(resultsSize - 2));
         //  MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : 
clientid : Protocol Version : 0-9
         validateMessageID("CON-1001",log);
         assertEquals("Connection IDs do not match", connectionID, 
extractConnectionID(fromActor(log)));



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

Reply via email to