diff options
author | Aidan Skinner <aidan@apache.org> | 2009-04-28 14:04:36 +0000 |
---|---|---|
committer | Aidan Skinner <aidan@apache.org> | 2009-04-28 14:04:36 +0000 |
commit | 979e96cb1df81a1a01204521dbfd6e19fdbcaf7b (patch) | |
tree | 8b087f3945bc113a909120eb69ff5c3a67f50e36 | |
parent | da80c673e9f5d0b05118f4f0b8698402fd2c6dd2 (diff) | |
download | qpid-python-979e96cb1df81a1a01204521dbfd6e19fdbcaf7b.tar.gz |
QPID-1730: add AlertingTest, although not to 010
java.testprofile: Make sure that the broker can always find the log configuration file even if we've used a different directory for the config file
QpidTestCase: expose the file that the output is being written to as a protected variable.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@769406 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | java/010ExcludeList | 3 | ||||
-rw-r--r-- | java/java.testprofile | 2 | ||||
-rw-r--r-- | java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java | 159 | ||||
-rw-r--r-- | java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java | 5 |
4 files changed, 167 insertions, 2 deletions
diff --git a/java/010ExcludeList b/java/010ExcludeList index 0b1993e71a..ef6140704b 100644 --- a/java/010ExcludeList +++ b/java/010ExcludeList @@ -73,3 +73,6 @@ org.apache.qpid.server.persistent.NoLocalAfterRecoveryTest#* // QPID-1823: this takes ages to run org.apache.qpid.client.SessionCreateTest#* +// QPID-1730: the C++ server has a totally different logging mechanism. We should split this file differently +org.apache.qpid.server.AlertingTest#* + diff --git a/java/java.testprofile b/java/java.testprofile index 4567db5f28..9581064ae3 100644 --- a/java/java.testprofile +++ b/java/java.testprofile @@ -1,5 +1,5 @@ broker.language=java -broker=${project.root}/build/bin/qpid-server -p @PORT -m @MPORT -c @CONFIG_FILE +broker=${project.root}/build/bin/qpid-server -p @PORT -m @MPORT -c @CONFIG_FILE -l ${project.root}/log4j-test.xml broker.clean=${project.root}/clean-dir ${build.data} broker.ready=Qpid Broker Ready diff --git a/java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java b/java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java new file mode 100644 index 0000000000..3befc8d327 --- /dev/null +++ b/java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java @@ -0,0 +1,159 @@ +/* +* +* 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 java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; + +import javax.jms.Connection; +import javax.jms.MessageConsumer; +import javax.jms.Queue; +import javax.jms.Session; + +import org.apache.commons.configuration.XMLConfiguration; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.apache.qpid.server.store.DerbyMessageStore; +import org.apache.qpid.test.utils.QpidTestCase; + +public class AlertingTest extends QpidTestCase +{ + private String VIRTUALHOST = "test"; + private Session _session; + private Connection _connection; + private Queue _destination; + private MessageConsumer _consumer; // Never read, but does need to be here to create the destination. + private File _logfile; + private XMLConfiguration _configuration; + + public void setUp() throws Exception + { + // First we munge the config file and, if we're in a VM, set up an additional logfile + + _configuration = new XMLConfiguration(_configFile); + _configuration.setProperty("management.enabled", "false"); + Class storeClass = DerbyMessageStore.class; + try { + Class bdb = Class.forName("org.apache.qpid.store.berkleydb.BDBMessageStore"); + } + catch (ClassNotFoundException e) + { + // No BDB store, we'll use Derby instead. + } + + _configuration.setProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".store.class", storeClass.getName()); + _configuration.setProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", 2); + + File tmpFile = File.createTempFile("configFile", "test"); + tmpFile.deleteOnExit(); + _configuration.save(tmpFile); + _configFile = tmpFile; + + if (_outputFile != null) + { + _logfile = _outputFile; + } + else + { + // This is mostly for running the test outside of the ant setup + _logfile = File.createTempFile("logFile", "test"); + FileAppender appender = new FileAppender(new SimpleLayout(), _logfile.getAbsolutePath()); + appender.setFile(_logfile.getAbsolutePath()); + appender.setImmediateFlush(true); + Logger.getRootLogger().addAppender(appender); + _logfile.deleteOnExit(); + } + + // Then we do the normal setup stuff like starting the broker, getting a connection etc. + + super.setUp(); + + _connection = getConnection(); + _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + _destination = _session.createQueue("testQueue"); + + // Consumer is only used to actually create the destination + _consumer = _session.createConsumer(_destination); + } + + private boolean wasAlertFired() throws Exception + { + // Loop throught alerts until we're done or 5 seconds have passed, + // just in case the logfile takes a while to flush. + BufferedReader reader = new BufferedReader(new FileReader(_logfile)); + boolean found = false; + int lineCount = 0; + long endtime = System.currentTimeMillis()+5000; + while (!found && System.currentTimeMillis() < endtime) + { + while (reader.ready()) + { + String line = reader.readLine(); + lineCount++; + if (line.contains("MESSAGE_COUNT_ALERT")) + { + found = true; + } + } + } + return found; + } + + public void testAlertingReallyWorks() throws Exception + { + // Send 5 messages, make sure that the alert was fired properly. + sendMessage(_session, _destination, 4); + boolean found = wasAlertFired(); + assertTrue("no alert generated in "+_logfile.getAbsolutePath(), found); + } + + public void testAlertingReallyWorksWithRestart() throws Exception + { + sendMessage(_session, _destination, 4); + stopBroker(); + (new FileOutputStream(_logfile)).getChannel().truncate(0); + startBroker(); + boolean found = wasAlertFired(); + assertTrue("no alert generated in "+_logfile.getAbsolutePath(), found); + } + + public void testAlertingReallyWorksWithChanges() throws Exception + { + // send some messages and nuke the logs + sendMessage(_session, _destination, 2); + stopBroker(); + (new FileOutputStream(_logfile)).getChannel().truncate(0); + + // Change max message count to 5, start broker and make sure that that's triggered at the right time + _configuration.setProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", 5); + startBroker(); + _connection = getConnection(); + _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Trigger the new value + sendMessage(_session, _destination, 3); + boolean found = wasAlertFired(); + assertTrue("no alert generated in "+_logfile.getAbsolutePath(), found); + } +} diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java index fef3f547d3..bd481df8a0 100644 --- a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -157,6 +157,8 @@ public class QpidTestCase extends TestCase private String _brokerVersion = System.getProperty(BROKER_VERSION, VERSION_08); private String _output = System.getProperty(TEST_OUTPUT); + protected File _outputFile; + private Map<Integer,Process> _brokers = new HashMap<Integer,Process>(); private InitialContext _initialContext; @@ -189,7 +191,8 @@ public class QpidTestCase extends TestCase boolean redirected = _output != null && _output.length() > 0; if (redirected) { - out = new PrintStream(String.format("%s/TEST-%s.out", _output, qname)); + _outputFile = new File (String.format("%s/TEST-%s.out", _output, qname)); + out = new PrintStream(_outputFile); err = new PrintStream(String.format("%s/TEST-%s.err", _output, qname)); System.setOut(out); System.setErr(err); |