Author: pferraro
Date: 2009-02-03 10:48:21 -0500 (Tue, 03 Feb 2009)
New Revision: 2263
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/DeterministicLoadState.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadStateImpl.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadState.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/RequestCountLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SendTrafficLoadMetric.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ActiveSessionsLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanAttributeLoadMetricTestCase.java
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:
Extract mockable interface from DeterministicLoadState so to simplify the unit testing of
deterministic load metrics
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/DeterministicLoadState.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/DeterministicLoadState.java
(rev 0)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/DeterministicLoadState.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.load.metric;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface DeterministicLoadState
+{
+ double delta(double currentLoad);
+}
\ No newline at end of file
Deleted:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadState.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadState.java 2009-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadState.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.modcluster.load.metric.impl;
-
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Computes incremental load change per second from record of previous load.
- * @author Paul Ferraro
- */
-public class DeterministicLoadState
-{
- private final AtomicReference<Double> currentLoad = new
AtomicReference<Double>(new Double(0));
- private final AtomicLong currentTime = new AtomicLong(System.currentTimeMillis());
-
- public double delta(double currentLoad)
- {
- long currentTime = System.currentTimeMillis();
- long previousTime = this.currentTime.getAndSet(currentTime);
-
- double previousLoad = this.currentLoad.getAndSet(new
Double(currentLoad)).doubleValue();
-
- double seconds = (currentTime - previousTime) / 1000d;
-
- // Normalize by time interval (in seconds)
- return (currentLoad - previousLoad) / seconds;
- }
-}
Copied:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadStateImpl.java
(from rev 2246,
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadState.java)
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadStateImpl.java
(rev 0)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/DeterministicLoadStateImpl.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.load.metric.impl;
+
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jboss.modcluster.load.metric.DeterministicLoadState;
+
+/**
+ * Computes incremental load change per second from record of previous load.
+ * @author Paul Ferraro
+ */
+public class DeterministicLoadStateImpl implements DeterministicLoadState
+{
+ private final AtomicReference<Double> currentLoad = new
AtomicReference<Double>(new Double(0));
+ private final AtomicLong currentTime = new AtomicLong(System.currentTimeMillis());
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.metric.DeterministicLoadState#delta(double)
+ */
+ public double delta(double currentLoad)
+ {
+ long currentTime = System.currentTimeMillis();
+ long previousTime = this.currentTime.getAndSet(currentTime);
+
+ double previousLoad = this.currentLoad.getAndSet(new
Double(currentLoad)).doubleValue();
+
+ double seconds = (currentTime - previousTime) / 1000d;
+
+ // Normalize by time interval (in seconds)
+ return (currentLoad - previousLoad) / seconds;
+ }
+
+ public long getCurrentTime()
+ {
+ return this.currentTime.get();
+ }
+}
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java 2009-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -24,6 +24,7 @@
import javax.management.JMException;
import javax.management.MalformedObjectNameException;
+import org.jboss.modcluster.load.metric.DeterministicLoadState;
import org.jboss.modcluster.load.metric.LoadMetric;
/**
@@ -34,21 +35,38 @@
{
public static final String DEFAULT_ATTRIBUTE = "bytesReceived";
- private final DeterministicLoadState state = new DeterministicLoadState();
+ private final DeterministicLoadState state;
public ReceiveTrafficLoadMetric() throws MalformedObjectNameException
{
this(new RequestProcessorLoadMetricSource());
}
+ public ReceiveTrafficLoadMetric(DeterministicLoadState state) throws
MalformedObjectNameException
+ {
+ this(new RequestProcessorLoadMetricSource(), state);
+ }
+
public ReceiveTrafficLoadMetric(RequestProcessorLoadMetricSource source)
{
- super(source, DEFAULT_ATTRIBUTE);
+ this(source, DEFAULT_ATTRIBUTE);
}
+ public ReceiveTrafficLoadMetric(RequestProcessorLoadMetricSource source,
DeterministicLoadState state)
+ {
+ this(source, DEFAULT_ATTRIBUTE, state);
+ }
+
public ReceiveTrafficLoadMetric(RequestProcessorLoadMetricSource source, String
attribute)
{
+ this(source, attribute, new DeterministicLoadStateImpl());
+ }
+
+ public ReceiveTrafficLoadMetric(RequestProcessorLoadMetricSource source, String
attribute, DeterministicLoadState state)
+ {
super(source, attribute);
+
+ this.state = state;
}
/**
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/RequestCountLoadMetric.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/RequestCountLoadMetric.java 2009-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/RequestCountLoadMetric.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -24,6 +24,7 @@
import javax.management.JMException;
import javax.management.MalformedObjectNameException;
+import org.jboss.modcluster.load.metric.DeterministicLoadState;
import org.jboss.modcluster.load.metric.LoadMetric;
/**
@@ -35,21 +36,38 @@
{
public static final String DEFAULT_ATTRIBUTE = "requestCount";
- private final DeterministicLoadState state = new DeterministicLoadState();
+ private final DeterministicLoadState state;
public RequestCountLoadMetric() throws MalformedObjectNameException
{
this(new RequestProcessorLoadMetricSource());
}
+ public RequestCountLoadMetric(DeterministicLoadState state) throws
MalformedObjectNameException
+ {
+ this(new RequestProcessorLoadMetricSource(), state);
+ }
+
public RequestCountLoadMetric(RequestProcessorLoadMetricSource source)
{
- super(source, DEFAULT_ATTRIBUTE);
+ this(source, DEFAULT_ATTRIBUTE);
}
+ public RequestCountLoadMetric(RequestProcessorLoadMetricSource source,
DeterministicLoadState state)
+ {
+ this(source, DEFAULT_ATTRIBUTE, state);
+ }
+
public RequestCountLoadMetric(RequestProcessorLoadMetricSource source, String
attribute)
{
+ this(source, attribute, new DeterministicLoadStateImpl());
+ }
+
+ public RequestCountLoadMetric(RequestProcessorLoadMetricSource source, String
attribute, DeterministicLoadState state)
+ {
super(source, attribute);
+
+ this.state = state;
}
/**
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SendTrafficLoadMetric.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SendTrafficLoadMetric.java 2009-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SendTrafficLoadMetric.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -24,6 +24,7 @@
import javax.management.JMException;
import javax.management.MalformedObjectNameException;
+import org.jboss.modcluster.load.metric.DeterministicLoadState;
import org.jboss.modcluster.load.metric.LoadMetric;
/**
@@ -35,21 +36,38 @@
{
public static final String DEFAULT_ATTRIBUTE = "bytesSent";
- private final DeterministicLoadState state = new DeterministicLoadState();
+ private final DeterministicLoadState state;
public SendTrafficLoadMetric() throws MalformedObjectNameException
{
this(new RequestProcessorLoadMetricSource());
}
+ public SendTrafficLoadMetric(DeterministicLoadState state) throws
MalformedObjectNameException
+ {
+ this(new RequestProcessorLoadMetricSource(), state);
+ }
+
public SendTrafficLoadMetric(RequestProcessorLoadMetricSource source)
{
this(source, DEFAULT_ATTRIBUTE);
}
+ public SendTrafficLoadMetric(RequestProcessorLoadMetricSource source,
DeterministicLoadState state)
+ {
+ this(source, DEFAULT_ATTRIBUTE, state);
+ }
+
public SendTrafficLoadMetric(RequestProcessorLoadMetricSource source, String
attribute)
{
+ this(source, attribute, new DeterministicLoadStateImpl());
+ }
+
+ public SendTrafficLoadMetric(RequestProcessorLoadMetricSource source, String
attribute, DeterministicLoadState state)
+ {
super(source, attribute);
+
+ this.state = state;
}
/**
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ActiveSessionsLoadMetricTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ActiveSessionsLoadMetricTestCase.java 2009-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ActiveSessionsLoadMetricTestCase.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -24,6 +24,7 @@
import javax.management.MalformedObjectNameException;
import org.jboss.modcluster.load.metric.impl.ActiveSessionsLoadMetric;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
/**
* @author Paul Ferraro
@@ -31,8 +32,23 @@
*/
public class ActiveSessionsLoadMetricTestCase extends MBeanAttributeLoadMetricTestCase
{
- public ActiveSessionsLoadMetricTestCase() throws MalformedObjectNameException
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.load.metric.MBeanAttributeLoadMetricTestCase#getAttribute()
+ */
+ @Override
+ protected String getAttribute()
{
- super(new ActiveSessionsLoadMetric(), ActiveSessionsLoadMetric.DEFAULT_ATTRIBUTE);
+ return ActiveSessionsLoadMetric.DEFAULT_ATTRIBUTE;
}
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.load.metric.MBeanAttributeLoadMetricTestCase#getLoadMetric()
+ */
+ @Override
+ protected LoadMetric<MBeanQueryLoadContext> getLoadMetric() throws
MalformedObjectNameException
+ {
+ return new ActiveSessionsLoadMetric();
+ }
}
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanAttributeLoadMetricTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanAttributeLoadMetricTestCase.java 2009-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanAttributeLoadMetricTestCase.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -51,25 +51,12 @@
private String attribute;
LoadMetric<MBeanQueryLoadContext> metric;
- public MBeanAttributeLoadMetricTestCase() throws MalformedObjectNameException
- {
- this("attribute");
- }
-
- private MBeanAttributeLoadMetricTestCase(String attribute) throws
MalformedObjectNameException
- {
- this(new MBeanAttributeLoadMetric(new
MBeanQueryLoadMetricSource("domain:*"), attribute), attribute);
- }
-
- protected MBeanAttributeLoadMetricTestCase(LoadMetric<MBeanQueryLoadContext>
metric, String attribute)
- {
- this.metric = metric;
- this.attribute = attribute;
- }
-
@Before
public void prepare() throws MalformedObjectNameException
{
+ this.attribute = this.getAttribute();
+ this.metric = this.getLoadMetric();
+
ObjectName pattern = ObjectName.getInstance("domain:*");
this.name1 = ObjectName.getInstance("domain:name=test1");
this.name2 = ObjectName.getInstance("domain:name=test2");
@@ -84,6 +71,16 @@
EasyMock.reset(this.server);
}
+ protected LoadMetric<MBeanQueryLoadContext> getLoadMetric() throws
MalformedObjectNameException
+ {
+ return new MBeanAttributeLoadMetric(new
MBeanQueryLoadMetricSource("domain:*"), this.attribute);
+ }
+
+ protected String getAttribute()
+ {
+ return "attribute";
+ }
+
@Test
public void getLoad() throws Exception
{
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-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -24,6 +24,7 @@
import javax.management.MalformedObjectNameException;
import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
import org.jboss.modcluster.load.metric.impl.ReceiveTrafficLoadMetric;
import org.junit.Assert;
import org.junit.Test;
@@ -35,72 +36,42 @@
@SuppressWarnings("boxing")
public class ReceiveTrafficLoadMetricTestCase extends MBeanAttributeLoadMetricTestCase
{
- public ReceiveTrafficLoadMetricTestCase() throws MalformedObjectNameException
+ private DeterministicLoadState state =
EasyMock.createStrictMock(DeterministicLoadState.class);
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.load.metric.MBeanAttributeLoadMetricTestCase#getAttribute()
+ */
+ @Override
+ protected String getAttribute()
{
- super(new ReceiveTrafficLoadMetric(), ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE);
+ return ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE;
}
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.load.metric.MBeanAttributeLoadMetricTestCase#getLoadMetric()
+ */
+ @Override
+ protected LoadMetric<MBeanQueryLoadContext> getLoadMetric() throws
MalformedObjectNameException
+ {
+ return new ReceiveTrafficLoadMetric(this.state);
+ }
+
@Test
@Override
public void getLoad() throws Exception
{
- Thread.sleep(1);
-
- EasyMock.expect(this.server.getAttribute(this.name1,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
- EasyMock.expect(this.server.getAttribute(this.name2,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
-
- 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);
-
EasyMock.expect(this.server.getAttribute(this.name1,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(10000L);
EasyMock.expect(this.server.getAttribute(this.name2,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(20000L);
+ EasyMock.expect(this.state.delta(30)).andReturn(10d);
- EasyMock.replay(this.server);
-
- long sleep = 1000 - (System.currentTimeMillis() - start);
+ EasyMock.replay(this.server, this.state);
- if (sleep > 0)
- {
- Thread.sleep(sleep);
- }
-
- start = System.currentTimeMillis();
+ double load = this.metric.getLoad(this.context);
- load = this.metric.getLoad(this.context);
-
- EasyMock.verify(this.server);
+ EasyMock.verify(this.server, this.state);
- Assert.assertEquals(30.0, load, 2.0);
-
- EasyMock.reset(this.server);
-
- EasyMock.expect(this.server.getAttribute(this.name1,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(20000L);
- EasyMock.expect(this.server.getAttribute(this.name2,
ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(30000L);
-
- EasyMock.replay(this.server);
-
- sleep = 1000 - (System.currentTimeMillis() - start);
-
- if (sleep > 0)
- {
- Thread.sleep(sleep);
- }
-
- load = this.metric.getLoad(this.context);
-
- EasyMock.verify(this.server);
-
- Assert.assertEquals(20.0, load, 2.0);
-
- EasyMock.reset(this.server);
+ Assert.assertEquals(10, load, 0);
}
}
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-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -24,6 +24,7 @@
import javax.management.MalformedObjectNameException;
import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
import org.jboss.modcluster.load.metric.impl.RequestCountLoadMetric;
import org.junit.Assert;
import org.junit.Test;
@@ -35,71 +36,42 @@
@SuppressWarnings("boxing")
public class RequestCountLoadMetricTestCase extends MBeanAttributeLoadMetricTestCase
{
- public RequestCountLoadMetricTestCase() throws MalformedObjectNameException
+ private DeterministicLoadState state =
EasyMock.createStrictMock(DeterministicLoadState.class);
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.load.metric.MBeanAttributeLoadMetricTestCase#getAttribute()
+ */
+ @Override
+ protected String getAttribute()
{
- super(new RequestCountLoadMetric(), RequestCountLoadMetric.DEFAULT_ATTRIBUTE);
+ return RequestCountLoadMetric.DEFAULT_ATTRIBUTE;
}
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.load.metric.MBeanAttributeLoadMetricTestCase#getLoadMetric()
+ */
+ @Override
+ protected LoadMetric<MBeanQueryLoadContext> getLoadMetric() throws
MalformedObjectNameException
+ {
+ return new RequestCountLoadMetric(this.state);
+ }
+
@Test
@Override
public void getLoad() throws Exception
{
- EasyMock.expect(this.server.getAttribute(this.name1,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
- EasyMock.expect(this.server.getAttribute(this.name2,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
-
- 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);
-
EasyMock.expect(this.server.getAttribute(this.name1,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(10);
EasyMock.expect(this.server.getAttribute(this.name2,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(20);
+ EasyMock.expect(this.state.delta(30)).andReturn(10d);
- EasyMock.replay(this.server);
-
- long sleep = 1000 - (System.currentTimeMillis() - start);
+ EasyMock.replay(this.server, this.state);
- if (sleep > 0)
- {
- Thread.sleep(sleep);
- }
-
- start = System.currentTimeMillis();
+ double load = this.metric.getLoad(this.context);
- load = this.metric.getLoad(this.context);
+ EasyMock.verify(this.server, this.state);
- EasyMock.verify(this.server);
-
- Assert.assertEquals(30.0, load, 2.0);
-
- EasyMock.reset(this.server);
-
- // Test incremental load
- EasyMock.expect(this.server.getAttribute(this.name1,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(20);
- EasyMock.expect(this.server.getAttribute(this.name2,
RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(30);
-
- EasyMock.replay(this.server);
-
- sleep = 1000 - (System.currentTimeMillis() - start);
-
- if (sleep > 0)
- {
- Thread.sleep(sleep);
- }
-
- load = this.metric.getLoad(this.context);
-
- EasyMock.verify(this.server);
-
- Assert.assertEquals(20.0, load, 2.0);
-
- EasyMock.reset(this.server);
+ Assert.assertEquals(10, load, 0);
}
}
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-02-03
08:47:31 UTC (rev 2262)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java 2009-02-03
15:48:21 UTC (rev 2263)
@@ -24,6 +24,7 @@
import javax.management.MalformedObjectNameException;
import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
import org.jboss.modcluster.load.metric.impl.SendTrafficLoadMetric;
import org.junit.Assert;
import org.junit.Test;
@@ -35,70 +36,42 @@
@SuppressWarnings("boxing")
public class SendTrafficLoadMetricTestCase extends MBeanAttributeLoadMetricTestCase
{
- public SendTrafficLoadMetricTestCase() throws MalformedObjectNameException
+ private DeterministicLoadState state =
EasyMock.createStrictMock(DeterministicLoadState.class);
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.load.metric.MBeanAttributeLoadMetricTestCase#getAttribute()
+ */
+ @Override
+ protected String getAttribute()
{
- super(new SendTrafficLoadMetric(), SendTrafficLoadMetric.DEFAULT_ATTRIBUTE);
+ return SendTrafficLoadMetric.DEFAULT_ATTRIBUTE;
}
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.load.metric.MBeanAttributeLoadMetricTestCase#getLoadMetric()
+ */
+ @Override
+ protected LoadMetric<MBeanQueryLoadContext> getLoadMetric() throws
MalformedObjectNameException
+ {
+ return new SendTrafficLoadMetric(this.state);
+ }
+
@Test
@Override
public void getLoad() throws Exception
{
- EasyMock.expect(this.server.getAttribute(this.name1,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
- EasyMock.expect(this.server.getAttribute(this.name2,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
-
- 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);
-
EasyMock.expect(this.server.getAttribute(this.name1,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(10000L);
EasyMock.expect(this.server.getAttribute(this.name2,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(20000L);
+ EasyMock.expect(this.state.delta(30)).andReturn(10d);
- EasyMock.replay(this.server);
+ EasyMock.replay(this.server, this.state);
- long sleep = 1000 - (System.currentTimeMillis() - start);
+ double load = this.metric.getLoad(this.context);
- if (sleep > 0)
- {
- Thread.sleep(sleep);
- }
+ EasyMock.verify(this.server, this.state);
- start = System.currentTimeMillis();
-
- load = this.metric.getLoad(this.context);
-
- EasyMock.verify(this.server);
-
- Assert.assertEquals(30.0, load, 2.0);
-
- EasyMock.reset(this.server);
-
- EasyMock.expect(this.server.getAttribute(this.name1,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(20000L);
- EasyMock.expect(this.server.getAttribute(this.name2,
SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(30000L);
-
- EasyMock.replay(this.server);
-
- sleep = 1000 - (System.currentTimeMillis() - start);
-
- if (sleep > 0)
- {
- Thread.sleep(sleep);
- }
-
- load = this.metric.getLoad(this.context);
-
- EasyMock.verify(this.server);
-
- Assert.assertEquals(20.0, load, 2.0);
-
- EasyMock.reset(this.server);
+ Assert.assertEquals(10, load, 0);
}
}