summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2009-08-03 13:33:54 +0000
committerMartin Ritchie <ritchiem@apache.org>2009-08-03 13:33:54 +0000
commitb8588d44be3e246706f22f356f4ca112f6197ff4 (patch)
tree7cc0681a0f9307671c656fd5ae911eb2f4c6d057
parentc632828aff01e75f3e89ba81d8e5cad4be58a999 (diff)
downloadqpid-python-b8588d44be3e246706f22f356f4ca112f6197ff4.tar.gz
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 git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@800375 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java92
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java14
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java12
3 files changed, 98 insertions, 20 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java b/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
index c5015760a5..6cb2f5dfc3 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
@@ -96,9 +96,7 @@ public class AbstractTestLogging extends QpidTestCase
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 @@ public class AbstractTestLogging extends QpidTestCase
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 @@ public class AbstractTestLogging extends QpidTestCase
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);
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java b/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java
index 9aa3799ca5..2de6b08751 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java
@@ -75,11 +75,11 @@ public class ChannelLoggingTest extends AbstractTestLogging
assertEquals("CHN messages not logged", 1, results.size());
- String log = results.get(0);
+ String log = getLog(results.get(0));
// MESSAGE [con:0(guest@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 @@ public class ChannelLoggingTest extends AbstractTestLogging
// 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 @@ public class ChannelLoggingTest extends AbstractTestLogging
// 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 @@ public class ChannelLoggingTest extends AbstractTestLogging
// 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 @@ public class ChannelLoggingTest extends AbstractTestLogging
// 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)));
}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java b/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java
index 861694d448..424e8e0cca 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java
@@ -74,7 +74,7 @@ public class ConnectionLoggingTest extends AbstractTestLogging
// 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 @@ public class ConnectionLoggingTest extends AbstractTestLogging
// 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 @@ public class ConnectionLoggingTest extends AbstractTestLogging
//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 @@ public class ConnectionLoggingTest extends AbstractTestLogging
// 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 @@ public class ConnectionLoggingTest extends AbstractTestLogging
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 @@ public class ConnectionLoggingTest extends AbstractTestLogging
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)));