diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2009-08-03 13:20:20 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2009-08-03 13:20:20 +0000 |
| commit | 8544a92ae006a7eac0e8f08a6a358f94bdab0c26 (patch) | |
| tree | c5a9acaeb17128ba9c1d8b6bafd72606e74bd3eb /java | |
| parent | 267f68e8c353b74201ca9f0822396071f410a086 (diff) | |
| download | qpid-python-8544a92ae006a7eac0e8f08a6a358f94bdab0c26.tar.gz | |
QPID-2002 : Addition of ConnectionLoggingTest
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@800359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
| -rw-r--r-- | java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java | 61 | ||||
| -rw-r--r-- | java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java | 164 |
2 files changed, 225 insertions, 0 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 new file mode 100644 index 0000000000..3437fea236 --- /dev/null +++ b/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java @@ -0,0 +1,61 @@ +/* + * + * 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.test.utils.QpidTestCase; +import org.apache.qpid.util.LogMonitor; +import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject; + +import java.io.IOException; + +public class AbstractTestLogging extends QpidTestCase +{ + protected LogMonitor _monitor; + + + @Override + public void setUp() throws Exception + { + super.setUp(); + _monitor = new LogMonitor(_outputFile); + } + + /** + * assert that the requested log message has not occured + * @param log + * @throws IOException + */ + public void assertLoggingNotYetOccured(String log) throws IOException + { + // Ensure the alert has not occured yet + assertEquals("Message has already occured:"+log, 0, + _monitor.findMatches(log).size()); + } + + protected int extractConnectionID(String log) + { + int conIDStart = log.indexOf("con:") + 4; + int conIDEnd = log.indexOf("(", conIDStart); + return Integer.parseInt(log.substring(conIDStart, conIDEnd)); + } + +} 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 new file mode 100644 index 0000000000..da061c844a --- /dev/null +++ b/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java @@ -0,0 +1,164 @@ +/* +* +* 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 javax.jms.Connection; +import java.io.File; +import java.util.List; + +public class ConnectionLoggingTest extends AbstractTestLogging +{ + private static final String CONNECTION_PREFIX = "CON-"; + + public void setUp() throws Exception + { + // set QPID_WORK to be [QPID_WORK|io.tmpdir]/<testName> + setSystemProperty("QPID_WORK", + System.getProperty("QPID_WORK", + System.getProperty("java.io.tmpdir")) + + File.separator + getName()); + + //Start the broker + super.setUp(); + } + + /** + * Description: + * When a new connection is made to the broker this must be logged. + * + * Input: + * 1. Running Broker + * 2. Connecting client + * Output: + * <date> CON-1001 : Open : Client ID {0}[ : Protocol Version : {1}] <version> + * + * Validation Steps: + * 1. The CON ID is correct + * 2. This is the first CON message for that Connection + * + * @throws Exception - if an error occurs + */ + public void testConnectionOpen() throws Exception + { + assertLoggingNotYetOccured(CONNECTION_PREFIX); + + Connection connection = getConnection(); + + List<String> results = _monitor.findMatches(CONNECTION_PREFIX); + + // Validation + + // 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); + + String log = results.get(0); + // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open + //1 & 2 + assertTrue("CON-1001 is not the first CON message", + log.contains("CON-1001")); + + //We get the size so that we can validate the last three CON- messages + int resultsSize = results.size(); + // This is because when running externally we will also have logged the failed + // 0-10 negotiation messages + + // 3 - Assert the options are correct + log = results.get(resultsSize - 1); + // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : clientid : Protocol Version : 0-9 + assertTrue("Incorrect CON message, not CON-1001", log.contains("CON-1001")); + assertTrue("Client ID option is not present", log.contains("Client ID :")); + assertTrue("Client ID value is not present", log.contains(connection.getClientID())); + + assertTrue("Protocol Version option is not present", log.contains("Protocol Version :")); + //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); + // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Protocol Version : 0-9 + assertTrue("Incorrect CON message, not CON-1001", log.contains("CON-1001")); + assertTrue("Protocol Version option is not present", log.contains("Protocol Version :")); + //fixme agani we should check the version + // Check that client ID is not present in log + assertTrue("Client ID option is present", !log.contains("Client ID :")); + + log = results.get(resultsSize - 3); + assertTrue("Incorrect CON message, not CON-1001", log.contains("CON-1001")); + // Check that PV is not present in log + assertTrue("Protocol Version option is present", !log.contains("Protocol Version :")); + // Check that client ID is not present in log + assertTrue("Client ID option is present", !log.contains("Client ID :")); + + connection.close(); + } + + /** + * Description: + * When a connected client closes the connection this will be logged as a CON-1002 message. + * Input: + * + * 1. Running Broker + * 2. Connected Client + * Output: + * + * <date> CON-1002 : Close + * + * Validation Steps: + * 3. The CON ID is correct + * 4. This must be the last CON message for the Connection + * 5. It must be preceded by a CON-1001 for this Connection + */ + public void testConnectionClose() throws Exception + { + assertLoggingNotYetOccured(CONNECTION_PREFIX); + + // Open and then close the conneciton + getConnection().close(); + + List<String> results = _monitor.findMatches(CONNECTION_PREFIX); + + // Validation + + // We should have at least four messages + assertTrue("CON messages not logged:" + results.size(), results.size() >= 4); + + //We get the size so that we can validate the last set of CON- messages + int resultsSize = results.size(); + + // Validate Close message occurs + String log = results.get(resultsSize - 1); + assertTrue("Incorrect CON message, not CON-1002", log.contains("CON-1002")); + assertTrue("Message does not end with close:" + log, log.endsWith("Close")); + + // Extract connection ID to validate there is a CON-1001 messasge for it + int connectionID = extractConnectionID(log); + + //Previous log message should be the open + log = results.get(resultsSize - 2); + // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : clientid : Protocol Version : 0-9 + assertTrue("Incorrect CON message, not CON-1001", log.contains("CON-1001")); + assertEquals("Connection IDs do not match", connectionID, extractConnectionID(log)); + } +} |
