diff options
-rw-r--r-- | java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java | 42 | ||||
-rw-r--r-- | java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java | 30 |
2 files changed, 67 insertions, 5 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 6cb2f5dfc3..47ae599d2b 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 @@ -24,6 +24,9 @@ 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.LinkedList; public class AbstractTestLogging extends QpidTestCase { @@ -53,7 +56,7 @@ public class AbstractTestLogging extends QpidTestCase protected void validateMessageID(String id, String log) { - assertEquals("Incorrect CHN message",id, getMessageID(log)); + assertEquals("Incorrect message",id, getMessageID(log)); } protected String getMessageID(String log) @@ -219,4 +222,41 @@ public class AbstractTestLogging extends QpidTestCase return rawLog.substring(start); } + /** + * 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 = extractConnectionID(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; + } } 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 424e8e0cca..46f32b1414 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 @@ -20,9 +20,16 @@ */ package org.apache.qpid.server.logging; +import org.apache.qpid.test.unit.client.forwardall.Client; + import javax.jms.Connection; import java.io.File; import java.util.List; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.SortedSet; +import java.util.Collections; +import java.util.TreeSet; public class ConnectionLoggingTest extends AbstractTestLogging { @@ -65,11 +72,26 @@ public class ConnectionLoggingTest extends AbstractTestLogging List<String> results = _monitor.findMatches(CONNECTION_PREFIX); // Validation + // We should have at least three messages when running InVM but when running External + // we will get 0-10 negotiation on con:0 whcih may close at some random point + // MESSAGE [con:0(/127.0.0.1:46926)] CON-1001 : Open + // MESSAGE [con:0(/127.0.0.1:46926)] CON-1001 : Open : Protocol Version : 0-10 + // MESSAGE [con:1(/127.0.0.1:46927)] CON-1001 : Open + // MESSAGE [con:1(/127.0.0.1:46927)] CON-1001 : Open : Protocol Version : 0-9 + // MESSAGE [con:0(/127.0.0.1:46926)] CON-1002 : Close + // MESSAGE [con:1(/127.0.0.1:46927)] CON-1001 : Open : Client ID : clientid : Protocol Version : 0-9 + + //So check how many connections we have in the result set and extract the last one. + // When running InVM we will have con:0 and externally con:1 + + HashMap<Integer, List<String>> connectionData = splitResultsOnConnectionID(results); + + // Get the last Integer from keySet of the ConnectionData + int connectionID = new TreeSet<Integer>(connectionData.keySet()).last(); + + //Use just the data from the last connection for the test + results = connectionData.get(connectionID); - // We should have at least three messages - // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open - // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Protocol Version : 0-9 - // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : clientid : Protocol Version : 0-9 // If we are running inVM we will get three open messagse, if running externally weN will also have // open and close messages from the failed 0-10 negotiation assertTrue("CON messages not logged:" + results.size(), results.size() >= 3); |