You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2013/01/29 14:08:48 UTC

svn commit: r1439880 - in /qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid: server/stats/StatisticsReportingTest.java util/LogMonitor.java

Author: orudyy
Date: Tue Jan 29 13:08:48 2013
New Revision: 1439880

URL: http://svn.apache.org/viewvc?rev=1439880&view=rev
Log:
QPID-4390: Fix StatisticsReportingTest

Modified:
    qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java
    qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java

Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java?rev=1439880&r1=1439879&r2=1439880&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java Tue Jan 29 13:08:48 2013
@@ -33,6 +33,7 @@ import org.apache.qpid.test.utils.TestBr
 import org.apache.qpid.util.LogMonitor;
 
 import java.util.List;
+import java.util.Map;
 
 import javax.jms.Connection;
 import javax.jms.Destination;
@@ -50,6 +51,7 @@ public class StatisticsReportingTest ext
     private static final String VHOST_NAME1 = "vhost1";
     private static final String VHOST_NAME2 = "vhost2";
     private static final String VHOST_NAME3 = "vhost3";
+    private static long STATISTICS_REPORTING_PERIOD_IN_SECONDS = 10l;
 
     protected LogMonitor _monitor;
     protected static final String USER = "admin";
@@ -58,6 +60,7 @@ public class StatisticsReportingTest ext
     protected String _queueName = "statistics";
     protected Destination _queue;
     protected String _brokerUrl;
+    private long _startTestTime;
 
     @Override
     public void setUp() throws Exception
@@ -70,10 +73,11 @@ public class StatisticsReportingTest ext
         {
             TestBrokerConfiguration config = getBrokerConfiguration();
             config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST);
-            config.setBrokerAttribute(Broker.STATISTICS_REPORTING_PERIOD, 10);
+            config.setBrokerAttribute(Broker.STATISTICS_REPORTING_PERIOD, STATISTICS_REPORTING_PERIOD_IN_SECONDS);
         }
 
         _monitor = new LogMonitor(_outputFile);
+        _startTestTime = System.currentTimeMillis();
 
         super.setUp();
 
@@ -106,17 +110,26 @@ public class StatisticsReportingTest ext
         sendUsing(_conToVhost2, 20, 100);
         sendUsing(_conToVhost3, 15, 100);
 
-        Thread.sleep(10 * 1000); // 15s
+        Thread.sleep(STATISTICS_REPORTING_PERIOD_IN_SECONDS * 1000);
 
-        List<String> brokerStatsData = _monitor.findMatches("BRK-1008");
-        List<String> brokerStatsMessages = _monitor.findMatches("BRK-1009");
-        List<String> vhostStatsData = _monitor.findMatches("VHT-1003");
-        List<String> vhostStatsMessages = _monitor.findMatches("VHT-1004");
+        Map<String, List<String>> brokerStatsData = _monitor.findMatches("BRK-1008", "BRK-1009", "VHT-1003", "VHT-1004");
+        long endTestTime = System.currentTimeMillis();
+
+        int maxNumberOfReports = (int)((endTestTime - _startTestTime)/STATISTICS_REPORTING_PERIOD_IN_SECONDS);
 
-        assertEquals("Incorrect number of broker data stats log messages", 2, brokerStatsData.size());
-        assertEquals("Incorrect number of broker message stats log messages", 2, brokerStatsMessages.size());
-        assertEquals("Incorrect number of virtualhost data stats log messages", 6, vhostStatsData.size());
-        assertEquals("Incorrect number of virtualhost message stats log messages", 6, vhostStatsMessages.size());
+        int brk1008LinesNumber = brokerStatsData.get("BRK-1008").size();
+        int brk1009LinesNumber = brokerStatsData.get("BRK-1009").size();
+        int vht1003LinesNumber = brokerStatsData.get("VHT-1003").size();
+        int vht1004LinesNumber = brokerStatsData.get("VHT-1004").size();
+
+        assertTrue("Incorrect number of broker data stats log messages:" + brk1008LinesNumber, 2 <= brk1008LinesNumber
+                && brk1008LinesNumber <= maxNumberOfReports * 2);
+        assertTrue("Incorrect number of broker message stats log messages:" + brk1009LinesNumber, 2 <= brk1009LinesNumber
+                && brk1009LinesNumber <= maxNumberOfReports * 2);
+        assertTrue("Incorrect number of virtualhost data stats log messages:" + vht1003LinesNumber, 6 <= vht1003LinesNumber
+                && vht1003LinesNumber <= maxNumberOfReports * 6);
+        assertTrue("Incorrect number of virtualhost message stats log messages: " + vht1004LinesNumber, 6 <= vht1004LinesNumber
+                && vht1004LinesNumber <= maxNumberOfReports * 6);
     }
 
     /**
@@ -143,7 +156,7 @@ public class StatisticsReportingTest ext
 
     private void sendUsing(Connection con, int number, int size) throws Exception
     {
-        Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Session session = con.createSession(true, Session.SESSION_TRANSACTED);
         createQueue(session);
         MessageProducer producer = session.createProducer(_queue);
         String content = new String(new byte[size]);
@@ -152,6 +165,8 @@ public class StatisticsReportingTest ext
         {
             producer.send(msg);
         }
+        session.commit();
+        session.close();
     }
 
     private void createQueue(Session session) throws AMQException, JMSException

Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java?rev=1439880&r1=1439879&r2=1439880&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java Tue Jan 29 13:08:48 2013
@@ -30,8 +30,10 @@ import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.LineNumberReader;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Utility to simplify the monitoring of Log4j file output
@@ -160,6 +162,39 @@ public class LogMonitor
         return results;
     }
 
+    public Map<String, List<String>> findMatches(String... pattern) throws IOException
+    {
+
+        Map<String, List<String>> results= new HashMap<String, List<String>>();
+        for (String p : pattern)
+        {
+            results.put(p, new LinkedList<String>());
+        }
+        LineNumberReader reader = new LineNumberReader(new FileReader(_logfile));
+        try
+        {
+            while (reader.ready())
+            {
+                String line = reader.readLine();
+                if (reader.getLineNumber()  > _linesToSkip)
+                {
+                    for (String p : pattern)
+                    {
+                        if (line.contains(p))
+                        {
+                            results.get(p).add(line);
+                        }
+                    }
+                }
+            }
+        }
+        finally
+        {
+            reader.close();
+        }
+
+        return results;
+    }
     /**
      * Checks the log file for a given message to appear.  If the caller
      * has previously called {@link #markDiscardPoint()}, lines up until the discard



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org