Author: aidan
Date: Tue Apr 28 14:04:36 2009
New Revision: 769406

URL: http://svn.apache.org/viewvc?rev=769406&view=rev
Log:
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.

Added:
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java
Modified:
    qpid/trunk/qpid/java/010ExcludeList
    qpid/trunk/qpid/java/java.testprofile
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java

Modified: qpid/trunk/qpid/java/010ExcludeList
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/010ExcludeList?rev=769406&r1=769405&r2=769406&view=diff
==============================================================================
--- qpid/trunk/qpid/java/010ExcludeList (original)
+++ qpid/trunk/qpid/java/010ExcludeList Tue Apr 28 14:04:36 2009
@@ -73,3 +73,6 @@
 // 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#*
+

Modified: qpid/trunk/qpid/java/java.testprofile
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/java.testprofile?rev=769406&r1=769405&r2=769406&view=diff
==============================================================================
--- qpid/trunk/qpid/java/java.testprofile (original)
+++ qpid/trunk/qpid/java/java.testprofile Tue Apr 28 14:04:36 2009
@@ -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
 

Added: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java?rev=769406&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java
 (added)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/AlertingTest.java
 Tue Apr 28 14:04:36 2009
@@ -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);
+    }
+}

Modified: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java?rev=769406&r1=769405&r2=769406&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
 (original)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
 Tue Apr 28 14:04:36 2009
@@ -157,6 +157,8 @@
     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 @@
         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);



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscr...@qpid.apache.org

Reply via email to