You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gr...@apache.org on 2010/11/23 16:14:07 UTC
svn commit: r1038157 - in /qpid/branches/0.5.x-dev/qpid/java:
broker/src/main/java/org/apache/qpid/server/
broker/src/main/java/org/apache/qpid/server/stats/
broker/src/main/java/org/apache/qpid/server/virtualhost/
broker/src/test/java/org/apache/qpid/...
Author: grkvlt
Date: Tue Nov 23 15:14:07 2010
New Revision: 1038157
URL: http://svn.apache.org/viewvc?rev=1038157&view=rev
Log:
QPID-2932: Updating tests and placement of counter callback
Added:
qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter1.java
- copied, changed from r1038156, qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java
qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter2.java
- copied, changed from r1038156, qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java
Modified:
qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java
qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java
qpid/branches/0.5.x-dev/qpid/java/broker/src/test/java/org/apache/qpid/server/stats/StatisticsCounterTest.java
qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java
qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTestCase.java
Modified: qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java?rev=1038157&r1=1038156&r2=1038157&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java Tue Nov 23 15:14:07 2010
@@ -206,9 +206,6 @@ public class AMQChannel
// check and deliver if header says body length is zero
if (_currentMessage.allContentReceived())
{
- long bodySize = _currentMessage.getContentHeaderBody().bodySize;
- long timestamp = ((BasicContentHeaderProperties) _currentMessage.getContentHeaderBody().properties).getTimestamp();
- _session.registerMessageReceived(bodySize, timestamp);
try
{
_currentMessage.deliverToQueues();
@@ -223,6 +220,9 @@ public class AMQChannel
}
finally
{
+ long bodySize = _currentMessage.getContentHeaderBody().bodySize;
+ long timestamp = ((BasicContentHeaderProperties) _currentMessage.getContentHeaderBody().properties).getTimestamp();
+ _session.registerMessageReceived(bodySize, timestamp);
// callback to allow the context to do any post message processing
// primary use is to allow message return processing in the non-tx case
_txnContext.messageProcessed(_session);
Modified: qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java?rev=1038157&r1=1038156&r2=1038157&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java Tue Nov 23 15:14:07 2010
@@ -82,7 +82,7 @@ public class StatisticsCounter
{
return;
}
-
+
long thisSample = (timestamp / _period);
synchronized (this)
{
Copied: qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter1.java (from r1038156, qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java)
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter1.java?p2=qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter1.java&p1=qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java&r1=1038156&r2=1038157&rev=1038157&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter1.java Tue Nov 23 15:14:07 2010
@@ -28,9 +28,9 @@ import org.slf4j.LoggerFactory;
* This class collects statistics and counts the total, rate per second and
* peak rate per second values for the events that are registered with it.
*/
-public class StatisticsCounter
+public class StatisticsCounter1
{
- private static final Logger _log = LoggerFactory.getLogger(StatisticsCounter.class);
+ private static final Logger _log = LoggerFactory.getLogger(StatisticsCounter1.class);
public static final long DEFAULT_SAMPLE_PERIOD = Long.getLong("qpid.statistics.samplePeriod", 2000L); // 2s
public static final boolean DISABLE_STATISTICS = Boolean.getBoolean("qpid.statistics.disable");
@@ -38,28 +38,28 @@ public class StatisticsCounter
private static final String COUNTER = "counter";
private static final AtomicLong _counterIds = new AtomicLong(0L);
- private long _peak = 0L;
- private long _total = 0L;
- private long _temp = 0L;
- private long _last = 0L;
- private long _rate = 0L;
+ private final AtomicLong _peak = new AtomicLong(0L);
+ private final AtomicLong _total = new AtomicLong(0L);
+ private final AtomicLong _temp = new AtomicLong(0L);
+ private final AtomicLong _last = new AtomicLong(0L);
+ private final AtomicLong _rate = new AtomicLong(0L);
private long _start;
private final long _period;
private final String _name;
- public StatisticsCounter()
+ public StatisticsCounter1()
{
this(COUNTER);
}
- public StatisticsCounter(String name)
+ public StatisticsCounter1(String name)
{
this(name, DEFAULT_SAMPLE_PERIOD);
}
- public StatisticsCounter(String name, long period)
+ public StatisticsCounter1(String name, long period)
{
_period = period;
_name = name + "-" + + _counterIds.incrementAndGet();
@@ -82,24 +82,25 @@ public class StatisticsCounter
{
return;
}
-
+
long thisSample = (timestamp / _period);
- synchronized (this)
+ long lastSample;
+ while (thisSample > (lastSample = _last.get()))
{
- if (thisSample > _last)
+ if (_last.compareAndSet(lastSample, thisSample))
{
- _last = thisSample;
- _rate = _temp;
- _temp = 0L;
- if (_rate > _peak)
+ long current = _temp.getAndSet(0L);
+ _rate.set(current);
+ long peak;
+ while (current > (peak = _peak.get()))
{
- _peak = _rate;
+ _peak.compareAndSet(peak, current);
}
}
-
- _total += value;
- _temp += value;
}
+
+ _total.addAndGet(value);
+ _temp.addAndGet(value);
}
/**
@@ -116,28 +117,28 @@ public class StatisticsCounter
*/
public void reset()
{
- _peak = 0L;
- _rate = 0L;
- _total = 0L;
+ _peak.set(0L);
+ _rate.set(0L);
+ _total.set(0L);
_start = System.currentTimeMillis();
- _last = _start / _period;
+ _last.set(_start / _period);
}
public double getPeak()
{
update();
- return (double) _peak / ((double) _period / 1000.0d);
+ return (double) _peak.get() / ((double) _period / 1000.0d);
}
public double getRate()
{
update();
- return (double) _rate / ((double) _period / 1000.0d);
+ return (double) _rate.get() / ((double) _period / 1000.0d);
}
public long getTotal()
{
- return _total;
+ return _total.get();
}
public long getStart()
Copied: qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter2.java (from r1038156, qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java)
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter2.java?p2=qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter2.java&p1=qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java&r1=1038156&r2=1038157&rev=1038157&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter2.java Tue Nov 23 15:14:07 2010
@@ -28,9 +28,9 @@ import org.slf4j.LoggerFactory;
* This class collects statistics and counts the total, rate per second and
* peak rate per second values for the events that are registered with it.
*/
-public class StatisticsCounter
+public class StatisticsCounter2
{
- private static final Logger _log = LoggerFactory.getLogger(StatisticsCounter.class);
+ private static final Logger _log = LoggerFactory.getLogger(StatisticsCounter2.class);
public static final long DEFAULT_SAMPLE_PERIOD = Long.getLong("qpid.statistics.samplePeriod", 2000L); // 2s
public static final boolean DISABLE_STATISTICS = Boolean.getBoolean("qpid.statistics.disable");
@@ -49,17 +49,17 @@ public class StatisticsCounter
private final long _period;
private final String _name;
- public StatisticsCounter()
+ public StatisticsCounter2()
{
this(COUNTER);
}
- public StatisticsCounter(String name)
+ public StatisticsCounter2(String name)
{
this(name, DEFAULT_SAMPLE_PERIOD);
}
- public StatisticsCounter(String name, long period)
+ public StatisticsCounter2(String name, long period)
{
_period = period;
_name = name + "-" + + _counterIds.incrementAndGet();
Modified: qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java?rev=1038157&r1=1038156&r2=1038157&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java Tue Nov 23 15:14:07 2010
@@ -38,7 +38,6 @@ import org.apache.qpid.server.AMQBrokerM
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.configuration.ExchangeConfiguration;
import org.apache.qpid.server.configuration.QueueConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.connection.ConnectionRegistry;
import org.apache.qpid.server.connection.IConnectionRegistry;
@@ -49,7 +48,6 @@ import org.apache.qpid.server.exchange.E
import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.logging.actors.AbstractActor;
import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.messages.ConnectionMessages;
import org.apache.qpid.server.logging.messages.VirtualHostMessages;
import org.apache.qpid.server.management.AMQManagedObject;
import org.apache.qpid.server.management.ManagedObject;
@@ -61,7 +59,6 @@ import org.apache.qpid.server.queue.Defa
import org.apache.qpid.server.queue.MessageMetaData;
import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.access.ACLManager;
import org.apache.qpid.server.security.access.Accessable;
import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
Modified: qpid/branches/0.5.x-dev/qpid/java/broker/src/test/java/org/apache/qpid/server/stats/StatisticsCounterTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/broker/src/test/java/org/apache/qpid/server/stats/StatisticsCounterTest.java?rev=1038157&r1=1038156&r2=1038157&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/broker/src/test/java/org/apache/qpid/server/stats/StatisticsCounterTest.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/broker/src/test/java/org/apache/qpid/server/stats/StatisticsCounterTest.java Tue Nov 23 15:14:07 2010
@@ -76,22 +76,25 @@ public class StatisticsCounterTest exten
/**
* Test that the peak rate is reported correctly.
*/
- public void testPeak()
+ public void testPeak() throws Exception
{
StatisticsCounter counter = new StatisticsCounter("test", 1000L);
long start = counter.getStart();
assertEquals(0.0, counter.getPeak());
counter.registerEvent(1000, start + 500);
+ Thread.sleep(1250);
assertEquals(1000.0, counter.getPeak());
counter.registerEvent(2000, start + 1500);
+ Thread.sleep(1000);
assertEquals(2000.0, counter.getPeak());
counter.registerEvent(1000, start + 2500);
+ Thread.sleep(1000);
assertEquals(2000.0, counter.getPeak());
}
/**
- * Test that peak rate is reported correctly even when messages are
- * delivered out-of-order.
+ * Test that peak rate is reported correctly for out-of-order messages,
+ * and the total is also unaffected.
*/
public void testPeakOutOfOrder() throws Exception
{
@@ -99,18 +102,22 @@ public class StatisticsCounterTest exten
long start = counter.getStart();
assertEquals(0.0, counter.getPeak());
counter.registerEvent(1000, start + 2500);
- assertEquals(1000.0, counter.getPeak());
+ Thread.sleep(1250);
+ assertEquals(0.0, counter.getPeak());
counter.registerEvent(2000, start + 1500);
- assertEquals(3000.0, counter.getPeak());
+ Thread.sleep(1000);
+ assertEquals(0.0, counter.getPeak());
counter.registerEvent(1000, start + 500);
+ Thread.sleep(1500);
assertEquals(4000.0, counter.getPeak());
Thread.sleep(2000);
assertEquals(4000.0, counter.getPeak());
counter.registerEvent(1000, start + 500);
- assertEquals(5000.0, counter.getPeak());
+ assertEquals(4000.0, counter.getPeak());
Thread.sleep(2000);
counter.registerEvent(1000);
- assertEquals(5000.0, counter.getPeak());
+ assertEquals(4000.0, counter.getPeak());
+ assertEquals(6000, counter.getTotal());
}
/**
@@ -122,12 +129,13 @@ public class StatisticsCounterTest exten
assertEquals(0.0, counter.getRate());
Thread.sleep(100);
counter.registerEvent(1000);
+ Thread.sleep(1250);
assertEquals(1000.0, counter.getRate());
- Thread.sleep(1000);
counter.registerEvent(2000);
- assertEquals(2000.0, counter.getRate());
Thread.sleep(1000);
+ assertEquals(2000.0, counter.getRate());
counter.registerEvent(1000);
+ Thread.sleep(1000);
assertEquals(1000.0, counter.getRate());
Thread.sleep(1000);
assertEquals(0.0, counter.getRate());
Modified: qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java?rev=1038157&r1=1038156&r2=1038157&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java Tue Nov 23 15:14:07 2010
@@ -154,22 +154,23 @@ public class MessageStatisticsTest exten
*/
public void testMessagePeakRates() throws Exception
{
- sendUsing(_test, 1, 10000);
+ sendUsing(_test, 2, 10);
+ Thread.sleep(10 * 1000);
+ sendUsing(_dev, 4, 10);
Thread.sleep(10 * 1000);
- sendUsing(_dev, 10, 10);
ManagedBroker test = _jmxUtils.getManagedBroker("test");
ManagedBroker dev = _jmxUtils.getManagedBroker("development");
assertApprox("Incorrect test vhost peak messages", 0.2d, 1.0d, test.getPeakMessageReceiptRate());
- assertApprox("Incorrect test vhost peak data", 0.2d, 10000.0d, test.getPeakDataReceiptRate());
- assertApprox("Incorrect dev vhost peak messages", 0.2d, 10.0d, dev.getPeakMessageReceiptRate());
- assertApprox("Incorrect dev vhost peak data", 0.2d, 100.0d, dev.getPeakDataReceiptRate());
+ assertApprox("Incorrect test vhost peak data", 0.2d, 10.0d, test.getPeakDataReceiptRate());
+ assertApprox("Incorrect dev vhost peak messages", 0.2d, 2.0d, dev.getPeakMessageReceiptRate());
+ assertApprox("Incorrect dev vhost peak data", 0.2d, 20.0d, dev.getPeakDataReceiptRate());
if (!_broker.equals(VM))
{
- assertApprox("Incorrect server peak messages", 0.2d, 10.0d, _jmxUtils.getServerInformation().getPeakMessageReceiptRate());
- assertApprox("Incorrect server peak data", 0.2d, 10000.0d, _jmxUtils.getServerInformation().getPeakDataReceiptRate());
+ assertApprox("Incorrect server peak messages", 0.2d, 2.0d, _jmxUtils.getServerInformation().getPeakMessageReceiptRate());
+ assertApprox("Incorrect server peak data", 0.2d, 20.0d, _jmxUtils.getServerInformation().getPeakDataReceiptRate());
}
}
Modified: qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTestCase.java
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTestCase.java?rev=1038157&r1=1038156&r2=1038157&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTestCase.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTestCase.java Tue Nov 23 15:14:07 2010
@@ -105,7 +105,7 @@ public abstract class MessageStatisticsT
{
double min = expected * (1.0d - error);
double max = expected * (1.0d + error);
- String assertion = String.format("%s: expected %f +/- %d, actual %f",
+ String assertion = String.format("%s: expected %f +/- %d%%, actual %f",
message, expected, (int) (error * 100.0d), actual);
assertTrue(assertion, actual > min && actual < max);
}
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org