Author: pferraro
Date: 2009-01-28 09:31:16 -0500 (Wed, 28 Jan 2009)
New Revision: 2237
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java
Log:
Improve reliability of test via more precise sleeping.
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java 2009-01-28
14:25:11 UTC (rev 2236)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java 2009-01-28
14:31:16 UTC (rev 2237)
@@ -49,18 +49,30 @@
EasyMock.replay(this.server);
+ long start = System.currentTimeMillis();
+
double load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
+
+ Assert.assertEquals(0, load, 0);
+
EasyMock.reset(this.server);
- Thread.sleep(500);
-
EasyMock.expect(this.server.getAttribute(this.name1,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1000L);
EasyMock.expect(this.server.getAttribute(this.name2,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2000L);
EasyMock.replay(this.server);
+
+ long sleep = 500 - (System.currentTimeMillis() - start);
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
+ start = System.currentTimeMillis();
+
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
@@ -69,13 +81,18 @@
EasyMock.reset(this.server);
- Thread.sleep(500);
-
EasyMock.expect(this.server.getAttribute(this.name1,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2000L);
EasyMock.expect(this.server.getAttribute(this.name2,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3000L);
EasyMock.replay(this.server);
+ sleep = 500 - (System.currentTimeMillis() - start);
+
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java 2009-01-28
14:25:11 UTC (rev 2236)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java 2009-01-28
14:31:16 UTC (rev 2237)
@@ -58,6 +58,11 @@
Assert.assertEquals(0, load, 0);
EasyMock.reset(this.server);
+
+ EasyMock.expect(this.server.getAttribute(this.name1,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1);
+ EasyMock.expect(this.server.getAttribute(this.name2,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
+
+ EasyMock.replay(this.server);
long sleep = 500 - (System.currentTimeMillis() - start);
@@ -65,11 +70,6 @@
{
Thread.sleep(sleep);
}
-
- EasyMock.expect(this.server.getAttribute(this.name1,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1);
- EasyMock.expect(this.server.getAttribute(this.name2,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
-
- EasyMock.replay(this.server);
start = System.currentTimeMillis();
@@ -81,6 +81,12 @@
EasyMock.reset(this.server);
+ // Test incremental load
+ EasyMock.expect(this.server.getAttribute(this.name1,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
+ EasyMock.expect(this.server.getAttribute(this.name2,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3);
+
+ EasyMock.replay(this.server);
+
sleep = 500 - (System.currentTimeMillis() - start);
if (sleep > 0)
@@ -88,12 +94,6 @@
Thread.sleep(sleep);
}
- // Test incremental load
- EasyMock.expect(this.server.getAttribute(this.name1,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
- EasyMock.expect(this.server.getAttribute(this.name2,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3);
-
- EasyMock.replay(this.server);
-
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java 2009-01-28
14:25:11 UTC (rev 2236)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java 2009-01-28
14:31:16 UTC (rev 2237)
@@ -49,18 +49,30 @@
EasyMock.replay(this.server);
+ long start = System.currentTimeMillis();
+
double load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
+
+ Assert.assertEquals(0, load, 0);
+
EasyMock.reset(this.server);
- Thread.sleep(500);
-
EasyMock.expect(this.server.getAttribute(this.name1,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1000L);
EasyMock.expect(this.server.getAttribute(this.name2,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2000L);
EasyMock.replay(this.server);
+ long sleep = 500 - (System.currentTimeMillis() - start);
+
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
+ start = System.currentTimeMillis();
+
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
@@ -69,13 +81,18 @@
EasyMock.reset(this.server);
- Thread.sleep(500);
-
EasyMock.expect(this.server.getAttribute(this.name1,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2000L);
EasyMock.expect(this.server.getAttribute(this.name2,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3000L);
EasyMock.replay(this.server);
+ sleep = 500 - (System.currentTimeMillis() - start);
+
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
Show replies by date