NO-JIRA: [Broker-J] [System Tests] Remove logging tests
Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/b21a8f56 Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/b21a8f56 Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/b21a8f56 Branch: refs/heads/master Commit: b21a8f564e9d914a41564fa0041f7355340cacaf Parents: 6b31d0f Author: Keith Wall <kw...@apache.org> Authored: Mon Mar 12 14:17:13 2018 +0000 Committer: Keith Wall <kw...@apache.org> Committed: Mon Mar 12 16:24:17 2018 +0000 ---------------------------------------------------------------------- .../apache/qpid/server/BrokerStartupTest.java | 84 -- .../server/logging/AbstractTestLogging.java | 412 --------- .../logging/AccessControlLoggingTest.java | 194 ----- .../qpid/server/logging/AlertingTest.java | 180 ---- .../qpid/server/logging/BrokerLoggingTest.java | 861 ------------------- .../qpid/server/logging/ChannelLoggingTest.java | 384 --------- .../server/logging/ConnectionLoggingTest.java | 209 ----- .../server/logging/ConsumerLoggingTest.java | 352 -------- .../server/logging/DurableQueueLoggingTest.java | 312 ------- .../server/logging/ExchangeLoggingTest.java | 247 ------ .../qpid/server/logging/QueueLoggingTest.java | 179 ---- .../logging/TransientQueueLoggingTest.java | 31 - .../server/logging/VirtualHostLoggingTest.java | 129 --- .../java/org/apache/qpid/util/LogMonitor.java | 310 ------- .../org/apache/qpid/util/LogMonitorTest.java | 227 ----- test-profiles/Java010Excludes | 4 - test-profiles/Java10Excludes | 19 - test-profiles/JavaPersistentExcludes | 2 - test-profiles/JavaPre010Excludes | 1 - 19 files changed, 4137 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b21a8f56/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java b/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java deleted file mode 100644 index 8b7443e..0000000 --- a/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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; - -import javax.jms.Connection; -import javax.jms.JMSException; - -import org.apache.qpid.server.logging.AbstractTestLogging; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.test.utils.TestBrokerConfiguration; - -/** - * Series of tests to validate the external Apache Qpid Broker-J starts up as expected. - */ -public class BrokerStartupTest extends AbstractTestLogging -{ - @Override - public void startDefaultBroker() - { - // noop; we do not want to start broker - } - - /** - * This test simply tests that the broker will startup even if there is no config file (i.e. that it can use the - * currently packaged initial config file (all system tests by default generate their own config file). - * - * @throws Exception - */ - public void testStartupWithNoConfig() throws Exception - { - if (isJavaBroker()) - { - super.startDefaultBroker(); - Connection conn = getConnection(); - assertNotNull(conn); - } - } - - public void testStartupWithErroredChildrenCanBeConfigured() throws Exception - { - if (isJavaBroker()) - { - // Purposely set the HTTP port to -1 so that the port object becomes ERRORED - final int invalidHttpPort = -1; - setTestSystemProperty("test.hport", String.valueOf(invalidHttpPort)); - getDefaultBrokerConfiguration().addHttpManagementConfiguration(); - getDefaultBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, invalidHttpPort); - - // Set broker to fail on startup if it has ERRORED children - setTestSystemProperty("broker.failStartupWithErroredChild", String.valueOf(Boolean.TRUE)); - - super.startDefaultBroker(); - - try - { - Connection conn = getConnection(); - fail("Connection should fail as broker startup should have failed due to ERRORED children (port)"); - } - catch (JMSException jmse) - { - //pass - } - } - } - -} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b21a8f56/systests/src/test/java/org/apache/qpid/server/logging/AbstractTestLogging.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/logging/AbstractTestLogging.java b/systests/src/test/java/org/apache/qpid/server/logging/AbstractTestLogging.java deleted file mode 100644 index 96b009e..0000000 --- a/systests/src/test/java/org/apache/qpid/server/logging/AbstractTestLogging.java +++ /dev/null @@ -1,412 +0,0 @@ -/* - * - * 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 java.io.FileNotFoundException; -import java.io.IOException; -import java.text.NumberFormat; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; - -import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject; -import org.apache.qpid.test.utils.QpidBrokerTestCase; -import org.apache.qpid.util.LogMonitor; - -/** - * Abstract superclass for logging test set up and utility methods. - * - * So named to prevent it being selected itself as a test to run by the test suite. - */ -public class AbstractTestLogging extends QpidBrokerTestCase -{ - public static final long DEFAULT_LOG_WAIT = 2000; - public static final String TEST_LOG_PREFIX = "MESSAGE"; - protected LogMonitor _monitor; - - @Override - public void setUp() throws Exception - { - setLogMessagePrefix(); - - super.setUp(); - _monitor = new LogMonitor(getOutputFile()); - } - - protected void setLogMessagePrefix() - { - //set the message prefix to facilitate scraping from the munged test output. - setSystemProperty("qpid.logging.prefix", TEST_LOG_PREFIX); - } - - @Override - public void tearDown() throws Exception - { - _monitor.close(); - super.tearDown(); - } - - /** - * 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, - findMatches(log).size()); - } - - protected void validateMessageID(String id, String log) - { - assertEquals("Incorrect message", id, getMessageID(log)); - } - - protected String getMessageID(String log) - { - String message = fromMessage(log); - - return message.substring(0, message.indexOf(" ")); - } - - /** - * Return the first channel id from the log string - * ' ch;X' if there is no channel id return -1. - * - * @param log the log string to search. - * - * @return channel id or -1 if no channel id exists. - */ - protected int getChannelID(String log) - { - int start = log.indexOf("ch:") + 3; - - // If we do a check for ] as the boundary we will get cases where log - // is presented with the bounding. If we don't match a ] then we can use - // the end of the string as the boundary. - int end = log.indexOf("]", start); - if (end == -1) - { - end = log.length(); - } - return parseInt(log, start, end); - } - - protected String fromMessage(String log) - {; - 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 - // in which case we can use the end of the actor as the index. - if (start == 0) - { - start = startSubject; - } - - 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; - // Take the second index - start = log.indexOf("[", start) + 1; - - // There may not be a subject so in that case return nothing. - if (start == 0) - { - return ""; - } - - int end = log.indexOf("]", start); - 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); - try - { - return log.substring(start, end).trim(); - } - catch (IndexOutOfBoundsException iobe) - { - return ""; - } - } - - /** - * Return the message String from the given message section - * - * @param log the Message Section - * - * @return the Message String. - */ - protected String getMessageString(String log) - { - // Remove the Log ID from the returned String - int start = log.indexOf(":") + 1; - - return log.substring(start).trim(); - } - - /** - * 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 getConnectionID(String log) - { - int conIDStart = log.indexOf("con:") + 4; - int conIDEnd = log.indexOf("(", conIDStart); - return parseInt(log, conIDStart, conIDEnd); - } - - /** - * Extract the log entry from the raw log. - * - * 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 log formating prefixes - */ - protected String getLog(String rawLog) - { - int start = rawLog.indexOf(TEST_LOG_PREFIX); - return rawLog.substring(start); - } - - /** - * Extract the log entry from the result set. Positions are 0-based. - * - * @param results list of log message results to extract from - * @param position position in the list of the message to extract - * @return the message string - */ - protected String getLogMessage(List<String> results, int position) - { - return getLog(results.get(position)); - } - - /** - * Extract the nth-from-last log entry from the result set. - * - * @param results list of log message results to extract from - * @param positionFromEnd position from end of the message list to extract (eg 0 for last) - * @return the message string - */ - protected String getLogMessageFromEnd(List<String> results, int positionFromEnd) - { - int resultSize = results.size(); - return getLogMessage(results, resultSize - 1 - positionFromEnd); - } - - protected List<String> findMatches(String toFind) throws IOException - { - return _monitor.findMatches(toFind); - } - - protected List<String> waitAndFindMatches(String toFind) throws IOException - { - return waitAndFindMatches(toFind, DEFAULT_LOG_WAIT); - } - - protected List<String> waitAndFindMatches(String toFind, long wait) throws IOException - { - return _monitor.waitAndFindMatches(toFind, wait); - } - - public boolean waitForMessage(String message) throws FileNotFoundException, IOException - { - return waitForMessage(message, DEFAULT_LOG_WAIT); - } - - public boolean waitForMessage(String message, long wait) throws FileNotFoundException, IOException - { - return _monitor.waitForMessage(message, wait); - } - - /** - * 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; - } - - /** - * Dump the log results. - */ - protected void dumpLogs(List<String> results) throws IOException - { - dumpLogs(results, null); - } - - /** - * Dump the log results or if there are none, the contents of the - * monitored log file if the monitor is non-null. - */ - protected void dumpLogs(List<String> results, LogMonitor monitor) throws IOException - { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } - - if (results.isEmpty() && monitor != null) - { - System.err.println("Monitored file contents:"); - System.err.println(monitor.readFile()); - } - } - - private int parseInt(final String logSubstring, final int start, final int end) - { - try - { - final NumberFormat format = NumberFormat.getInstance(Locale.getDefault()); - final Number number = format.parse(logSubstring.substring(start, end)); - return number.intValue(); - } - catch (Exception e) - { - return -1; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b21a8f56/systests/src/test/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java b/systests/src/test/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java deleted file mode 100644 index fa366b4..0000000 --- a/systests/src/test/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * 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 java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.jms.Connection; -import javax.jms.JMSException; -import javax.jms.Session; - -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ExclusivityPolicy; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.test.utils.TestUtils; - -/** - * ACL version 2/3 file testing to verify that ACL actor logging works correctly. - * - * This suite of tests validate that the AccessControl messages occur correctly - * and according to the following format: - * - * <pre> - * ACL-1001 : Allowed Operation Object {PROPERTIES} - * ACL-1002 : Denied Operation Object {PROPERTIES} - * </pre> - */ -public class AccessControlLoggingTest extends AbstractTestLogging -{ - private static final String ACL_LOG_PREFIX = "ACL-"; - private static final String USER = "client"; - private static final String PASS = "guest"; - private Connection _connection; - private Session _session; - - @Override - public void setUp() throws Exception - { - // Write out ACL for this test - TestUtils.writeACLFileUtil(this, "ACL ALLOW client ACCESS VIRTUALHOST", - "ACL ALLOW client CREATE QUEUE name='allow'", - "ACL ALLOW-LOG client CREATE QUEUE name='allow-log'", - "ACL DENY client CREATE QUEUE name='deny'", - "ACL DENY-LOG client CREATE QUEUE name='deny-log'", - "ACL ALLOW client PUBLISH EXCHANGE name='' routingkey='$management"); - - super.setUp(); - - _connection = getConnection(USER, PASS); - _session = _connection.createSession(true, Session.SESSION_TRANSACTED); - _connection.start(); - - } - - @Override - public void tearDown() throws Exception - { - try - { - _connection.close(); - super.tearDown(); - } - catch (JMSException e) - { - //we're throwing this away as it can happen in this test as the state manager remembers exceptions - //that we provoked with authentication failures, where the test passes - we can ignore on con close - } - } - - /** - * Test that {@code allow} ACL entries do not log anything. - */ - public void testAllow() throws Exception - { - String name = "allow"; - boolean autoDelete = false; - boolean durable = false; - boolean exclusive = false; - createQueue(name, autoDelete, durable, exclusive); - - List<String> matches = findMatches(ACL_LOG_PREFIX + 1001); - - assertTrue("Should be no ACL log messages", matches.isEmpty()); - } - - protected void createQueue(final String name, - final boolean autoDelete, - final boolean durable, final boolean exclusive) - throws JMSException - { - Map<String,Object> attributes = new LinkedHashMap<>(); - attributes.put(ConfiguredObject.NAME, name); - attributes.put(ConfiguredObject.DURABLE, durable); - LifetimePolicy lifetimePolicy; - ExclusivityPolicy exclusivityPolicy; - - if (exclusive) - { - lifetimePolicy = autoDelete - ? LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS - : durable ? LifetimePolicy.PERMANENT : LifetimePolicy.DELETE_ON_CONNECTION_CLOSE; - exclusivityPolicy = durable ? ExclusivityPolicy.CONTAINER : ExclusivityPolicy.CONNECTION; - } - else - { - lifetimePolicy = autoDelete ? LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS : LifetimePolicy.PERMANENT; - exclusivityPolicy = ExclusivityPolicy.NONE; - } - - attributes.put(Queue.EXCLUSIVE, exclusivityPolicy.toString()); - attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy.toString()); - createEntityUsingAmqpManagement(name, _session, "org.apache.qpid.Queue", attributes); - } - - /** - * Test that {@code allow-log} ACL entries log correctly. - */ - public void testAllowLog() throws Exception - { - createQueue("allow-log", false, false, false); - - List<String> matches = findMatches(ACL_LOG_PREFIX + 1001); - - assertEquals("Should only be one ACL log message", 1, matches.size()); - - String log = getLogMessage(matches, 0); - String actor = fromActor(log); - String subject = fromSubject(log); - String message = getMessageString(fromMessage(log)); - - validateMessageID(ACL_LOG_PREFIX + 1001, log); - - assertTrue("Actor " + actor + " should contain the user identity: " + USER, actor.contains(USER)); - assertTrue("Subject should be empty", subject.length() == 0); - assertTrue("Message should start with 'Allowed'", message.startsWith("Allowed")); - assertTrue("Message should contain 'Create Queue'", message.contains("Create Queue")); - assertTrue("Message should have contained the queue name", message.contains("allow-log")); - } - - /** - * Test that {@code deny-log} ACL entries log correctly. - */ - public void testDenyLog() throws Exception - { - createQueue("deny-log", false, false, false); - - List<String> matches = findMatches(ACL_LOG_PREFIX + 1002); - - assertEquals("Should only be one ACL log message", 1, matches.size()); - - String log = getLogMessage(matches, 0); - String actor = fromActor(log); - String subject = fromSubject(log); - String message = getMessageString(fromMessage(log)); - - validateMessageID(ACL_LOG_PREFIX + 1002, log); - - assertTrue("Actor " + actor + " should contain the user identity: " + USER, actor.contains(USER)); - assertTrue("Subject should be empty", subject.length() == 0); - assertTrue("Message should start with 'Denied'", message.startsWith("Denied")); - assertTrue("Message should contain 'Create Queue'", message.contains("Create Queue")); - assertTrue("Message should have contained the queue name", message.contains("deny-log")); - } - - /** - * Test that {@code deny} ACL entries do not log anything. - */ - public void testDeny() throws Exception - { - createQueue("deny", false, false, false); - - List<String> matches = findMatches(ACL_LOG_PREFIX + 1002); - - assertTrue("Should be no ACL log messages", matches.isEmpty()); - } -} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b21a8f56/systests/src/test/java/org/apache/qpid/server/logging/AlertingTest.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/logging/AlertingTest.java b/systests/src/test/java/org/apache/qpid/server/logging/AlertingTest.java deleted file mode 100644 index 3830f96..0000000 --- a/systests/src/test/java/org/apache/qpid/server/logging/AlertingTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/* -* -* 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 java.util.Collections; - -import javax.jms.Connection; -import javax.jms.Queue; -import javax.jms.Session; - -import org.apache.qpid.systest.rest.RestTestHelper; -import org.apache.qpid.test.utils.TestBrokerConfiguration; - -public class AlertingTest extends AbstractTestLogging -{ - - private Session _session; - private Connection _connection; - private Queue _destination; - private int _numMessages; - - private static final int ALERT_LOG_WAIT_PERIOD = 5000; - private static final String MESSAGE_COUNT_ALERT = "MESSAGE_COUNT_ALERT"; - - @Override - public void setUp() throws Exception - { - _numMessages = 50; - setTestSystemProperty("virtualhost.housekeepingCheckPeriod", String.valueOf(ALERT_LOG_WAIT_PERIOD)); - setTestSystemProperty("queue.alertThresholdQueueDepthMessages", String.valueOf(_numMessages)); - - // Then we do the normal setup stuff like starting the broker, getting a connection etc. - super.setUp(); - - setupConnection(); - } - - /** - * Create a new connection and ensure that our destination queue is created - * and bound. - * - * Note that the tests here that restart the broker rely on persistence. - * However, the queue creation here is transient. So the queue will not be - * rebound on restart. Hence the consumer creation here rather than just the - * once. - * - * The persistent messages will recreate the queue but not bind it (as it - * was not a durable queue) However, the consumer creation here will ensure - * that the queue is correctly bound and can receive new messages. - * - * @throws Exception - */ - private void setupConnection() - throws Exception - { - _connection = getConnection(); - _connection.start(); - _session = _connection.createSession(true, Session.SESSION_TRANSACTED); - _destination = createTestQueue(_session); - - } - - /** - * Checks the log file for MESSAGE_COUNT_ALERT, fails() the test if it's not found and - * places the entire contents in the message to help debug cruise control failures. - * - * @throws Exception - */ - private void wasAlertFired() throws Exception - { - if (!waitForMessage(MESSAGE_COUNT_ALERT, ALERT_LOG_WAIT_PERIOD)) - { - StringBuffer message = new StringBuffer("Could not find 'MESSAGE_COUNT_ALERT' in log file: " + _monitor.getMonitoredFile().getAbsolutePath()); - fail(message.toString()); - } - } - - public void testAlertingReallyWorks() throws Exception - { - // Send 5 messages, make sure that the alert was fired properly. - sendMessage(_session, _destination, _numMessages + 1); - _session.commit(); - wasAlertFired(); - } - - public void testAlertingReallyWorksWithRestart() throws Exception - { - sendMessage(_session, _destination, _numMessages + 1); - _session.commit(); - _connection.close(); - stopDefaultBroker(); - - startDefaultBroker(); - wasAlertFired(); - } - - /** - * Test that if the alert value is change from the previous value we can - * still get alerts. - * - * Test sends two messages to the broker then restarts the broker with new - * configuration. - * - * Validates that we only have two messages on the queue and then sends - * enough messages to trigger the alert. - * - * The alert is then validate. - * - * - * @throws Exception - */ - public void testAlertingReallyWorksWithChanges() throws Exception - { - // send some messages and nuke the logs - sendMessage(_session, _destination, 2); - _session.commit(); - // To prevent any failover/retry/connection dropped errors - _connection.close(); - - stopDefaultBroker(); - - TestBrokerConfiguration config = getDefaultBrokerConfiguration(); - config.addHttpManagementConfiguration(); - config.setSaved(false); - - startDefaultBroker(); - - setupConnection(); - - // Validate the queue depth is as expected - long messageCount = getQueueDepth(_connection, _destination); - assertEquals("Broker has invalid message count for test", 2, messageCount); - - // Ensure the alert has not occurred yet - assertLoggingNotYetOccured(MESSAGE_COUNT_ALERT); - - // Change max message count to 5, start broker and make sure that that's triggered at the right time - TestBrokerConfiguration brokerConfiguration = getDefaultBrokerConfiguration(); - setTestSystemProperty("queue.alertThresholdQueueDepthMessages","5"); - brokerConfiguration.setSaved(false); - - RestTestHelper restTestHelper = new RestTestHelper(getDefaultBroker().getHttpPort()); - try - { - restTestHelper.submitRequest("queue/test/test/" + getTestQueueName(), - "PUT", - Collections.<String, Object>singletonMap(org.apache.qpid.server.model.Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, - 5)); - } - finally - { - restTestHelper.tearDown(); - } - - // Trigger the new value - sendMessage(_session, _destination, 3); - _session.commit(); - - // Validate that the alert occurred. - wasAlertFired(); - } -} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b21a8f56/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java deleted file mode 100644 index 9e1fc07..0000000 --- a/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java +++ /dev/null @@ -1,861 +0,0 @@ -/* -* -* 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 java.io.IOException; -import java.net.Socket; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import junit.framework.AssertionFailedError; - -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.test.utils.BrokerHolder; -import org.apache.qpid.test.utils.TestBrokerConfiguration; -import org.apache.qpid.transport.ConnectionException; -import org.apache.qpid.util.LogMonitor; - -/** - * Broker Test Suite - * - * The Broker test suite validates that the follow log messages as specified in the Functional Specification. - * - * BRK-1001 : Startup : Version: <Version> Build: <Build> - * BRK-1002 : Starting : Listening on <Transport> port <Port> - * BRK-1003 : Shutting down : <Transport> port <Port> - * BRK-1004 : Ready - * BRK-1005 : Stopped - * BRK-1006 : Using configuration : <path> - * BRK-1007 : Using logging configuration : <path> - * - * These messages should only occur during startup. The tests need to verify the order of messages. In the case of the BRK-1002 and BRK-1003 the respective ports should only be available between the two log messages. - */ -public class BrokerLoggingTest extends AbstractTestLogging -{ - private static final String BROKER_MESSAGE_LOG_REG_EXP = ".*\\[\\w*\\] (BRK\\-\\d*) .*"; - private static final Pattern BROKER_MESSAGE_LOG_PATTERN = Pattern.compile(BROKER_MESSAGE_LOG_REG_EXP); - private static final String BRK_LOG_PREFIX = "BRK-"; - - - @Override - public void startDefaultBroker() - { - // noop. we do not want to start broker - } - - /** - * Description: - * On startup the broker must report the active configuration file. The - * logging system must output this so that we can know what configuration - * is being used for this broker instance. - * - * Input: - * The value of -c specified on the command line. - * Output: - * <date> MESSAGE BRK-1006 : Using configuration : <config file> - * Constraints: - * This MUST BE the first BRK log message. - * - * Validation Steps: - * 1. This is first BRK log message. - * 2. The BRK ID is correct - * 3. The config file is the full path to the file specified on - * the commandline. - * - * @throws Exception caused by broker startup - */ - public void testBrokerStartupConfiguration() throws Exception - { - String TESTID="BRK-1006"; - - if (isJavaBroker()) - { - super.startDefaultBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(getOutputFile()); - - - String configFilePath = getDefaultBroker().getConfigurationPath(); - - // Ensure we wait for TESTID to be logged - waitAndFindMatches(TESTID); - - List<String> results = waitAndFindMatches(BRK_LOG_PREFIX); - try - { - // Validation - - assertTrue("BRKer message not logged", results.size() > 0); - - String log = getLogMessage(results, 0); - - //1 - validateMessageID(TESTID, log); - - //2 - results = findMatches(TESTID); - assertEquals("More than one configuration message found.", - 1, results.size()); - - //3 - assertTrue("Config file details not correctly logged, got " - + log + " but expected it to end with " + configFilePath, - log.endsWith(configFilePath)); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - - - /** - * Description: On startup the broker reports the broker version number and svn build revision. This information is retrieved from the resource 'qpidversion.properties' which is located via the classloader. - * Input: The 'qpidversion.properties' file located on the classpath. - * Output: - * - * <date> MESSAGE BRK-1001 : Startup : qpid Version: 0.6 Build: 767150 - * - * Validation Steps: - * - * 1. The BRK ID is correct - * 2. This occurs before any BRK-1002 listening messages are reported. - * - * @throws Exception caused by broker startup - */ - public void testBrokerStartupStartup() throws Exception - { - // This logging startup code only occurs when you run a Apache Qpid Broker-J, - // that broker must be started via Main so not an InVM broker. - if (isJavaBroker()) - { - String TESTID = "BRK-1001"; - - super.startDefaultBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(getOutputFile()); - - // Ensure we wait for TESTID to be logged - waitAndFindMatches(TESTID); - - // Retrieve all BRK- log messages so we can check for an erroneous - // BRK-1002 message. - List<String> results = findMatches(BRK_LOG_PREFIX); - - try - { - // Validation - - assertTrue("BRKer message not logged", results.size() > 0); - - boolean validation = false; - for (String rawLog : results) - { - if (validation) - { - //Stop checking once we have got to our startup test - break; - } - String log = getLog(rawLog); - - // Ensure we do not have a BRK-1002 message - if (!getMessageID(log).equals(TESTID)) - { - assertFalse(getMessageID(log).equals("BRK-1002")); - continue; - } - - //1 - validateMessageID(TESTID, log); - - //2 - //There will be 2 copies of the startup message (one via SystemOut, and one via Log4J) - assertEquals("Unexpected startup message count", - 1, findMatches(TESTID).size()); - - validation = true; - } - - assertTrue("Validation not performed: " + TESTID + " not logged", validation); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - - /** - * Description: - * On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available. - * Input: - * The default configuration with no SSL - * Output: - * - * <date> MESSAGE BRK-1002 : Starting : Listening on TCP port 5672 - * - * Constraints: - * Additional broker configuration will occur between the Startup(BRK-1001) and Starting(BRK-1002) messages depending on what VirtualHosts are configured. - * Validation Steps: - * - * 1. The BRK ID is correct - * 2. This occurs after the BRK-1001 startup message - * 3. Using the default configuration a single BRK-1002 will be printed showing values TCP / 5672 - * - * @throws Exception caused by broker startup - */ - public void testBrokerStartupListeningTCPDefault() throws Exception - { - if (isJavaBroker()) - { - String TESTID = "BRK-1002"; - - super.startDefaultBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(getOutputFile()); - - // Ensure broker has fully started up. - getConnection(); - - // Ensure we wait for TESTID to be logged - waitAndFindMatches(TESTID); - - // Retrieve all BRK- log messages so we can check for an erroneous - // BRK-1002 message. - List<String> results = findMatches(BRK_LOG_PREFIX); - try - { - // Validation - - assertTrue("BRKer message not logged", results.size() > 0); - - boolean validation = false; - boolean foundBRK1001 = false; - for (String rawLog : results) - { - String log = getLog(rawLog); - - // using custom method to get id as getMessageId() fails to correctly identify id - // because of using brackets for protocols - String id = getBrokerLogId(log); - // Ensure we do not have a BRK-1002 message - if (!id.equals(TESTID)) - { - if (id.equals("BRK-1001")) - { - foundBRK1001 = true; - } - continue; - } - - assertTrue("BRK-1001 not logged before this message", foundBRK1001); - - //1 - assertEquals("Incorrect message", TESTID, id); - - //2 - assertEquals("Unexpected listen message count", - 1, findMatches(TESTID).size()); - - //3 - String message = getMessageString(log); - assertTrue("Expected Listen log not correct" + message, - message.endsWith("Listening on TCP port " + getDefaultBroker().getAmqpPort())); - - validation = true; - } - - assertTrue("Validation not performed: " + TESTID + " not logged", validation); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - - private String getBrokerLogId(String log) - { - Matcher m = BROKER_MESSAGE_LOG_PATTERN.matcher(log); - if (m.matches()) - { - return m.group(1); - } - return getMessageID(log); - } - - /** - * Description: - * On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available. - * Input: - * The default configuration with SSL enabled - * Output: - * - * <date> MESSAGE BRK-1002 : Starting : Listening on TCP port 5672 - * <date> MESSAGE BRK-1002 : Starting : Listening on TCP/SSL port 8672 - * - * Constraints: - * Additional broker configuration will occur between the Startup(BRK-1001) and Starting(BRK-1002) messages depending on what VirtualHosts are configured. - * Validation Steps: - * - * 1. The BRK ID is correct - * 2. This occurs after the BRK-1001 startup message - * 3. With SSL enabled in the configuration two BRK-1002 will be printed (order is not specified) - * 1. One showing values [TCP] 5672 - * 2. One showing values [SSL] 5671 - * - * @throws Exception caused by broker startup - */ - public void testBrokerStartupListeningTCPSSL() throws Exception - { - if (isJavaBroker()) - { - String TESTID = "BRK-1002"; - - // Enable SSL on the connection - Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); - sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); - sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); - sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); - sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); - sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); - getDefaultBrokerConfiguration().addObjectConfiguration(Port.class, sslPortAttributes); - - super.startDefaultBroker(); - - final BrokerHolder defaultBroker = getDefaultBroker(); - int amqpTlsPort = defaultBroker.getAmqpTlsPort(); - int amqpPort = defaultBroker.getAmqpPort(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(getOutputFile()); - - // Ensure broker has fully started up. - getConnection(); - - // Ensure we wait for TESTID to be logged - waitAndFindMatches(TESTID); - - // Retrieve all BRK- log messages so we can check for an erroneous - // BRK-1002 message. - List<String> results = findMatches(BRK_LOG_PREFIX); - try - { - // Validation - - assertTrue("BRKer message not logged", results.size() > 0); - - boolean validation = false; - boolean foundBRK1001 = false; - for (String rawLog : results) - { - String log = getLog(rawLog); - - String id = getBrokerLogId(log); - // Ensure we do not have a BRK-1002 message - if (!id.equals(TESTID)) - { - if (id.equals("BRK-1001")) - { - foundBRK1001 = true; - } - continue; - } - - assertTrue("BRK-1001 not logged before this message", foundBRK1001); - - //1 - assertEquals("Incorrect message", TESTID, id); - - //2 - //There will be 4 copies of the startup message (two via SystemOut, and two via Log4J) - List<String> listenMessages = findMatches(TESTID); - assertEquals("Four listen messages should be found.", - 2, listenMessages .size()); - - int tcpStarted = 0; - int sslStarted = 0; - - for (String message : listenMessages) - { - if (message.endsWith("Listening on TCP port " + amqpPort)) - { - tcpStarted++; - } - if (message.endsWith("Listening on SSL port " + amqpTlsPort)) - { - sslStarted++; - } - } - - assertEquals("Unexpected number of logs 'Listening on TCP port'", 1, tcpStarted); - assertEquals("Unexpected number of logs 'Listening on SSL port'", 1, sslStarted); - - //4 Test ports open - testSocketOpen(amqpPort); - testSocketOpen(amqpTlsPort); - - validation = true; - } - - assertTrue("Validation not performed: " + TESTID + " not logged", validation); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - - /** - * Description: - * The final message the broker will print when it has performed all initialisation and listener startups will be to log the BRK-1004 Ready message - * Input: - * No input, all successful broker startups will show BRK-1004 messages. - * Output: - * - * 2009-07-09 15:50:20 +0100 MESSAGE BRK-1004 : Qpid Broker Ready - * - * Validation Steps: - * - * 1. The BRK ID is correct - * 2. This occurs after the BRK-1001 startup message - * 3. This must be the last message the broker prints after startup. Currently, if there is no further interaction with the broker then there should be no more logging. - * - * @throws Exception caused by broker startup - */ - public void testBrokerStartupReady() throws Exception - { - if (isJavaBroker()) - { - String TESTID = "BRK-1004"; - - super.startDefaultBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(getOutputFile()); - - //Ensure the broker has fully started up. - getConnection(); - // Ensure we wait for TESTID to be logged - waitAndFindMatches(TESTID); - - // Retrieve all BRK- log messages so we can check for an erroneous - // BRK-1001 message. - List<String> results = findMatches(BRK_LOG_PREFIX); - try - { - // Validation - - assertTrue("BRKer message not logged", results.size() > 0); - - boolean validationComplete = false; - boolean foundBRK1001 = false; - - for (int i=0; i < results.size(); i++) - { - String rawLog = results.get(i); - String log = getLog(rawLog); - - // Ensure we do not have a BRK-1001 message - if (!getMessageID(log).equals(TESTID)) - { - if (getMessageID(log).equals("BRK-1001")) - { - foundBRK1001 = true; - } - continue; - } - - assertTrue("BRK-1001 not logged before this message", foundBRK1001); - - //1 - validateMessageID(TESTID, log); - - //2 - assertEquals("Ready message not present", "Qpid Broker Ready", getMessageString(log)); - - assertEquals("Unexpected ready message count", - 1, findMatches(TESTID).size()); - assertEquals("The ready messages should have been the last 2 messages", results.size() - 1, i); - - validationComplete = true; - break; - } - - assertTrue("Validation not performed: " + TESTID + " not logged", validationComplete); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - - /** - * Description: - * On startup the broker may listen on a number of ports and protocols. Each of these must then report a shutting down message as they stop listening. - * Input: - * The default configuration with no SSL - * Output: - * - * <date> MESSAGE BRK-1003 : Shutting down : TCP port 5672 - * - * Validation Steps: - * - * 1. The BRK ID is correct - * 2. Only TCP is reported with the default configuration with no SSL. - * 3. The default port is correct - * 4. The port is not accessible after this message - * - * @throws Exception caused by broker startup - */ - public void testBrokerShutdownListeningTCPDefault() throws Exception - { - if (isJavaBroker() && isInternalBroker()) - { - String TESTID = "BRK-1003"; - - super.startDefaultBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(getOutputFile()); - - stopDefaultBroker(); - - //Give broker time to shutdown and flush log - checkSocketClosed(getDefaultBroker().getAmqpPort()); - - List<String> results = waitAndFindMatches(BRK_LOG_PREFIX); - try - { - // Validation - - assertTrue("BRKer message not logged", results.size() > 0); - - boolean validation = false; - boolean foundBRK1001 = false; - for (String rawLog : results) - { - String log = getLog(rawLog); - - // Ensure we do not have a BRK-1002 message - if (!getMessageID(log).equals(TESTID)) - { - if (getMessageID(log).equals("BRK-1001")) - { - foundBRK1001 = true; - } - continue; - } - - assertTrue("BRK-1001 not logged before this message", foundBRK1001); - - //1 - validateMessageID(TESTID, log); - - //2 - assertEquals("More than one listen message found.", - 1, findMatches(TESTID).size()); - - //3 - String message = getMessageString(log); - final int amqpPort = getDefaultBroker().getAmqpPort(); - assertTrue("Expected shutdown log not correct" + message, - message.endsWith("TCP port " + amqpPort)); - - //4 - checkSocketClosed(amqpPort); - - validation = true; - } - - assertTrue("Validation not performed: " + TESTID + " not logged", validation); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - - /** - * Description: - * On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available. - * Input: - * The default configuration with SSL enabled - * Output: - * - * <date> MESSAGE BRK-1002 : Starting : Listening on TCP port 5672 - * <date> MESSAGE BRK-1002 : Starting : Listening on TCP/SSL port 8672 - * - * Constraints: - * Additional broker configuration will occur between the Startup(BRK-1001) and Starting(BRK-1002) messages depending on what VirtualHosts are configured. - * Validation Steps: - * - * 1. The BRK ID is correct - * 2. This occurs after the BRK-1001 startup message - * 3. With SSL enabled in the configuration two BRK-1002 will be printed (order is not specified) - * 1. One showing values TCP / 5672 - * 2. One showing values TCP/SSL / 5672 - * - * @throws Exception caused by broker startup - */ - public void testBrokerShutdownListeningTCPSSL() throws Exception - { - if (isJavaBroker() && isInternalBroker()) - { - String TESTID = "BRK-1003"; - - // Enable SSL on the connection - Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); - sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); - sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); - sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); - sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); - sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); - getDefaultBrokerConfiguration().addObjectConfiguration(Port.class, sslPortAttributes); - - super.startDefaultBroker(); - - final BrokerHolder defaultBroker = getDefaultBroker(); - int amqpTlsPort = defaultBroker.getAmqpTlsPort(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(getOutputFile()); - - -// //Clear any startup messages as we don't need them for validation -// _monitor.reset(); - //Stop the broker to get the log messages for testing - stopDefaultBroker(); - - //Give broker time to shutdown and flush log - final int amqpPort = getDefaultBroker().getAmqpPort(); - checkSocketClosed(amqpPort); - - List<String> results = waitAndFindMatches(TESTID); - try - { - // Validation - - assertTrue(TESTID + " messages not logged", results.size() > 0); - - String log = getLog(results.get(0)); - - //1 - validateMessageID(TESTID, log); - - //2 - List<String> listenMessages = findMatches(TESTID); - assertEquals("Two shutdown messages should be found.", - 2, listenMessages.size()); - - int tcpShuttingDown = 0; - int sslShuttingDown = 0; - - for (String m : listenMessages) - { - if (m.endsWith("Shutting down : TCP port " + amqpPort)) - { - tcpShuttingDown++; - } - if (m.endsWith("Shutting down : SSL port " + amqpTlsPort)) - { - sslShuttingDown++; - } - } - - assertEquals("Unexpected number of logs 'Shutting down : TCP port'", 1, tcpShuttingDown); - assertEquals("Unexpected number of logs 'Shutting down : SSL port'", 1, sslShuttingDown); - - //4 - //Test Port closed - checkSocketClosed(amqpPort); - //Test SSL Port closed - checkSocketClosed(amqpTlsPort); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - - /** - * Description: - * Input: - * No input, all clean broker shutdowns will show BRK-1005 messages. - * Output: - * - * <date> MESSAGE BRK-1005 : Stopped - * - * Constraints: - * This is the LAST message the broker will log. - * Validation Steps: - * - * 1. The BRK ID is correct - * 2. This is the last message the broker will log. - * - * @throws Exception caused by broker startup - */ - public void testBrokerShutdownStopped() throws Exception - { - if (isJavaBroker() && isInternalBroker()) - { - String TESTID = "BRK-1005"; - - super.startDefaultBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(getOutputFile()); - - getConnection().close(); - - stopDefaultBroker(); - - final int amqpPort = getDefaultBroker().getAmqpPort(); - - // Ensure the broker has shutdown before retreving results - checkSocketClosed(amqpPort); - - waitAndFindMatches(TESTID); - - List<String> results = waitAndFindMatches(BRK_LOG_PREFIX); - try - { - // Validation - - assertTrue("BRKer message not logged", results.size() > 0); - - boolean validation = false; - for (String rawLog : results) - { - assertFalse("More broker log statements present after ready message", validation); - String log = getLog(rawLog); - - // Ignore all logs until we get to the test id. - if (!getMessageID(log).equals(TESTID)) - { - continue; - } - - //1 - validateMessageID(TESTID, log); - - //2 - assertEquals("More than one ready message found.", - 1, findMatches(TESTID).size()); - - //3 - assertEquals("Stopped message not present", "Stopped", getMessageString(log)); - - validation = true; - } - - assertTrue("Validation not performed: " + TESTID + " not logged", validation); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - - /** - * Test that a socket on the given port is closed. - * - * Does this by attempting to connect to the port and expecting a - * ConnectionRefused IOException or a ConnectionException - * - * @param port the port number - */ - private void checkSocketClosed(int port) - { - try - { - Socket socket = new Socket((String) null, port); - fail("Socket not closed on port:" + port); - } - catch (ConnectionException e) - { - //normal path - } - catch (IOException e) - { - if (!e.getMessage().startsWith("Connection refused")) - { - fail("Socket not closed on port:" + port + ":" + e.getMessage()); - // Keep stack trace for diagnosis. - e.printStackTrace(System.err); - } - } - } - - /** - * Test that a socket on the given port is open. - * - * Does this by attempting to connect to the port and expecting a - * The connection to succeed. - * It then closes the socket and expects that to work cleanly. - * - * @param port the port number - */ - private void testSocketOpen(int port) - { - try - { - Socket socket = new Socket((String) null, port); - socket.close(); - } - catch (IOException e) - { - fail("Unable to open and close socket to port:" + port - + ". Due to:" + e.getMessage()); - } - } - -} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b21a8f56/systests/src/test/java/org/apache/qpid/server/logging/ChannelLoggingTest.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/logging/ChannelLoggingTest.java b/systests/src/test/java/org/apache/qpid/server/logging/ChannelLoggingTest.java deleted file mode 100644 index f16398c..0000000 --- a/systests/src/test/java/org/apache/qpid/server/logging/ChannelLoggingTest.java +++ /dev/null @@ -1,384 +0,0 @@ -/* - * - * 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 java.util.List; -import java.util.regex.Pattern; - -import javax.jms.Connection; -import javax.jms.MessageConsumer; -import javax.jms.Queue; -import javax.jms.Session; - -import org.apache.qpid.QpidException; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQDestination; -import org.apache.qpid.client.AMQSession; -import org.apache.qpid.server.virtualhost.VirtualHostPropertiesNodeCreator; - -public class ChannelLoggingTest extends AbstractTestLogging -{ - private static final String CHANNEL_CLOSE_FORCED_MESSAGE_PATTERN = "CHN-1003 : Close : \\d* - .*"; - private static final String CHANNEL_PREFIX = "CHN-"; - - @Override - public void setUp() throws Exception - { - - // disable the virtualhostPropertiesNode as it messes with the logging since it causes the client to - // create a session and then it sends a message - setTestSystemProperty("qpid.plugin.disabled:systemnodecreator."+ VirtualHostPropertiesNodeCreator.TYPE, "true"); - super.setUp(); - } - - /** - * Description: - * When a new Channel (JMS Session) is created this will be logged as a CHN-1001 Create message. The messages will contain the prefetch details about this new Channel. - * Input: - * - * 1. Running Broker - * 2. New JMS Session/Channel creation - * - * Output: - * <date> CHN-1001 : Create - * <date> CHN-1004 : Prefetch Size (bytes) {0,number} : Count {1,number} - * - * Validation Steps: - * 1. The CHN ID is correct - * 2. The prefetch value matches that defined by the requesting client. - * - * @throws Exception - if an error occurs - */ - public void testChannelCreate() throws Exception - { - assertLoggingNotYetOccured(CHANNEL_PREFIX); - - Connection connection = getConnection(); - - int PREFETCH = 12; - - if(!(isBroker010() || isBroker10())) - { - // Test that calling session.close gives us the expected output - ((AMQConnection) connection).createSession(false, Session.AUTO_ACKNOWLEDGE, PREFETCH); - } - else - { - connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - } - - // Wait to ensure that the CHN-1001 message is logged - waitForMessage("CHN-1001"); - - List<String> results = findMatches("CHN-1001"); - - // Validation - assertEquals("CHN-1001 messages not logged", isBroker10() ? 2 : 1, results.size()); - - String log = getLogMessage(results, isBroker10() ? 1 : 0); - // MESSAGE [con:0(guest@anonymous(3273383)/test)/ch:1] CHN-1001 : Create - validateMessageID("CHN-1001", log); - final String fromActor = fromActor(log); - final int channelID = getChannelID(fromActor); - assertEquals("Incorrect Channel in actor:"+fromActor(log), isBroker010()? 0 : 1, channelID); - - if (!(isBroker010() || isBroker10())) - { - // Wait to ensure that the CHN-1004 message is logged - waitForMessage("CHN-1004"); - - results = findMatches("CHN-1004"); - - // Validation - assertEquals("CHN-1004 messages not logged", 1, results.size()); - log = getLogMessage(results, 0); - // MESSAGE [con:0(guest@anonymous(3273383)/test)/ch:1] CHN-1004 : Prefetch Size (bytes) {0,number} : Count {1,number} - validateMessageID("CHN-1004", log); - assertEquals("Incorrect Channel in actor:"+fromActor(log), 1, getChannelID(fromActor(log))); - assertTrue("Prefetch Count not correct",getMessageString(fromMessage(log)).endsWith("Count "+PREFETCH)); - } - - connection.close(); - } - - /** - * Description: - * The Apache Qpid Broker-J implements consumer flow control for all ack modes except - * No-Ack. When a client connects the session's flow is initially set to - * Stopped. Verify this message appears - * - * Input: - * 1. Running broker - * 2. Create consumer - * Output: - * - * <date> CHN-1002 : Flow Stopped - * - * Validation Steps: - * 4. The CHN ID is correct - * - * @throws Exception - if an error occurs - */ - - public void testChannelStartsFlowStopped() throws Exception - { - assertLoggingNotYetOccured(CHANNEL_PREFIX); - - Connection connection = getConnection(); - - // Create a session to fill up - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - Queue queue = createTestQueue(session); - - connection.start(); - - // Wait to ensure that the CHN-1002 message is logged - waitForMessage("CHN-1002"); - - List<String> results = findMatches(CHANNEL_PREFIX); - - assertTrue("No CHN messages logged", results.size() > 0); - - // The last channel message should be: - // - // INFO - MESSAGE [con:0(guest@anonymous(4205299)/test)/ch:1] [con:0(guest@anonymous(4205299)/test)/ch:1] CHN-1002 : Flow Stopped - - // Verify the last channel message is stopped - validateChannelStart(results, false); - } - - private void validateChannelStart(List<String> results, boolean flowStarted) - { - String log = getLogMessageFromEnd(results, 0); - - String flow = flowStarted ? "Started" : "Stopped"; - validateMessageID("CHN-1002", log); - assertEquals("Message should be Flow " + flow, "Flow " + flow, getMessageString(fromMessage(log))); - } - - /** - * Description: - * The Apache Qpid Broker-J implements consumer flow control for all ack modes except - * No-Ack. When the client first attempts to receive a message then the Flow - * status of the Session is set to Started. - * - * Input: - * 1. Running broker - * 2. Create a consumer - * 3. Attempt to receive a message - * Output: - * - * <date> CHN-1002 : Flow Started - * - * Validation Steps: - * 4. The CHN ID is correct - * - * @throws Exception - if an error occurs - */ - - public void testChannelStartConsumerFlowStarted() throws Exception - { - assertLoggingNotYetOccured(CHANNEL_PREFIX); - - Connection connection = getConnection(); - - // Create a session to fill up - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - Queue queue = createTestQueue(session); - - MessageConsumer consumer = session.createConsumer(queue); - - connection.start(); - - //Call receive to send the Flow On message - consumer.receiveNoWait(); - - //Wait for up to 2 seconds for message to appear - // ignore response as we will use the findMatches afterwards just - // incase it did take more than 2 seconds to log. - _monitor.waitForMessage(CHANNEL_PREFIX, 2000); - - // Wait to ensure that the CHN-1002 message is logged - waitForMessage("CHN-1002"); - - List<String> results = findMatches(CHANNEL_PREFIX); - - assertTrue("No CHN messages logged", results.size() > 0); - - // The last two channel messages(before the close) should be: - // - // INFO [qpid.message] MESSAGE [con:1(guest@/127.0.0.1:49869/test)/ch:1] [con:1(guest@/127.0.0.1:49869/test)/ch:1] CHN-1002 : Flow Stopped - // INFO [qpid.message] MESSAGE [con:1(guest@/127.0.0.1:49869/test)/ch:1] [con:1(guest@/127.0.0.1:49869/test)/ch:1] CHN-1002 : Flow Started - - // Verify the last channel msg is Started. - validateChannelStart(results, true); - } - - /** - * Description: - * When the client gracefully closes the Connection then a CHN-1003 Close - * message will be issued. This must be the last message logged for this - * Channel. - * Input: - * 1. Running Broker - * 2. Connected Client - * 3. Client then requests that the Connection is closed - * Output: - * - * <date> CHN-1003 : Close - * - * Validation Steps: - * 4. The MST ID is correct - * 5. This must be the last message logged for this Channel. - * - * @throws Exception - if an error occurs - */ - public void testChannelCloseViaConnectionClose() throws Exception - { - assertLoggingNotYetOccured(CHANNEL_PREFIX); - - Connection connection = getConnection(); - - // Create a session - connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Close the connection to verify the created session closing is logged. - connection.close(); - - // Wait to ensure that the CHN-1003 message is logged - waitForMessage("CHN-1003"); - - List<String> results = findMatches(CHANNEL_PREFIX); - - assertTrue("No CHN messages logged", results.size() > 0); - - // The last two channel messages should be: - // - // INFO - MESSAGE [con:0(guest@anonymous(4205299)/test)/ch:1] [con:0(guest@anonymous(4205299)/test)/ch:1] CHN-1002 : Flow On - - // Verify - validateChannelClose(results); - } - - /** - * Description: - * When the client gracefully closes the Connection then a CHN-1003 Close - * message will be issued. This must be the last message logged for this - * Channel. - * Input: - * 1. Running Broker - * 2. Connected Client - * 3. Client then requests that the Channel is closed - * Output: - * - * <date> CHN-1003 : Close - * - * Validation Steps: - * 4. The MST ID is correct - * 5. This must be the last message logged for this Channel. - * - * @throws Exception - if an error occurs - */ - public void testChannelCloseViaChannelClose() throws Exception - { - assertLoggingNotYetOccured(CHANNEL_PREFIX); - - Connection connection = getConnection(); - - // Create a session and then close it - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - waitForMessage("CHN-1001"); - - // Wait to ensure that the CHN-1003 message is logged - session.close(); - waitForMessage("CHN-1003"); - - List<String> results = findMatches(CHANNEL_PREFIX); - - assertTrue("No CHN messages logged", results.size() > 0); - - // Verify - validateChannelClose(results); - } - - public void testChannelClosedOnExclusiveQueueDeclaredOnDifferentSession() throws Exception - { - assertLoggingNotYetOccured(CHANNEL_PREFIX); - - Connection connection = getConnection(); - - // Create a session and then close it - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - waitForMessage("CHN-1001"); - - Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - waitForMessage("CHN-1001"); - - String testQueueName = getTestQueueName(); - - Queue queue = (Queue) session.createQueue("direct://amq.direct/" + testQueueName + "/" + testQueueName - + "?exclusive='true'"); - - ((AMQSession<?,?>)session).declareAndBind((AMQDestination)queue); - - try - { - ((AMQSession<?,?>)session2).declareAndBind((AMQDestination) queue); - fail("Exception not thrown"); - } - catch (QpidException acce) - { - // pass - } - catch (Exception e) - { - fail("Wrong exception thrown " + e); - } - waitForMessage("CHN-1003"); - - List<String> results = findMatches(CHANNEL_PREFIX); - assertTrue("No CHN messages logged", results.size() > 0); - - String closeLog = results.get(results.size() -1); - int closeMessageID = closeLog.indexOf("CHN-1003"); - assertFalse("CHN-1003 is not found", closeMessageID == -1); - - String closeMessage = closeLog.substring(closeMessageID); - assertTrue("Unexpected close channel message :" + closeMessage, Pattern.matches(CHANNEL_CLOSE_FORCED_MESSAGE_PATTERN, closeMessage)); - - session.close(); - connection.close(); - } - private void validateChannelClose(List<String> results) - { - String open = getLogMessage(results, isBroker10() ? 1 : 0); - String close = getLogMessageFromEnd(results, 0); - - validateMessageID("CHN-1001", open); - validateMessageID("CHN-1003", close); - assertEquals("Message should be Close", "Close", getMessageString(fromMessage(close))); - assertEquals("Incorrect Channel ID closed: " + close, isBroker010()? 0 : 1, getChannelID(fromSubject(close))); - assertEquals("Channel IDs should be the same", getChannelID(fromActor(open)), getChannelID(fromSubject(close))); - assertEquals("Connection IDs should be the same", getConnectionID(fromActor(open)), getConnectionID(fromSubject(close))); - } -} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b21a8f56/systests/src/test/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java b/systests/src/test/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java deleted file mode 100644 index d38665b..0000000 --- a/systests/src/test/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java +++ /dev/null @@ -1,209 +0,0 @@ -/* -* -* 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 java.util.List; -import java.util.Map; -import java.util.TreeSet; - -import javax.jms.Connection; - -import org.apache.qpid.configuration.CommonProperties; - -public class ConnectionLoggingTest extends AbstractTestLogging -{ - private static final String CONNECTION_PREFIX = "CON-"; - - // No explicit startup configuration is required for this test - // so no setUp() method - - /** - * 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 .... - * - * 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(); - String clientid = connection.getClientID(); - - // Wait until opened - waitForMessage("CON-1001"); - - // Close the connection - connection.close(); - - // Wait to ensure that the desired message is logged - waitForMessage("CON-1002"); - - List<String> results = waitAndFindMatches("CON-1001"); - - // MESSAGE [con:1(/127.0.0.1:46927)] CON-1001 : Open : Destination : amqp(127.0.0.1:15672) : Protocol Version : 0-10 - // MESSAGE [con:1(guest@/127.0.0.1:46927/test)] CON-1001 : Open : Destination : amqp(127.0.0.1:15672) : Protocol Version : 0-10 : Client ID : clientid : Client Version : 6.0.0-SNAPSHOT : Client Product : qpid - // MESSAGE [con:1(guest@/127.0.0.1:46927/test)] CON-1002 : Close - - Map<Integer, List<String>> connectionData = splitResultsOnConnectionID(results); - - // Get the last Integer from keySet of the ConnectionData - int connectionID = new TreeSet<>(connectionData.keySet()).last(); - - //Use just the data from the last connection for the test - results = connectionData.get(connectionID); - - assertEquals("Unexpected CON-1001 messages count", 2, results.size()); - - // validate the two CON-1001 messages. - // MESSAGE [con:1(guest@/127.0.0.1:46927/test)] CON-1001 : Open : Destination : amqp(127.0.0.1:15672) : Protocol Version : 0-10 : Client ID : clientid : Client Version : 6.0.0-SNAPSHOT : Client Product : qpid - validateConnectionOpen(results, 0, - true, getBrokerProtocol().getProtocolVersion(), - true, clientid, - true, CommonProperties.getReleaseVersion(), - true, CommonProperties.getProductName()); - - // MESSAGE [con:1(/127.0.0.1:46927)] CON-1001 : Open : Destination : amqp(127.0.0.1:15672) : Protocol Version : 0-10 - validateConnectionOpen(results, 1, - true, getBrokerProtocol().getProtocolVersion(), - false, null, - false, null, - false, null); - } - - private void validateConnectionOpen(List<String> results, int positionFromEnd, - boolean protocolVersionPresent, final String protocolVersionValue, - boolean clientIdOptionPresent, String clientIdValue, - boolean clientVersionPresent, String clientVersionValue, - boolean clientProductPresent, String clientProductValue) - { - String log = getLogMessageFromEnd(results, positionFromEnd); - - validateMessageID("CON-1001", log); - - String message = fromMessage(log); - - assertTrue("Destination not present", message.contains("Destination :")); - - assertEquals("unexpected Protocol Version option state", - protocolVersionPresent, message.contains("Protocol Version :")); - if(protocolVersionPresent && protocolVersionValue != null) - { - assertTrue("Protocol Version value is not present: " + protocolVersionValue, message.contains(protocolVersionValue)); - } - - assertEquals("unexpected Client ID option state", clientIdOptionPresent, message.contains("Client ID :")); - - if(clientIdOptionPresent && clientIdValue != null) - { - assertTrue("Client ID value is not present: " + clientIdValue, message.contains(clientIdValue)); - } - - - assertEquals("unexpected Client Version option state", clientVersionPresent, message.contains( - "Client Version :")); - - if(clientVersionPresent && clientVersionValue != null && !isBroker10()) - { - assertTrue("Client version value is not present: " + clientVersionValue, message.contains( - clientVersionValue)); - } - - assertEquals("unexpected Client Product option state", clientVersionPresent, message.contains( - "Client Product :")); - - if(clientProductPresent && clientProductValue != null && !isBroker10()) - { - assertTrue("Client product value is not present: " + clientProductValue, message.contains( - clientProductValue)); - } - } - - /** - * 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); - - Connection connection = getConnection(); - - // Wait until opened - waitForMessage("CON-1001"); - - // Close the conneciton - connection.close(); - - // Wait to ensure that the desired message is logged - waitForMessage("CON-1002"); - - List<String> results = findMatches(CONNECTION_PREFIX); - - // Validation - - assertEquals("CON messages not logged:" + results.size(), 3, results.size()); - - // Validate Close message occurs - String log = getLogMessageFromEnd(results, 0); - validateMessageID("CON-1002",log); - assertTrue("Message does not end with close:" + log, log.endsWith("Close")); - - // Extract connection ID to validate there is a CON-1001 message for it - final String logSubject = fromActor(log); - int closeConnectionID = getConnectionID(logSubject); - assertTrue("Could not get the connection id from CLOSE message: " + logSubject, closeConnectionID != -1); - - //Previous log message should be the open - log = getLogMessageFromEnd(results, 1); - // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : clientid : Protocol Version : 0-9 - validateMessageID("CON-1001",log); - - // Extract connection ID to validate it matches the CON-1002 messasge - int openConnectionID = getConnectionID(fromActor(log)); - assertTrue("Could not find connection id in OPEN", openConnectionID != -1); - - // Check connection ids match - assertEquals("Connection IDs do not match", closeConnectionID, openConnectionID); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org