JBoss Native SVN: r1974 - in trunk/mod_cluster/src: main/java/org/jboss/modcluster/ha and 5 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 22:15:23 -0400 (Tue, 21 Oct 2008)
New Revision: 1974
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/ResetRequestSourceRpcHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java
Log:
ResetRequestSource now sends requests based on diff from parsed INFO-RSP.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -23,6 +23,7 @@
package org.jboss.modcluster;
import java.util.List;
+import java.util.Map;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@@ -92,9 +93,9 @@
/**
* Reset configuration for a particular proxy following an error.
*/
- public List<MCMPRequest> getResetRequests()
+ public List<MCMPRequest> getResetRequests(Map<String, Map<String, Status>> response)
{
- return MCMPUtils.getResetRequests(ServerFactory.getServer(), this, this);
+ return MCMPUtils.getResetRequests(response, ServerFactory.getServer(), this, this);
}
//----------------------------------------------------------------- Public
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -25,6 +25,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -73,6 +74,7 @@
import org.jboss.modcluster.mcmp.MCMPServer;
import org.jboss.modcluster.mcmp.MCMPServerState;
import org.jboss.modcluster.mcmp.MCMPUtils;
+import org.jboss.modcluster.mcmp.ResetRequestSource.Status;
import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
/**
@@ -521,7 +523,8 @@
boolean needReset = this.coord.clusteredHandler.getNeedsResetTransmission();
- List<MCMPRequest> resetRequests = needReset ? this.coord.resetRequestSource.getLocalResetRequests() : null;
+ Map<String, Map<String, Status>> map = Collections.emptyMap();
+ List<MCMPRequest> resetRequests = needReset ? this.coord.resetRequestSource.getLocalResetRequests(map) : null;
ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
List<MCMPServerDiscoveryEvent> events = this.coord.clusteredHandler.getPendingDiscoveryEvents();
@@ -659,10 +662,10 @@
/**
* @see org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler#getResetRequests()
*/
- public GroupRpcResponse getResetRequests()
+ public GroupRpcResponse getResetRequests(Map<String, Map<String, Status>> response)
{
ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
- List<MCMPRequest> requests = this.coord.resetRequestSource.getLocalResetRequests();
+ List<MCMPRequest> requests = this.coord.resetRequestSource.getLocalResetRequests(response);
return new ResetRequestGroupRpcResponse(node, requests);
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -1,6 +1,7 @@
package org.jboss.modcluster;
import java.io.IOException;
+import java.lang.reflect.Method;
import java.net.InetAddress;
import org.apache.catalina.Context;
@@ -19,30 +20,24 @@
private static final StringManager sm = StringManager.getManager(Constants.Package);
- public enum TCtype {
- JBOSSWEB, TC6, UNKNOWN
+ private enum ServerType
+ {
+ JBOSSWEB, TC6
}
- // public final static TCtype tctype = TCtype.UNKNOWN;
- public static TCtype tctype = TCtype.UNKNOWN;
-
- static
+
+ private static final ServerType serverType = getServerType();
+
+ private static ServerType getServerType()
{
-
- if (tctype == tctype.UNKNOWN) {
- try {
- Class t = Class.forName("org.apache.catalina.Context");
- java.lang.reflect.Method m = t.getMethod("isStarted", (Class [])null);
- if (m != null) {
- tctype = tctype.JBOSSWEB;
- } else {
- tctype = tctype.TC6;
- }
- } catch (NoSuchMethodException ex) {
- tctype = tctype.TC6;
- } catch (ClassNotFoundException ex) {
- tctype = tctype.TC6;
+ for (Method method: Context.class.getMethods())
+ {
+ if (method.getName().equals("isStarted") && (method.getParameterTypes().length == 0))
+ {
+ return ServerType.JBOSSWEB;
}
- }
+ }
+
+ return ServerType.TC6;
}
/**
@@ -136,10 +131,7 @@
*/
public static boolean isContextStarted(Context context)
{
- boolean ret = true;
- if (tctype == tctype.JBOSSWEB)
- ret = context.isStarted();
- return ret;
+ return (serverType == ServerType.TC6) ? true : context.isStarted();
}
/**
@@ -148,12 +140,14 @@
*/
public static boolean isJBossWEB()
{
- if (tctype == tctype.JBOSSWEB)
- return true;
- else
- return false;
+ return (serverType == ServerType.JBOSSWEB);
}
-
+/*
+ public static MCMPURLEncoder createMCMPURLEncoder()
+ {
+ return (serverType == ServerType.JBOSSWEB) ? new MCMPJBURLEncoder() : new MCMPTCURLEncoder();
+ }
+*/
public static void establishJvmRouteAndConnectorAddress(Engine engine, MCMPHandler mcmpHandler) throws IOException
{
Connector connector = findProxyConnector(engine.getService().findConnectors());
@@ -187,7 +181,7 @@
* @return a RuntimeException based on t
* @throws Error if t is an Error
*/
- public static RuntimeException convertToUnchecked(Throwable t) throws Error
+ public static RuntimeException convertToUnchecked(Throwable t)
{
if (t instanceof Error)
{
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -22,6 +22,7 @@
package org.jboss.modcluster.ha;
import java.util.List;
+import java.util.Map;
import org.apache.catalina.Server;
import org.jboss.modcluster.mcmp.MCMPRequest;
@@ -33,7 +34,7 @@
*/
public interface HASingletonAwareResetRequestSource extends ResetRequestSource
{
- List<MCMPRequest> getLocalResetRequests();
+ List<MCMPRequest> getLocalResetRequests(Map<String, Map<String, Status>> response);
void setJbossWebServer(Server jbossWebServer);
}
\ No newline at end of file
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -25,22 +25,23 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.apache.catalina.Server;
import org.apache.catalina.util.StringManager;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.logging.Logger;
+import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.Utils;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
+import org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler;
+import org.jboss.modcluster.ha.rpc.ThrowableGroupRpcResponse;
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPUtils;
import org.jboss.modcluster.mcmp.ResetRequestSource;
-import org.jboss.modcluster.Constants;
-import org.jboss.modcluster.Utils;
-import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
-import org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler;
-import org.jboss.modcluster.ha.rpc.ThrowableGroupRpcResponse;
/**
* {@link ResetRequestSource} that provides different reset requests
@@ -76,12 +77,12 @@
this.rpcStub = new RpcStub(serviceKeyProvider);
}
- public List<MCMPRequest> getResetRequests()
+ public List<MCMPRequest> getResetRequests(Map<String, Map<String, Status>> response)
{
if (this.singleton.isMasterNode())
{
- List<MCMPRequest> resets = this.getLocalResetRequests();
- this.addRemoteRequests(resets);
+ List<MCMPRequest> resets = this.getLocalResetRequests(response);
+ this.addRemoteRequests(resets, response);
return resets;
}
@@ -92,14 +93,14 @@
* @{inheritDoc}
* @see org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#getLocalResetRequests()
*/
- public List<MCMPRequest> getLocalResetRequests()
+ public List<MCMPRequest> getLocalResetRequests(Map<String, Map<String, Status>> response)
{
if (this.jbossWebServer == null)
{
return new ArrayList<MCMPRequest>();
}
- return MCMPUtils.getResetRequests(this.jbossWebServer, this.nodeConfig, this.balancerConfig);
+ return MCMPUtils.getResetRequests(response, this.jbossWebServer, this.nodeConfig, this.balancerConfig);
}
/**
@@ -111,9 +112,9 @@
this.jbossWebServer = jbossWebServer;
}
- private void addRemoteRequests(List<MCMPRequest> resets)
+ private void addRemoteRequests(List<MCMPRequest> resets, Map<String, Map<String, Status>> resp)
{
- List<?> responses = this.rpcStub.getResetRequests();
+ List<?> responses = this.rpcStub.getResetRequests(resp);
for (Object response : responses)
{
@@ -151,7 +152,7 @@
/**
* @see org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler#getResetRequests()
*/
- public List<?> getResetRequests()
+ public List<?> getResetRequests(Map<String, Map<String, Status>> response)
{
try
{
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/ResetRequestSourceRpcHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/ResetRequestSourceRpcHandler.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/ResetRequestSourceRpcHandler.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -21,12 +21,16 @@
*/
package org.jboss.modcluster.ha.rpc;
+import java.util.Map;
+import org.jboss.modcluster.mcmp.ResetRequestSource.Status;
+
+
/**
* @author Paul Ferraro
*
*/
public interface ResetRequestSourceRpcHandler<T>
{
- T getResetRequests();
+ T getResetRequests(Map<String, Map<String, Status>> response);
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -27,8 +27,10 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
@@ -68,7 +70,12 @@
public static MCMPRequest createConfigRequest(Engine engine, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
{
- Connector connector = Utils.findProxyConnector(engine.getService().findConnectors());
+ return createConfigRequest(engine.getJvmRoute(), engine.getService().findConnectors(), nodeConfig, balancerConfig);
+ }
+
+ public static MCMPRequest createConfigRequest(String jvmRoute, Connector[] connectors, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
+ {
+ Connector connector = Utils.findProxyConnector(connectors);
Map<String, String> parameters = new HashMap<String, String>();
ProtocolHandler handler = connector.getProtocolHandler();
@@ -167,7 +174,7 @@
parameters.put("Maxattempts", "" + maxAttempts);
}
- return new MCMPRequest(MCMPRequestType.CONFIG, false, engine.getJvmRoute(), parameters);
+ return new MCMPRequest(MCMPRequestType.CONFIG, false, jvmRoute, parameters);
}
public static MCMPRequest createEnableAppRequest(Context context)
@@ -192,14 +199,17 @@
private static MCMPRequest createRequest(MCMPRequestType type, Context context)
{
+ return createContextRequest(type, Utils.getJvmRoute(context), Utils.getHost(context), context.getPath());
+ }
+
+ private static MCMPRequest createContextRequest(MCMPRequestType type, String jvmRoute, String host, String path)
+ {
Map<String, String> parameters = new HashMap<String, String>();
- String path = context.getPath();
-
parameters.put("Context", "".equals(path) ? "/" : path);
- parameters.put("Alias", Utils.getHost(context));
+ parameters.put("Alias", host);
- return new MCMPRequest(type, false, Utils.getJvmRoute(context), parameters);
+ return new MCMPRequest(type, false, jvmRoute, parameters);
}
public static MCMPRequest createStatusRequest(Engine engine, int lbf)
@@ -229,36 +239,83 @@
private static MCMPRequest createRequest(MCMPRequestType type, Engine engine)
{
- return new MCMPRequest(type, true, engine.getJvmRoute(), EMPTY_MAP);
+ return createEngineRequest(type, engine.getJvmRoute());
}
+
+ private static MCMPRequest createEngineRequest(MCMPRequestType type, String jvmRoute)
+ {
+ return new MCMPRequest(type, true, jvmRoute, EMPTY_MAP);
+ }
/**
* Reset configuration for a particular proxy following an error.
*/
- public static List<MCMPRequest> getResetRequests(Server server, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
+ public static List<MCMPRequest> getResetRequests(Map<String, Map<String, ResetRequestSource.Status>> response, Server server, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
{
List<MCMPRequest> requests = new ArrayList<MCMPRequest>();
- Service[] services = server.findServices();
- for (Service service: services)
+ Set<String> jvmRoutes = new HashSet<String>(response.keySet());
+
+ for (Service service: server.findServices())
{
Engine engine = (Engine) service.getContainer();
- requests.add(MCMPUtils.createRemoveAllRequest(engine));
- requests.add(MCMPUtils.createConfigRequest(engine, nodeConfig, balancerConfig));
- Container[] children = engine.findChildren();
- for (Container element: children)
+
+ String jvmRoute = engine.getJvmRoute();
+
+ jvmRoutes.remove(jvmRoute);
+
+ requests.add(createConfigRequest(jvmRoute, service.findConnectors(), nodeConfig, balancerConfig));
+
+ Map<String, ResetRequestSource.Status> contextStatusMap = response.get(jvmRoute);
+
+ Set<String> contexts = new HashSet<String>();
+
+ if (contextStatusMap != null)
{
- Container[] children2 = element.findChildren();
- for (Container element2: children2)
+ contexts.addAll(contextStatusMap.keySet());
+ }
+
+ for (Container child: engine.findChildren())
+ {
+ for (Container container: child.findChildren())
{
- Context ctx = (Context) element2;
- if (Utils.isContextStarted(ctx))
+ Context context = (Context) container;
+
+ String path = context.getPath();
+
+ contexts.remove(path);
+
+ ResetRequestSource.Status status = (contextStatusMap != null) ? contextStatusMap.get(path) : null;
+
+ if (Utils.isContextStarted(context))
{
- requests.add(MCMPUtils.createEnableAppRequest(ctx));
+ if (status != ResetRequestSource.Status.ENABLED)
+ {
+ requests.add(createEnableAppRequest(context));
+ }
}
+ else
+ {
+ if (status == ResetRequestSource.Status.ENABLED)
+ {
+ requests.add(createStopAppRequest(context));
+ }
+ }
}
}
+
+ // Send REMOVE-APP requests for contexts that don't exist
+ for (String context: contexts)
+ {
+ requests.add(createContextRequest(MCMPRequestType.REMOVE_APP, jvmRoute, "", context));
+ }
}
+ // Add REMOVE-APP * for non-existing engines
+ for (String jvmRoute: jvmRoutes)
+ {
+ requests.add(createEngineRequest(MCMPRequestType.REMOVE_APP, jvmRoute));
+ }
+
return requests;
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -23,6 +23,7 @@
package org.jboss.modcluster.mcmp;
import java.util.List;
+import java.util.Map;
/**
* Source for a list of requests that should be sent to an httpd-side
@@ -34,12 +35,18 @@
*/
public interface ResetRequestSource
{
+ enum Status
+ {
+ ENABLED, DISABLED, STOPPED
+ }
+
/**
* Gets a list of requests that should be sent to an httpd-side
* mod_cluster instance when an {@link MCMPHandler} determines that
* its state needs to be reset.
*
+ * @param response a parsed INFO-RSP, expressed as the context status per context path, per jvmRoute
* @return a list of requests. Will not return <code>null</code>.
*/
- List<MCMPRequest> getResetRequests();
+ List<MCMPRequest> getResetRequests(Map<String, Map<String, Status>> response);
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -33,6 +33,7 @@
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@@ -50,10 +51,9 @@
import net.jcip.annotations.ThreadSafe;
import org.apache.catalina.util.StringManager;
-import org.apache.tomcat.util.buf.CharChunk;
-import org.apache.tomcat.util.buf.UEncoder;
import org.jboss.logging.Logger;
import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.Utils;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.mcmp.AbstractMCMPHandler;
import org.jboss.modcluster.mcmp.AddressPort;
@@ -61,7 +61,6 @@
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPServerState;
import org.jboss.modcluster.mcmp.MCMPUtils;
-import org.jboss.modcluster.Utils;
import org.jboss.modcluster.mcmp.ResetRequestSource;
import org.jboss.modcluster.mcmp.MCMPServerState.State;
@@ -75,7 +74,7 @@
public class DefaultMCMPHandler extends AbstractMCMPHandler
{
protected static final Logger log = Logger.getLogger(DefaultMCMPHandler.class);
-
+
/** The string manager for this package. */
protected StringManager sm = StringManager.getManager(Constants.Package);
@@ -436,9 +435,6 @@
{
this.processPendingDiscoveryEvents();
- // Attempt to reset any proxies in error
- List<MCMPRequest> resetRequests = null;
-
Lock lock = this.proxiesLock.readLock();
lock.lock();
@@ -446,11 +442,12 @@
{
for (Proxy proxy: this.proxies)
{
+ // Attempt to reset any proxies in error
if (proxy.getState() == Proxy.State.ERROR)
{
proxy.setState(Proxy.State.OK);
- this.sendRequest(MCMPUtils.INFO_REQUEST, proxy);
+ String response = this.sendRequest(MCMPUtils.INFO_REQUEST, proxy);
if (proxy.getState() == Proxy.State.OK)
{
@@ -460,15 +457,9 @@
if (sendResetRequests)
{
- if (resetRequests == null)
- {
- resetRequests = this.resetRequestSource.getResetRequests();
- }
-
- for (MCMPRequest request: resetRequests)
- {
- this.sendRequest(request, proxy);
- }
+ Map<String, Map<String, ResetRequestSource.Status>> responseMap = this.parseInfoResponse(response);
+
+ this.sendRequests(this.resetRequestSource.getResetRequests(responseMap));
}
}
}
@@ -480,6 +471,73 @@
}
}
+ private Map<String, Map<String, ResetRequestSource.Status>> parseInfoResponse(String response)
+ {
+ if (response == null) return Collections.emptyMap();
+
+ Map<String, Map<String, ResetRequestSource.Status>> result = new HashMap<String, Map<String, ResetRequestSource.Status>>();
+ Map<String, ResetRequestSource.Status> contextMap = null;
+
+ for (String line: response.split("\r\n|\r|\n"))
+ {
+ if (line.startsWith("Node:"))
+ {
+ String[] entries = line.split(",");
+
+ for (int i = 1; i < entries.length; ++i)
+ {
+ String entry = entries[i];
+ int index = entry.indexOf(':');
+
+ if (index >= 0)
+ {
+ String key = entry.substring(0, index).trim();
+
+ if ("Name".equals(key))
+ {
+ contextMap = new HashMap<String, ResetRequestSource.Status>();
+ result.put(entry.substring(index + 1).trim(), contextMap);
+ break;
+ }
+ }
+ }
+ }
+ else if (line.startsWith("Context:"))
+ {
+ if (contextMap == null) throw new IllegalStateException();
+
+ String[] entries = line.split(",");
+ String context = null;
+ ResetRequestSource.Status status = null;
+
+ for (int i = 1; i < entries.length; ++i)
+ {
+ String entry = entries[i];
+ int index = entry.indexOf(':');
+
+ if (index >= 0)
+ {
+ String key = entry.substring(0, index).trim();
+ String value = entry.substring(index + 1).trim();
+
+ if ("Context".equals(key))
+ {
+ context = value;
+ }
+ else if ("Status".equals(key))
+ {
+ status = ResetRequestSource.Status.valueOf(value);
+ }
+ }
+ }
+
+ contextMap.put(context, status);
+ }
+ }
+
+ return result;
+ }
+
/**
* Send HTTP request, with the specified list of parameters. If an IO error occurs, the error state will
* be set. If the front end server reports an error, will mark as error Proxy.State. Other unexpected exceptions
@@ -673,26 +731,26 @@
// Read the response to a string
BufferedReader reader = proxy.getConnectionReader();
// Read the first response line and skip the rest of the HTTP header
- String responseStatus = reader.readLine();
+ String line = reader.readLine();
// Parse the line, which is formed like HTTP/1.x YYY Message
int status = 500;
// String version = "0";
String message = null;
String errorType = null;
int contentLength = 0;
- if (responseStatus != null)
+ if (line != null)
{
try
{
- responseStatus = responseStatus.substring(responseStatus.indexOf(' ') + 1, responseStatus.indexOf(
- ' ', responseStatus.indexOf(' ') + 1));
+ int spaceIndex = line.indexOf(' ');
+ String responseStatus = line.substring(spaceIndex + 1, line.indexOf(' ', spaceIndex + 1));
status = Integer.parseInt(responseStatus);
- String header = reader.readLine();
- while (!"".equals(header))
+ line = reader.readLine();
+ while (line.length() > 0)
{
- int colon = header.indexOf(':');
- String headerName = header.substring(0, colon).trim();
- String headerValue = header.substring(colon + 1).trim();
+ int colon = line.indexOf(':');
+ String headerName = line.substring(0, colon).trim();
+ String headerValue = line.substring(colon + 1).trim();
if ("version".equalsIgnoreCase(headerName))
{
// version = headerValue;
@@ -709,7 +767,7 @@
{
contentLength = Integer.parseInt(headerValue);
}
- header = reader.readLine();
+ line = reader.readLine();
}
}
catch (Exception e)
@@ -722,47 +780,45 @@
// be refreshed during the next periodic event
if (status == 200)
{
-
- // We know the request succeeded, so if appropriate
- // mark the proxy as established before any possible
- // later exception happens
if (request.getRequestType().getEstablishesServer())
{
+ // We know the request succeeded, so if appropriate
+ // mark the proxy as established before any possible
+ // later exception happens
proxy.setEstablished(true);
}
-
- // Read the request body
- StringBuilder result = new StringBuilder();
- if (contentLength > 0)
+ }
+ else
+ {
+ if ("SYNTAX".equals(errorType))
{
- int thisTime = contentLength;
- char[] buf = new char[512];
- while (contentLength > 0)
- {
- thisTime = (contentLength > buf.length) ? buf.length : contentLength;
- int n = reader.read(buf, 0, thisTime);
-
- if (n <= 0) break;
-
- result.append(buf, 0, n);
- contentLength -= n;
- }
+ // Syntax error means the protocol is incorrect, which cannot be automatically fixed
+ proxy.setState(Proxy.State.DOWN);
+ log.error(this.sm.getString("modcluster.error.syntax", command, proxy, errorType, message));
}
-
- return result.toString();
+ else
+ {
+ proxy.setState(Proxy.State.ERROR);
+ log.error(this.sm.getString("modcluster.error.other", command, proxy, errorType, message));
+ }
}
-
- if ("SYNTAX".equals(errorType))
+
+ if (contentLength == 0) return null;
+
+ // Read the request body
+ StringBuilder result = new StringBuilder();
+ char[] buffer = new char[512];
+ while (contentLength > 0)
{
- // Syntax error means the protocol is incorrect, which cannot be automatically fixed
- proxy.setState(Proxy.State.DOWN);
- log.error(this.sm.getString("modcluster.error.syntax", command, proxy, errorType, message));
+ int bytes = reader.read(buffer, 0, (contentLength > buffer.length) ? buffer.length : contentLength);
+
+ if (bytes <= 0) break;
+
+ result.append(buffer, 0, bytes);
+ contentLength -= bytes;
}
- else
- {
- proxy.setState(Proxy.State.ERROR);
- log.error(this.sm.getString("modcluster.error.other", command, proxy, errorType, message));
- }
+
+ return result.toString();
}
catch (IOException e)
{
@@ -775,6 +831,8 @@
log.info(this.sm.getString("modcluster.error.io", command, proxy), e);
proxy.setIoExceptionLogged(true);
}
+
+ return null;
}
finally
{
@@ -785,29 +843,8 @@
}
}
}
-
- return null;
}
- private CharChunk encodeParameter(UEncoder encoder, String key, String value, boolean hasNext) throws IOException
- {
- if (value == null)
- {
- throw new IllegalArgumentException(this.sm.getString("modcluster.error.nullAttribute", key));
- }
-
- encoder.encodeURL(key, 0, key.length()).append('=');
-
- CharChunk body = encoder.encodeURL(value, 0, value.length());
-
- if (hasNext)
- {
- body.append('&');
- }
-
- return body;
- }
-
/**
* This class represents a front-end httpd server.
*/
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -21,14 +21,13 @@
*/
package org.jboss.modcluster;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import junit.framework.TestCase;
-
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.ContainerListener;
@@ -48,12 +47,16 @@
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPRequestType;
+import org.jboss.modcluster.mcmp.ResetRequestSource;
+import org.junit.Assert;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class ClusterListenerTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class ClusterListenerTestCase
{
private static final LifecycleServer server = EasyMock.createStrictMock(LifecycleServer.class);
{
@@ -66,7 +69,8 @@
private final ClusterListener listener = new ClusterListener(this.mcmpHandler, this.lifecycleListener, this.containerListener);
- public void testGetResetRequests() throws Exception
+ @Test
+ public void getResetRequests() throws Exception
{
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
@@ -115,55 +119,57 @@
EasyMock.replay(server, service, engine, container, context, host);
- List<MCMPRequest> requests = this.listener.getResetRequests();
+ Map<String, Map<String, ResetRequestSource.Status>> emptyResponseMap = Collections.emptyMap();
+ List<MCMPRequest> requests = this.listener.getResetRequests(emptyResponseMap);
EasyMock.verify(server, service, engine, container, context, host);
MCMPRequest request = requests.get(0);
Map<String, String> parameters = request.getParameters();
- assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- assertTrue(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
request = requests.get(1);
parameters = request.getParameters();
- assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertEquals(16, parameters.size());
- assertEquals("127.0.0.1", parameters.get("Host"));
- assertEquals("0", parameters.get("Port"));
- assertEquals("ajp", parameters.get("Type"));
- assertEquals("domain", parameters.get("Domain"));
- assertEquals("On", parameters.get("flushpackets"));
- assertEquals("1", parameters.get("flushwait"));
- assertEquals("2", parameters.get("ping"));
- assertEquals("3", parameters.get("smax"));
- assertEquals("4", parameters.get("ttl"));
- assertEquals("5", parameters.get("Timeout"));
- assertEquals("S", parameters.get("Balancer"));
- assertEquals("No", parameters.get("StickySession"));
- assertEquals("Yes", parameters.get("StickySessionRemove"));
- assertEquals("No", parameters.get("StickySessionForce"));
- assertEquals("6", parameters.get("WaitWorker"));
- assertEquals("7", parameters.get("Maxattempts"));
+ Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertEquals(16, parameters.size());
+ Assert.assertEquals("127.0.0.1", parameters.get("Host"));
+ Assert.assertEquals("0", parameters.get("Port"));
+ Assert.assertEquals("ajp", parameters.get("Type"));
+ Assert.assertEquals("domain", parameters.get("Domain"));
+ Assert.assertEquals("On", parameters.get("flushpackets"));
+ Assert.assertEquals("1", parameters.get("flushwait"));
+ Assert.assertEquals("2", parameters.get("ping"));
+ Assert.assertEquals("3", parameters.get("smax"));
+ Assert.assertEquals("4", parameters.get("ttl"));
+ Assert.assertEquals("5", parameters.get("Timeout"));
+ Assert.assertEquals("S", parameters.get("Balancer"));
+ Assert.assertEquals("No", parameters.get("StickySession"));
+ Assert.assertEquals("Yes", parameters.get("StickySessionRemove"));
+ Assert.assertEquals("No", parameters.get("StickySessionForce"));
+ Assert.assertEquals("6", parameters.get("WaitWorker"));
+ Assert.assertEquals("7", parameters.get("Maxattempts"));
request = requests.get(2);
parameters = request.getParameters();
- assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
EasyMock.reset(server, service, engine, container, context, host);
}
- public void testGetProxyConfiguration()
+ @Test
+ public void getProxyConfiguration()
{
EasyMock.expect(this.mcmpHandler.getProxyConfiguration()).andReturn("config");
@@ -173,12 +179,13 @@
EasyMock.verify(this.mcmpHandler);
- assertEquals("config", result);
+ Assert.assertEquals("config", result);
EasyMock.reset(this.mcmpHandler);
}
- public void testReset()
+ @Test
+ public void reset()
{
this.mcmpHandler.reset();
@@ -190,7 +197,8 @@
EasyMock.reset(this.mcmpHandler);
}
- public void testRefresh()
+ @Test
+ public void refresh()
{
this.mcmpHandler.markProxiesInError();
@@ -202,7 +210,8 @@
EasyMock.reset(this.mcmpHandler);
}
- public void testEnable()
+ @Test
+ public void enable()
{
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
@@ -221,19 +230,20 @@
EasyMock.verify(this.mcmpHandler, server, service, engine);
- assertTrue(result);
+ Assert.assertTrue(result);
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- assertTrue(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertTrue(request.getParameters().isEmpty());
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
EasyMock.reset(this.mcmpHandler, server, service, engine);
}
- public void testDisable()
+ @Test
+ public void disable()
{
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
@@ -252,19 +262,20 @@
EasyMock.verify(this.mcmpHandler, server, service, engine);
- assertTrue(result);
+ Assert.assertTrue(result);
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
- assertTrue(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertTrue(request.getParameters().isEmpty());
+ Assert.assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
EasyMock.reset(this.mcmpHandler, server, service, engine);
}
- public void testContainerEvent()
+ @Test
+ public void containerEvent()
{
ContainerEvent event = new ContainerEvent(EasyMock.createMock(Container.class), Container.ADD_CHILD_EVENT, null);
@@ -278,7 +289,8 @@
EasyMock.reset(this.containerListener);
}
- public void testStartServerLifecycleEvent() throws MalformedObjectNameException
+ @Test
+ public void startServerLifecycleEvent() throws MalformedObjectNameException
{
LifecycleEvent event = new LifecycleEvent(server, Lifecycle.AFTER_START_EVENT);
@@ -295,12 +307,13 @@
Registry registry = Registry.getRegistry(null, null);
ObjectName name = ObjectName.getInstance("domain:type=ClusterListener");
- assertTrue(registry.getMBeanServer().isRegistered(name));
+ Assert.assertTrue(registry.getMBeanServer().isRegistered(name));
EasyMock.reset(this.lifecycleListener, server);
}
- public void testStopServerLifecycleEvent() throws MalformedObjectNameException
+ @Test
+ public void stopServerLifecycleEvent() throws MalformedObjectNameException
{
LifecycleEvent event = new LifecycleEvent(server, Lifecycle.STOP_EVENT);
@@ -317,12 +330,13 @@
Registry registry = Registry.getRegistry(null, null);
ObjectName name = ObjectName.getInstance("domain:type=ClusterListener");
- assertFalse(registry.getMBeanServer().isRegistered(name));
+ Assert.assertFalse(registry.getMBeanServer().isRegistered(name));
EasyMock.reset(this.lifecycleListener, server);
}
- public void testOtherLifecycleEvent()
+ @Test
+ public void otherLifecycleEvent()
{
LifecycleEvent event = new LifecycleEvent(EasyMock.createMock(Lifecycle.class), Lifecycle.START_EVENT);
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -32,8 +32,6 @@
import java.util.Set;
import java.util.TreeSet;
-import junit.framework.TestCase;
-
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
@@ -63,12 +61,16 @@
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPRequestType;
import org.jboss.modcluster.mcmp.MCMPServerState;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class ModClusterServiceTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class ModClusterServiceTestCase
{
private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
private NodeConfiguration nodeConfig = EasyMock.createMock(NodeConfiguration.class);
@@ -87,12 +89,8 @@
private ModClusterService modClusterService;
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
EasyMock.expect(this.mcmpConfig.isMasterPerDomain()).andReturn(MASTER_PER_DOMAIN);
EasyMock.expect(this.nodeConfig.getDomain()).andReturn(DOMAIN);
@@ -108,7 +106,8 @@
EasyMock.reset(this.mcmpConfig, this.nodeConfig, this.partition);
}
- public void testAddProxy()
+ @Test
+ public void addProxy()
{
String host = "127.0.0.1";
int port = 0;
@@ -123,7 +122,8 @@
EasyMock.reset(this.clusteredMCMPHandler);
}
- public void testRemoveProxy()
+ @Test
+ public void removeProxy()
{
String host = "127.0.0.1";
int port = 0;
@@ -138,7 +138,8 @@
EasyMock.reset(this.clusteredMCMPHandler);
}
- public void testGetProxyConfiguration()
+ @Test
+ public void getProxyConfiguration()
{
EasyMock.expect(this.clusteredMCMPHandler.getProxyConfiguration()).andReturn("configuration");
@@ -148,12 +149,13 @@
EasyMock.verify(this.clusteredMCMPHandler);
- assertEquals("configuration", result);
+ Assert.assertEquals("configuration", result);
EasyMock.reset(this.clusteredMCMPHandler);
}
- public void testReset()
+ @Test
+ public void reset()
{
this.clusteredMCMPHandler.reset();
@@ -165,7 +167,8 @@
EasyMock.reset(this.clusteredMCMPHandler);
}
- public void testRefresh()
+ @Test
+ public void refresh()
{
this.clusteredMCMPHandler.markProxiesInError();
@@ -177,7 +180,8 @@
EasyMock.reset(this.clusteredMCMPHandler);
}
- public void testInit() throws UnknownHostException
+ @Test
+ public void init() throws UnknownHostException
{
InetAddress localAddress = InetAddress.getLocalHost();
String localHostName = localAddress.getHostName();
@@ -214,7 +218,8 @@
EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
}
- public void testStartServer() throws Exception
+ @Test
+ public void startServer() throws Exception
{
Server server = EasyMock.createStrictMock(Server.class);
@@ -227,7 +232,7 @@
{
this.modClusterService.startServer(server);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
@@ -237,7 +242,7 @@
EasyMock.verify(this.resetRequestSource);
EasyMock.reset(this.resetRequestSource);
- testInit();
+ init();
// Test initialized
Service service = EasyMock.createStrictMock(Service.class);
@@ -261,7 +266,7 @@
EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
EasyMock.expect(engine.getJvmRoute()).andReturn(null);
Set<MCMPServerState> states = Collections.emptySet();
- EasyMock.expect(this.clusteredMCMPHandler.getProxyStates()).andReturn(states);
+ EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
EasyMock.expect(engine.getJvmRoute()).andReturn("route");
EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
@@ -292,42 +297,42 @@
EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
this.recordAddContext(context, container);
- EasyMock.replay(this.partition, this.resetRequestSource, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+ EasyMock.replay(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
this.modClusterService.startServer(server);
- EasyMock.verify(this.partition, this.resetRequestSource, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+ EasyMock.verify(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(16, parameters.size());
- assertEquals("127.0.0.1", parameters.get("Host"));
- assertEquals("0", parameters.get("Port"));
- assertEquals("ajp", parameters.get("Type"));
- assertEquals("domain", parameters.get("Domain"));
- assertEquals("On", parameters.get("flushpackets"));
- assertEquals("1", parameters.get("flushwait"));
- assertEquals("2", parameters.get("ping"));
- assertEquals("3", parameters.get("smax"));
- assertEquals("4", parameters.get("ttl"));
- assertEquals("5", parameters.get("Timeout"));
- assertEquals("S", parameters.get("Balancer"));
- assertEquals("No", parameters.get("StickySession"));
- assertEquals("Yes", parameters.get("StickySessionRemove"));
- assertEquals("No", parameters.get("StickySessionForce"));
- assertEquals("6", parameters.get("WaitWorker"));
- assertEquals("7", parameters.get("Maxattempts"));
+ Assert.assertEquals(16, parameters.size());
+ Assert.assertEquals("127.0.0.1", parameters.get("Host"));
+ Assert.assertEquals("0", parameters.get("Port"));
+ Assert.assertEquals("ajp", parameters.get("Type"));
+ Assert.assertEquals("domain", parameters.get("Domain"));
+ Assert.assertEquals("On", parameters.get("flushpackets"));
+ Assert.assertEquals("1", parameters.get("flushwait"));
+ Assert.assertEquals("2", parameters.get("ping"));
+ Assert.assertEquals("3", parameters.get("smax"));
+ Assert.assertEquals("4", parameters.get("ttl"));
+ Assert.assertEquals("5", parameters.get("Timeout"));
+ Assert.assertEquals("S", parameters.get("Balancer"));
+ Assert.assertEquals("No", parameters.get("StickySession"));
+ Assert.assertEquals("Yes", parameters.get("StickySessionRemove"));
+ Assert.assertEquals("No", parameters.get("StickySessionForce"));
+ Assert.assertEquals("6", parameters.get("WaitWorker"));
+ Assert.assertEquals("7", parameters.get("Maxattempts"));
Set<String> routes = this.modClusterService.drmEntry.getJvmRoutes();
- assertEquals(1, routes.size());
- assertEquals("route", routes.iterator().next());
+ Assert.assertEquals(1, routes.size());
+ Assert.assertEquals("route", routes.iterator().next());
- EasyMock.reset(this.partition, this.resetRequestSource, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+ EasyMock.reset(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
}
private void recordAddContext(Context context, Container container)
@@ -340,7 +345,8 @@
EasyMock.expect(context.isStarted()).andReturn(false);
}
- public void testStopServer() throws Exception
+ @Test
+ public void stopServer() throws Exception
{
Server server = EasyMock.createStrictMock(Server.class);
@@ -349,14 +355,14 @@
{
this.modClusterService.stopServer(server);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ init();
this.modClusterService.drmEntry.addJvmRoute("route");
@@ -394,12 +400,12 @@
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- assertTrue(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertTrue(request.getParameters().isEmpty());
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
- assertTrue(this.modClusterService.drmEntry.getJvmRoutes().isEmpty());
+ Assert.assertTrue(this.modClusterService.drmEntry.getJvmRoutes().isEmpty());
EasyMock.reset(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
}
@@ -416,7 +422,8 @@
EasyMock.expect(engine.getJvmRoute()).andReturn(null);
}
- public void testAddContext() throws UnknownHostException
+ @Test
+ public void addContext() throws UnknownHostException
{
Context context = EasyMock.createStrictMock(Context.class);
@@ -425,14 +432,14 @@
{
this.modClusterService.addContext(context);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ init();
// Test context not started
Container container = EasyMock.createStrictMock(Container.class);
@@ -477,21 +484,22 @@
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(2, parameters.size());
+ Assert.assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
EasyMock.reset(this.clusteredMCMPHandler, context, container, engine, host);
}
- public void testStartContext() throws UnknownHostException
+ @Test
+ public void startContext() throws UnknownHostException
{
Context context = EasyMock.createStrictMock(Context.class);
@@ -500,14 +508,14 @@
{
this.modClusterService.startContext(context);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ init();
// Test initialized
Container container = EasyMock.createStrictMock(Container.class);
@@ -539,21 +547,22 @@
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(2, parameters.size());
+ Assert.assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
EasyMock.reset(this.clusteredMCMPHandler, context, container, engine, host);
}
- public void testStopContext() throws UnknownHostException
+ @Test
+ public void stopContext() throws UnknownHostException
{
Context context = EasyMock.createStrictMock(Context.class);
@@ -562,14 +571,14 @@
{
this.modClusterService.stopContext(context);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ init();
// Test initialized
Container container = EasyMock.createStrictMock(Container.class);
@@ -601,21 +610,22 @@
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(2, parameters.size());
+ Assert.assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
EasyMock.reset(this.clusteredMCMPHandler, context, container, engine, host);
}
- public void testRemoveContext() throws UnknownHostException
+ @Test
+ public void removeContext() throws UnknownHostException
{
Context context = EasyMock.createStrictMock(Context.class);
@@ -624,14 +634,14 @@
{
this.modClusterService.removeContext(context);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ init();
// Test initialized - no jvm route
Container container = EasyMock.createStrictMock(Container.class);
@@ -679,21 +689,23 @@
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(2, parameters.size());
+ Assert.assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
EasyMock.reset(this.clusteredMCMPHandler, context, container, engine, host);
}
- public void testStatus() throws Exception
+ @SuppressWarnings("unchecked")
+ @Test
+ public void status() throws Exception
{
Engine engine = EasyMock.createStrictMock(Engine.class);
@@ -726,7 +738,7 @@
EasyMock.verify(this.partition, drm);
- assertTrue(this.modClusterService.isMasterNode());
+ Assert.assertTrue(this.modClusterService.isMasterNode());
EasyMock.reset(this.partition, drm);
@@ -840,42 +852,42 @@
List<MCMPRequest> requests = capturedRequests.getValue();
- assertEquals(2, requests.size());
+ Assert.assertEquals(2, requests.size());
- assertSame(MCMPRequestType.STATUS, requests.get(0).getRequestType());
- assertFalse(requests.get(0).isWildcard());
- assertEquals("host2", requests.get(0).getJvmRoute());
- assertEquals(1, requests.get(0).getParameters().size());
- assertEquals("20", requests.get(0).getParameters().get("Load"));
+ Assert.assertSame(MCMPRequestType.STATUS, requests.get(0).getRequestType());
+ Assert.assertFalse(requests.get(0).isWildcard());
+ Assert.assertEquals("host2", requests.get(0).getJvmRoute());
+ Assert.assertEquals(1, requests.get(0).getParameters().size());
+ Assert.assertEquals("20", requests.get(0).getParameters().get("Load"));
- assertSame(MCMPRequestType.STATUS, requests.get(1).getRequestType());
- assertFalse(requests.get(1).isWildcard());
- assertEquals("host1", requests.get(1).getJvmRoute());
- assertEquals(1, requests.get(1).getParameters().size());
- assertEquals("10", requests.get(1).getParameters().get("Load"));
+ Assert.assertSame(MCMPRequestType.STATUS, requests.get(1).getRequestType());
+ Assert.assertFalse(requests.get(1).isWildcard());
+ Assert.assertEquals("host1", requests.get(1).getJvmRoute());
+ Assert.assertEquals(1, requests.get(1).getParameters().size());
+ Assert.assertEquals("10", requests.get(1).getParameters().get("Load"));
ModClusterServiceDRMEntry entry = capturedEntry.getValue();
- assertSame(this.node, entry.getPeer());
- assertEquals(states, entry.getMCMPServerStates());
- assertTrue(entry.getJvmRoutes().isEmpty());
+ Assert.assertSame(this.node, entry.getPeer());
+ Assert.assertEquals(states, entry.getMCMPServerStates());
+ Assert.assertTrue(entry.getJvmRoutes().isEmpty());
Object[] args = capturedArgs.getValue();
- assertEquals(1, args.length);
- assertTrue(args[0] instanceof Map);
+ Assert.assertEquals(1, args.length);
+ Assert.assertTrue(args[0] instanceof Map);
- Map<ClusterNode, PeerMCMPDiscoveryStatus> map = (Map) args[0];
+ Map<ClusterNode, PeerMCMPDiscoveryStatus> map = (Map<ClusterNode, PeerMCMPDiscoveryStatus>) args[0];
- assertEquals(2, map.size());
- assertTrue(map.containsKey(remoteNode1));
- assertTrue(map.containsKey(remoteNode2));
+ Assert.assertEquals(2, map.size());
+ Assert.assertTrue(map.containsKey(remoteNode1));
+ Assert.assertTrue(map.containsKey(remoteNode2));
PeerMCMPDiscoveryStatus status1 = map.get(remoteNode1);
- assertSame(remoteNode1, status1.getPeer());
- assertEquals(Collections.singleton(remoteState1), status1.getMCMPServerStates());
- assertTrue(status1.getJvmRoutes().isEmpty());
- assertNull(status1.getLatestDiscoveryEvent());
+ Assert.assertSame(remoteNode1, status1.getPeer());
+ Assert.assertEquals(Collections.singleton(remoteState1), status1.getMCMPServerStates());
+ Assert.assertTrue(status1.getJvmRoutes().isEmpty());
+ Assert.assertNull(status1.getLatestDiscoveryEvent());
EasyMock.reset(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -29,8 +29,6 @@
import java.util.List;
import java.util.Set;
-import junit.framework.TestCase;
-
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.jboss.ha.framework.interfaces.ClusterNode;
@@ -48,12 +46,15 @@
import org.jboss.modcluster.mcmp.MCMPRequestType;
import org.jboss.modcluster.mcmp.MCMPServer;
import org.jboss.modcluster.mcmp.MCMPServerState;
+import org.junit.Assert;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class ClusteredMCMPHandlerTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class ClusteredMCMPHandlerTestCase
{
private MCMPHandler localHandler = EasyMock.createStrictMock(MCMPHandler.class);
private HAServiceKeyProvider keyProvider = EasyMock.createStrictMock(HAServiceKeyProvider.class);
@@ -61,8 +62,9 @@
private HASingletonMBean singleton = EasyMock.createStrictMock(HASingletonMBean.class);
private ClusteredMCMPHandler handler = new ClusteredMCMPHandlerImpl(this.localHandler, this.singleton, this.keyProvider);
-
- public void testGetPartitionName()
+
+ @Test
+ public void getPartitionName()
{
String expected = "name";
@@ -75,12 +77,13 @@
EasyMock.verify(this.keyProvider, this.partition);
- assertSame(expected, result);
+ Assert.assertSame(expected, result);
EasyMock.reset(this.keyProvider, this.partition);
}
- public void testInit() throws Exception
+ @Test
+ public void init() throws Exception
{
ClusterNode node = EasyMock.createMock(ClusterNode.class);
InetAddress address = InetAddress.getLocalHost();
@@ -123,30 +126,31 @@
EasyMock.verify(this.localHandler, this.singleton, this.keyProvider, this.partition);
- assertNotNull(capturedList.getValue());
- assertTrue(capturedList.getValue().isEmpty());
+ Assert.assertNotNull(capturedList.getValue());
+ Assert.assertTrue(capturedList.getValue().isEmpty());
List<MCMPServerDiscoveryEvent> events = this.handler.getPendingDiscoveryEvents();
- assertNotNull(events);
- assertEquals(1, events.size());
+ Assert.assertNotNull(events);
+ Assert.assertEquals(1, events.size());
MCMPServerDiscoveryEvent event = events.get(0);
- assertSame(node, event.getSender());
- assertSame(address, event.getMCMPServer().getAddress());
- assertEquals(port, event.getMCMPServer().getPort());
- assertTrue(event.isAddition());
- assertEquals(1, event.getEventIndex());
+ Assert.assertSame(node, event.getSender());
+ Assert.assertSame(address, event.getMCMPServer().getAddress());
+ Assert.assertEquals(port, event.getMCMPServer().getPort());
+ Assert.assertTrue(event.isAddition());
+ Assert.assertEquals(1, event.getEventIndex());
- assertNotNull(capturedEvents.getValue());
- assertEquals(1, capturedEvents.getValue().length);
- assertSame(event, capturedEvents.getValue()[0]);
+ Assert.assertNotNull(capturedEvents.getValue());
+ Assert.assertEquals(1, capturedEvents.getValue().length);
+ Assert.assertSame(event, capturedEvents.getValue()[0]);
EasyMock.reset(this.localHandler, this.singleton, this.keyProvider, this.partition);
}
- public void testUpdateServersFromMasterNode() throws Exception
+ @Test
+ public void updateServersFromMasterNode() throws Exception
{
MCMPServer server = EasyMock.createMock(MCMPServer.class);
MCMPServerState state = EasyMock.createMock(MCMPServerState.class);
@@ -180,12 +184,13 @@
EasyMock.verify(this.localHandler, this.singleton, server, state);
- assertSame(states, result);
+ Assert.assertSame(states, result);
EasyMock.reset(this.localHandler, this.singleton, server, state);
}
- public void testAddProxy() throws Exception
+ @Test
+ public void addProxy() throws Exception
{
InetAddress address = InetAddress.getLocalHost();
int port = 0;
@@ -265,20 +270,20 @@
List<MCMPServerDiscoveryEvent> events = this.handler.getPendingDiscoveryEvents();
- assertNotNull(events);
- assertEquals(1, events.size());
+ Assert.assertNotNull(events);
+ Assert.assertEquals(1, events.size());
MCMPServerDiscoveryEvent event = events.get(0);
- assertSame(node, event.getSender());
- assertSame(address, event.getMCMPServer().getAddress());
- assertEquals(port, event.getMCMPServer().getPort());
- assertTrue(event.isAddition());
- assertEquals(1, event.getEventIndex());
+ Assert.assertSame(node, event.getSender());
+ Assert.assertSame(address, event.getMCMPServer().getAddress());
+ Assert.assertEquals(port, event.getMCMPServer().getPort());
+ Assert.assertTrue(event.isAddition());
+ Assert.assertEquals(1, event.getEventIndex());
- assertNotNull(capturedEvents.getValue());
- assertEquals(1, capturedEvents.getValue().length);
- assertSame(event, capturedEvents.getValue()[0]);
+ Assert.assertNotNull(capturedEvents.getValue());
+ Assert.assertEquals(1, capturedEvents.getValue().length);
+ Assert.assertSame(event, capturedEvents.getValue()[0]);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
@@ -302,20 +307,20 @@
events = this.handler.getPendingDiscoveryEvents();
- assertNotNull(events);
- assertEquals(2, events.size());
+ Assert.assertNotNull(events);
+ Assert.assertEquals(2, events.size());
event = events.get(1);
- assertSame(node, event.getSender());
- assertSame(address, event.getMCMPServer().getAddress());
- assertEquals(port, event.getMCMPServer().getPort());
- assertTrue(event.isAddition());
- assertEquals(2, event.getEventIndex());
+ Assert.assertSame(node, event.getSender());
+ Assert.assertSame(address, event.getMCMPServer().getAddress());
+ Assert.assertEquals(port, event.getMCMPServer().getPort());
+ Assert.assertTrue(event.isAddition());
+ Assert.assertEquals(2, event.getEventIndex());
- assertNotNull(capturedEvents.getValue());
- assertEquals(1, capturedEvents.getValue().length);
- assertSame(event, capturedEvents.getValue()[0]);
+ Assert.assertNotNull(capturedEvents.getValue());
+ Assert.assertEquals(1, capturedEvents.getValue().length);
+ Assert.assertSame(event, capturedEvents.getValue()[0]);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
@@ -339,20 +344,20 @@
events = this.handler.getPendingDiscoveryEvents();
- assertNotNull(events);
- assertEquals(3, events.size());
+ Assert.assertNotNull(events);
+ Assert.assertEquals(3, events.size());
event = events.get(2);
- assertSame(node, event.getSender());
- assertSame(address, event.getMCMPServer().getAddress());
- assertEquals(port, event.getMCMPServer().getPort());
- assertTrue(event.isAddition());
- assertEquals(3, event.getEventIndex());
+ Assert.assertSame(node, event.getSender());
+ Assert.assertSame(address, event.getMCMPServer().getAddress());
+ Assert.assertEquals(port, event.getMCMPServer().getPort());
+ Assert.assertTrue(event.isAddition());
+ Assert.assertEquals(3, event.getEventIndex());
- assertNotNull(capturedEvents.getValue());
- assertEquals(1, capturedEvents.getValue().length);
- assertSame(event, capturedEvents.getValue()[0]);
+ Assert.assertNotNull(capturedEvents.getValue());
+ Assert.assertEquals(1, capturedEvents.getValue().length);
+ Assert.assertSame(event, capturedEvents.getValue()[0]);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
@@ -368,7 +373,8 @@
EasyMock.reset(this.localHandler);
}
- public void testRemoveProxy() throws Exception
+ @Test
+ public void removeProxy() throws Exception
{
InetAddress address = InetAddress.getLocalHost();
int port = 0;
@@ -424,20 +430,20 @@
List<MCMPServerDiscoveryEvent> events = this.handler.getPendingDiscoveryEvents();
- assertNotNull(events);
- assertEquals(1, events.size());
+ Assert.assertNotNull(events);
+ Assert.assertEquals(1, events.size());
MCMPServerDiscoveryEvent event = events.get(0);
- assertSame(node, event.getSender());
- assertSame(address, event.getMCMPServer().getAddress());
- assertEquals(port, event.getMCMPServer().getPort());
- assertFalse(event.isAddition());
- assertEquals(1, event.getEventIndex());
+ Assert.assertSame(node, event.getSender());
+ Assert.assertSame(address, event.getMCMPServer().getAddress());
+ Assert.assertEquals(port, event.getMCMPServer().getPort());
+ Assert.assertFalse(event.isAddition());
+ Assert.assertEquals(1, event.getEventIndex());
- assertNotNull(capturedEvents.getValue());
- assertEquals(1, capturedEvents.getValue().length);
- assertSame(event, capturedEvents.getValue()[0]);
+ Assert.assertNotNull(capturedEvents.getValue());
+ Assert.assertEquals(1, capturedEvents.getValue().length);
+ Assert.assertSame(event, capturedEvents.getValue()[0]);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
@@ -461,25 +467,26 @@
events = this.handler.getPendingDiscoveryEvents();
- assertNotNull(events);
- assertEquals(2, events.size());
+ Assert.assertNotNull(events);
+ Assert.assertEquals(2, events.size());
event = events.get(1);
- assertSame(node, event.getSender());
- assertSame(address, event.getMCMPServer().getAddress());
- assertEquals(port, event.getMCMPServer().getPort());
- assertFalse(event.isAddition());
- assertEquals(2, event.getEventIndex());
+ Assert.assertSame(node, event.getSender());
+ Assert.assertSame(address, event.getMCMPServer().getAddress());
+ Assert.assertEquals(port, event.getMCMPServer().getPort());
+ Assert.assertFalse(event.isAddition());
+ Assert.assertEquals(2, event.getEventIndex());
- assertNotNull(capturedEvents.getValue());
- assertEquals(1, capturedEvents.getValue().length);
- assertSame(event, capturedEvents.getValue()[0]);
+ Assert.assertNotNull(capturedEvents.getValue());
+ Assert.assertEquals(1, capturedEvents.getValue().length);
+ Assert.assertSame(event, capturedEvents.getValue()[0]);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
- public void testGetProxyStates()
+ @Test
+ public void getProxyStates()
{
Set<MCMPServerState> states = Collections.emptySet();
@@ -491,12 +498,13 @@
EasyMock.verify(this.localHandler);
- assertSame(states, result);
+ Assert.assertSame(states, result);
EasyMock.reset(this.localHandler);
}
- public void testGetLocalAddress() throws UnknownHostException, IOException
+ @Test
+ public void getLocalAddress() throws UnknownHostException, IOException
{
InetAddress address = InetAddress.getLocalHost();
@@ -508,12 +516,13 @@
EasyMock.verify(this.localHandler);
- assertSame(address, result);
+ Assert.assertSame(address, result);
EasyMock.reset(this.localHandler);
}
- public void testGetProxyConfiguration() throws Exception
+ @Test
+ public void getProxyConfiguration() throws Exception
{
String configuration = "configuration";
@@ -528,7 +537,7 @@
EasyMock.verify(this.localHandler, this.singleton);
- assertSame(configuration, result);
+ Assert.assertSame(configuration, result);
EasyMock.reset(this.localHandler, this.singleton);
@@ -550,12 +559,13 @@
EasyMock.verify(this.keyProvider, this.partition, this.singleton);
- assertSame(configuration, result);
+ Assert.assertSame(configuration, result);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
- public void testIsProxyHealthOK() throws Exception
+ @Test
+ public void isProxyHealthOK() throws Exception
{
// Test master use case
EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
@@ -568,7 +578,7 @@
EasyMock.verify(this.localHandler, this.singleton);
- assertTrue(result);
+ Assert.assertTrue(result);
EasyMock.reset(this.localHandler, this.singleton);
@@ -590,12 +600,13 @@
EasyMock.verify(this.keyProvider, this.partition, this.singleton);
- assertTrue(result);
+ Assert.assertTrue(result);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
- public void testMarkProxiesInError() throws Exception
+ @Test
+ public void markProxiesInError() throws Exception
{
// Test master use case
EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
@@ -629,7 +640,8 @@
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
- public void testReset() throws Exception
+ @Test
+ public void reset() throws Exception
{
// Test master use case
EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
@@ -663,7 +675,8 @@
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
- public void testSendRequest() throws Exception
+ @Test
+ public void sendRequest() throws Exception
{
MCMPRequest request = new MCMPRequest(MCMPRequestType.INFO, false, "route", Collections.singletonMap("name", "value"));
@@ -699,14 +712,15 @@
EasyMock.verify(this.keyProvider, this.partition, this.singleton);
- assertNotNull(captured.getValue());
- assertEquals(1, captured.getValue().length);
- assertSame(request, captured.getValue()[0]);
+ Assert.assertNotNull(captured.getValue());
+ Assert.assertEquals(1, captured.getValue().length);
+ Assert.assertSame(request, captured.getValue()[0]);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
- public void testSendRequests() throws Exception
+ @Test
+ public void sendRequests() throws Exception
{
List<MCMPRequest> requests = Collections.emptyList();
@@ -742,14 +756,15 @@
EasyMock.verify(this.keyProvider, this.partition, this.singleton);
- assertNotNull(captured.getValue());
- assertEquals(1, captured.getValue().length);
- assertSame(requests, captured.getValue()[0]);
+ Assert.assertNotNull(captured.getValue());
+ Assert.assertEquals(1, captured.getValue().length);
+ Assert.assertSame(requests, captured.getValue()[0]);
EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
- public void testShutdown()
+ @Test
+ public void shutdown()
{
this.localHandler.shutdown();
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2008-10-22 02:03:07 UTC (rev 1973)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2008-10-22 02:15:23 UTC (rev 1974)
@@ -27,8 +27,6 @@
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
@@ -46,12 +44,16 @@
import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPRequestType;
+import org.jboss.modcluster.mcmp.ResetRequestSource;
+import org.junit.Assert;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class HASingletonAwareResetRequestSourceTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class HASingletonAwareResetRequestSourceTestCase
{
private NodeConfiguration nodeConfig = EasyMock.createStrictMock(NodeConfiguration.class);
private BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
@@ -60,8 +62,9 @@
private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
private HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.singleton, this.key);
-
- public void testGetResetRequests() throws Exception
+
+ @Test
+ public void getResetRequests() throws Exception
{
Map<String, String> emptyMap = Collections.emptyMap();
MCMPRequest request1 = new MCMPRequest(MCMPRequestType.ENABLE_APP, false, "host1", emptyMap);
@@ -79,13 +82,14 @@
EasyMock.replay(this.singleton, this.key, this.partition);
- List<MCMPRequest> results = this.source.getResetRequests();
+ Map<String, Map<String, ResetRequestSource.Status>> emptyResponseMap = Collections.emptyMap();
+ List<MCMPRequest> results = this.source.getResetRequests(emptyResponseMap);
EasyMock.verify(this.singleton, this.key, this.partition);
- assertEquals(2, results.size());
- assertSame(request1, results.get(0));
- assertSame(request2, results.get(1));
+ Assert.assertEquals(2, results.size());
+ Assert.assertSame(request1, results.get(0));
+ Assert.assertSame(request2, results.get(1));
EasyMock.reset(this.singleton, this.key, this.partition);
@@ -144,72 +148,74 @@
EasyMock.replay(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
- results = this.source.getResetRequests();
+ results = this.source.getResetRequests(emptyResponseMap);
EasyMock.verify(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
- assertEquals(5, results.size());
+ Assert.assertEquals(5, results.size());
MCMPRequest request = results.get(0);
Map<String, String> parameters = request.getParameters();
- assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- assertTrue(request.isWildcard());
- assertEquals("host", request.getJvmRoute());
- assertTrue(request.getParameters().isEmpty());
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
request = results.get(1);
parameters = request.getParameters();
- assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertEquals(16, parameters.size());
- assertEquals("127.0.0.1", parameters.get("Host"));
- assertEquals("0", parameters.get("Port"));
- assertEquals("ajp", parameters.get("Type"));
- assertEquals("domain", parameters.get("Domain"));
- assertEquals("On", parameters.get("flushpackets"));
- assertEquals("1", parameters.get("flushwait"));
- assertEquals("2", parameters.get("ping"));
- assertEquals("3", parameters.get("smax"));
- assertEquals("4", parameters.get("ttl"));
- assertEquals("5", parameters.get("Timeout"));
- assertEquals("S", parameters.get("Balancer"));
- assertEquals("No", parameters.get("StickySession"));
- assertEquals("Yes", parameters.get("StickySessionRemove"));
- assertEquals("No", parameters.get("StickySessionForce"));
- assertEquals("6", parameters.get("WaitWorker"));
- assertEquals("7", parameters.get("Maxattempts"));
+ Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertEquals(16, parameters.size());
+ Assert.assertEquals("127.0.0.1", parameters.get("Host"));
+ Assert.assertEquals("0", parameters.get("Port"));
+ Assert.assertEquals("ajp", parameters.get("Type"));
+ Assert.assertEquals("domain", parameters.get("Domain"));
+ Assert.assertEquals("On", parameters.get("flushpackets"));
+ Assert.assertEquals("1", parameters.get("flushwait"));
+ Assert.assertEquals("2", parameters.get("ping"));
+ Assert.assertEquals("3", parameters.get("smax"));
+ Assert.assertEquals("4", parameters.get("ttl"));
+ Assert.assertEquals("5", parameters.get("Timeout"));
+ Assert.assertEquals("S", parameters.get("Balancer"));
+ Assert.assertEquals("No", parameters.get("StickySession"));
+ Assert.assertEquals("Yes", parameters.get("StickySessionRemove"));
+ Assert.assertEquals("No", parameters.get("StickySessionForce"));
+ Assert.assertEquals("6", parameters.get("WaitWorker"));
+ Assert.assertEquals("7", parameters.get("Maxattempts"));
request = results.get(2);
parameters = request.getParameters();
- assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
- assertSame(request1, results.get(3));
- assertSame(request2, results.get(4));
+ Assert.assertSame(request1, results.get(3));
+ Assert.assertSame(request2, results.get(4));
EasyMock.reset(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
// Test non-master
- results = this.source.getResetRequests();
+ results = this.source.getResetRequests(emptyResponseMap);
- assertTrue(results.isEmpty());
+ Assert.assertTrue(results.isEmpty());
}
- public void testGetLocalResetRequests() throws Exception
+ @Test
+ public void getLocalResetRequests() throws Exception
{
+ Map<String, Map<String, ResetRequestSource.Status>> emptyResponseMap = Collections.emptyMap();
// Test w/out server
- List<MCMPRequest> results = this.source.getLocalResetRequests();
+ List<MCMPRequest> results = this.source.getLocalResetRequests(emptyResponseMap);
- assertTrue(results.isEmpty());
+ Assert.assertTrue(results.isEmpty());
// Test w/server
@@ -260,52 +266,52 @@
EasyMock.replay(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
- results = this.source.getLocalResetRequests();
+ results = this.source.getLocalResetRequests(emptyResponseMap);
EasyMock.verify(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
- assertEquals(3, results.size());
+ Assert.assertEquals(3, results.size());
MCMPRequest request = results.get(0);
- assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- assertTrue(request.isWildcard());
- assertEquals("host", request.getJvmRoute());
- assertTrue(request.getParameters().isEmpty());
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
request = results.get(1);
Map<String, String> parameters = request.getParameters();
- assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertEquals(16, parameters.size());
- assertEquals("127.0.0.1", parameters.get("Host"));
- assertEquals("0", parameters.get("Port"));
- assertEquals("ajp", parameters.get("Type"));
- assertEquals("domain", parameters.get("Domain"));
- assertEquals("On", parameters.get("flushpackets"));
- assertEquals("1", parameters.get("flushwait"));
- assertEquals("2", parameters.get("ping"));
- assertEquals("3", parameters.get("smax"));
- assertEquals("4", parameters.get("ttl"));
- assertEquals("5", parameters.get("Timeout"));
- assertEquals("S", parameters.get("Balancer"));
- assertEquals("No", parameters.get("StickySession"));
- assertEquals("Yes", parameters.get("StickySessionRemove"));
- assertEquals("No", parameters.get("StickySessionForce"));
- assertEquals("6", parameters.get("WaitWorker"));
- assertEquals("7", parameters.get("Maxattempts"));
+ Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertEquals(16, parameters.size());
+ Assert.assertEquals("127.0.0.1", parameters.get("Host"));
+ Assert.assertEquals("0", parameters.get("Port"));
+ Assert.assertEquals("ajp", parameters.get("Type"));
+ Assert.assertEquals("domain", parameters.get("Domain"));
+ Assert.assertEquals("On", parameters.get("flushpackets"));
+ Assert.assertEquals("1", parameters.get("flushwait"));
+ Assert.assertEquals("2", parameters.get("ping"));
+ Assert.assertEquals("3", parameters.get("smax"));
+ Assert.assertEquals("4", parameters.get("ttl"));
+ Assert.assertEquals("5", parameters.get("Timeout"));
+ Assert.assertEquals("S", parameters.get("Balancer"));
+ Assert.assertEquals("No", parameters.get("StickySession"));
+ Assert.assertEquals("Yes", parameters.get("StickySessionRemove"));
+ Assert.assertEquals("No", parameters.get("StickySessionForce"));
+ Assert.assertEquals("6", parameters.get("WaitWorker"));
+ Assert.assertEquals("7", parameters.get("Maxattempts"));
request = results.get(2);
parameters = request.getParameters();
- assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
EasyMock.reset(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
}
16 years, 2 months
JBoss Native SVN: r1973 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 22:03:07 -0400 (Tue, 21 Oct 2008)
New Revision: 1973
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPServerState.java
Log:
cosmetic
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPServerState.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPServerState.java 2008-10-21 22:12:17 UTC (rev 1972)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPServerState.java 2008-10-22 02:03:07 UTC (rev 1973)
@@ -32,7 +32,10 @@
public interface MCMPServerState extends MCMPServer
{
/** Possible communication states vis a vis the server */
- enum State { OK, ERROR, DOWN };
+ enum State
+ {
+ OK, ERROR, DOWN
+ }
State getState();
}
16 years, 2 months
JBoss Native SVN: r1972 - trunk/mod_cluster/src/main/resources.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 18:12:17 -0400 (Tue, 21 Oct 2008)
New Revision: 1972
Modified:
trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
Log:
F
Modified: trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
===================================================================
--- trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2008-10-21 18:33:56 UTC (rev 1971)
+++ trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2008-10-21 22:12:17 UTC (rev 1972)
@@ -9,7 +9,7 @@
<bean name="ModClusterConfig" class="org.jboss.modcluster.config.ModClusterConfig" mode="On Demand">
<!-- Comma separated list of address:port listing the httpd servers
- where mod_cluster is running.
+ where mod_cluster is running. -->
<!--property name="proxyList"></property-->
<!-- URL prefix to send with commands to mod_cluster. Default is no prefix.
<!--property name="proxyURL"></property-->
16 years, 2 months
JBoss Native SVN: r1971 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 14:33:56 -0400 (Tue, 21 Oct 2008)
New Revision: 1971
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java
Log:
Use static final for response encoding.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java 2008-10-21 17:57:09 UTC (rev 1970)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java 2008-10-21 18:33:56 UTC (rev 1971)
@@ -61,7 +61,8 @@
public static final int DEFAULT_PORT = 23364;
/** Default Multicast group address for listening Advertise messages. */
public static final String DEFAULT_GROUP = "224.0.1.105";
-
+ public static final String DEFAULT_ENCODING = "8859_1";
+
private static final Logger log = Logger.getLogger(AdvertiseListenerImpl.class);
private static final String RFC_822_FMT = "EEE, d MMM yyyy HH:mm:ss Z";
@@ -431,7 +432,7 @@
byte[] data = dp.getData();
- String s = new String(data, 0, dp.getLength(), "8859_1");
+ String s = new String(data, 0, dp.getLength(), DEFAULT_ENCODING);
if (!s.startsWith("HTTP/1."))
{
continue;
16 years, 2 months
JBoss Native SVN: r1970 - trunk/mod_cluster/src/main/resources.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 13:57:09 -0400 (Tue, 21 Oct 2008)
New Revision: 1970
Modified:
trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
Log:
Reorganized configuration, using new metric/source relationships.
Added default metrics/sources.
Added lots of comments.
Modified: trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
===================================================================
--- trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2008-10-21 17:36:11 UTC (rev 1969)
+++ trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2008-10-21 17:57:09 UTC (rev 1970)
@@ -1,299 +1,284 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Beans that provide JBoss AS-side functionality for mod_cluster. These
- beans are all "On Demand", i.e. that are not installed unless requested.
+ Beans that provide JBoss AS-side functionality for mod_cluster. These
+ beans are all "On Demand", i.e. that are not installed unless requested.
-->
<deployment xmlns="urn:jboss:bean-deployer:2.0">
- <!-- Configuration bean -->
- <bean name="ModClusterConfig"
- class="org.jboss.modcluster.config.ModClusterConfig"
- mode="On Demand">
-
- <!-- Configure this node's communication with the load balancer -->
-
- <!-- Comma separated list of address:port listing the httpd servers
- where mod_cluster is running.
- <property name="proxyList"></property>
- -->
- <!--URL prefix to send with commands to mod_cluster. Default is no prefix
- <property name="proxyURL">/bla</property>
- -->
-
- <!-- mod_advertise is a small httpd module that advertises the
- availability of httpd servers via multicast, allowing
- ModClusterService to discover the httpd front-end instead of/in
- addition to having them defined in proxyList.
- -->
- <!-- Whether to listen for advertise messages -->
- <property name="advertise">true</property>
- <!-- Multicast address to listen on for advertisements -->
- <!--property name="advertiseGroupAddress">${jboss.modcluster.advertise.address,jboss.partition.udpGroup:224.0.1.105}</property-->
- <!-- Port to listen to for advertisements -->
- <!--property name="advertisePort">${jboss.modcluster.advertise.address:23364}</property-->
-
- <!-- Key the front-end is going to send with advertise messages.
- Default is no key no check.
- <property name="advertiseSecurityKey"></property>
- -->
-
- <!-- Whether to use SSL to communicate with mod_cluster. Note this
- has nothing to do with handling of https requests by JBoss Web -->
- <property name="ssl">false</property>
-
-
- <!-- Configuration values for the load balancer itself (must be the
- same on all nodes in the cluster). These will be passed to the
- load balancer. -->
- <property name="stickySession">true</property>
- <property name="stickySessionForce">false</property>
- <property name="stickySessionRemove">false</property>
- <property name="maxAttempts">-1</property>
- <property name="workerTimeout">-1</property>
-
- </bean>
-
- <!-- Provides information to ModClusterService informing it how much load
- this server should take. This basic impl just uses a static
- configuration and doesn't adjust it based on runtime conditions. -->
- <bean name="StaticModClusterLoadBalanceFactorProvider"
- class="org.jboss.modcluster.load.impl.StaticLoadBalanceFactorProvider"
- mode="On Demand">
- <property name="loadBalanceFactor">1</property>
- </bean>
-
- <!-- Provides information to ModClusterService informing it how much load
- this server should take. This impl calculates load factor from a
- number of metrics and adjusts the value periodically based on runtime
- conditions. -->
- <bean name="DynamicModClusterLoadBalanceFactorProvider"
- class="org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=LoadBalanceFactorProvider",exposedInterface=org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProviderMBean.class)</annotation>
- <constructor>
- <parameter>
- <collection elementClass="org.jboss.modcluster.load.metric.LoadMetricSource">
- <!-- Define the load metric sources to use in your load balance factor calculation here -->
- <value><inject bean="ThreadPoolLoadMetricSource"/></value>
- <value><inject bean="HeapMemoryUsageLoadMetric"/></value><!-- N.B. This load metric is its own source -->
- </collection>
- </parameter>
- </constructor>
- <!-- The number of historical load values used to determine load factor -->
- <!--property name="history">10</property-->
- <!-- The exponential decay factor for historical load values -->
- <!--property name="decayFactor">2</property-->
- </bean>
+ <!-- Configure this node's communication with the load balancer -->
+ <bean name="ModClusterConfig" class="org.jboss.modcluster.config.ModClusterConfig" mode="On Demand">
+
+ <!-- Comma separated list of address:port listing the httpd servers
+ where mod_cluster is running.
+ <!--property name="proxyList"></property-->
+ <!-- URL prefix to send with commands to mod_cluster. Default is no prefix.
+ <!--property name="proxyURL"></property-->
+
+ <!-- mod_advertise is a small httpd module that advertises the
+ availability of httpd servers via multicast, allowing
+ ModClusterService to discover the httpd front-end instead of/in
+ addition to having them defined in proxyList. -->
+ <!-- Whether to listen for advertise messages -->
+ <property name="advertise">true</property>
+ <!-- Multicast address to listen on for advertisements -->
+ <!--property name="advertiseGroupAddress">${jboss.modcluster.advertise.address,jboss.partition.udpGroup:224.0.1.105}</property-->
+ <!-- Port to listen to for advertisements -->
+ <!--property name="advertisePort">${jboss.modcluster.advertise.address:23364}</property-->
+
+ <!-- Security key the proxy is going to send with advertise messages.
+ Default is none. -->
+ <!--property name="advertiseSecurityKey"></property-->
+
+ <!-- Whether to use SSL to communicate with mod_cluster. Note this
+ has nothing to do with handling of https requests by JBoss Web -->
+ <property name="ssl">false</property>
+
+ <!-- Configuration values for the load balancer itself (must be the
+ same on all nodes in the cluster). These will be passed to the
+ load balancer. -->
+ <property name="stickySession">true</property>
+ <property name="stickySessionForce">false</property>
+ <property name="stickySessionRemove">false</property>
+ <property name="maxAttempts">-1</property>
+ <property name="workerTimeout">-1</property>
+ </bean>
+
+ <!-- Provides information to ModClusterService informing it how much load
+ this server should take. This impl calculates load factor from a
+ number of metrics and adjusts the value periodically based on runtime
+ conditions, using to the JBossWeb engine's backgroundProcessorDelay. -->
+ <bean name="DynamicModClusterLoadBalanceFactorProvider" class="org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=LoadBalanceFactorProvider",exposedInterface=org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProviderMBean.class)</annotation>
+ <constructor>
+ <parameter>
+ <!-- Define the load metric sources to use in your load balance factor calculation here -->
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetricSource">
+ <value><inject bean="ThreadPoolLoadMetricSource"/></value>
+ <value><inject bean="HeapMemoryUsageLoadMetric"/></value>
+ </collection>
+ </parameter>
+ </constructor>
+ <!-- The number of historical load values used to determine load factor -->
+ <!--property name="history">10</property-->
+ <!-- The exponential decay factor for historical load values -->
+ <!--property name="decayFactor">2</property-->
+ </bean>
- <bean name="ThreadPoolLoadMetricSource"
- class="org.jboss.modcluster.load.metric.impl.ThreadPoolLoadMetricSource"
- mode="On Demand">
- <constructor>
- <parameter>
- <!-- Define the load metrics for this source to use in your load balance factor calculation here -->
- <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
- <value><inject bean="BusyConnectorsLoadMetric"/></value>
- </collection>
- </parameter>
- <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
- <!-- Object name pattern for connector thread pools -->
- <!--parameter>jboss.web:type=ThreadPool,*</parameter-->
- </constructor>
- </bean>
- <bean name="BusyConnectorsLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=BusyConnectorsLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!-- The weight determines the significance of this metric with respect to others in the overall load balance factor calculation -->
- <property name="weight">2</property>
- </bean>
- <bean name="HeapMemoryUsageLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.HeapMemoryUsageLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=HeapMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!-- By default, all metrics have a weight of 1 -->
- <!-- A metric with weight of 0 will be ignored -->
- </bean>
+ <!-- Default load metrics/sources -->
+ <!-- Queries all JBossWeb ThreadPool mbeans -->
+ <bean name="ThreadPoolLoadMetricSource" class="org.jboss.modcluster.load.metric.impl.ThreadPoolLoadMetricSource" mode="On Demand">
+ <constructor>
+ <parameter>
+ <!-- Define the load metrics for this source -->
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="BusyConnectorsLoadMetric"/></value>
+ </collection>
+ </parameter>
+ <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
+ <!-- Object name pattern for connector thread pools -->
+ <!--parameter>jboss.web:type=ThreadPool,*</parameter-->
+ </constructor>
+ </bean>
+ <!-- The JBossWeb connector thread pool usage as a ratio of busy threads to max thread pool size -->
+ <!-- Analogous to method=B in mod_jk -->
+ <bean name="BusyConnectorsLoadMetric" class="org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=BusyConnectorsLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!-- The weight determines the significance of this metric with respect
+ to others in the overall load balance factor calculation -->
+ <property name="weight">2</property>
+ </bean>
+
+ <!-- The heap memory usage as a ratio of used heap to max heap size -->
+ <!-- N.B. This load metric is its own source -->
+ <bean name="HeapMemoryUsageLoadMetric" class="org.jboss.modcluster.load.metric.impl.HeapMemoryUsageLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=HeapMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!--property name="weight">1</property-->
+ </bean>
+
+ <!-- The core ModClusterService -->
+ <bean name="ModClusterService" class="org.jboss.modcluster.ModClusterService" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ModCluster",exposedInterface=org.jboss.modcluster.ModClusterServiceMBean.class)</annotation>
+ <constructor>
+ <parameter><inject bean="HAPartition"/></parameter>
+ <parameter><inject bean="ModClusterConfig"/></parameter>
+ <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
+ <parameter><bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"/></parameter>
+ </constructor>
+ </bean>
+
+ <!--
+ An org.apache.catalina.LifecycleListener impl that notifies
+ ModClusterService of events inside JBoss Web (deployments, starts, stops. etc.)
+ -->
+ <bean name="ModClusterLifecycleListener" class="org.jboss.modcluster.BasicClusterListener" mode="On Demand">
+ <constructor>
+ <parameter><inject bean="ModClusterService"/></parameter>
+ </constructor>
+ </bean>
- <!-- Other JBossWeb load metric sources -->
- <bean name="RequestProcessorLoadMetricSource"
- class="org.jboss.modcluster.load.metric.impl.RequestProcessorLoadMetricSource"
- mode="On Demand">
- <constructor>
- <parameter>
- <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
- <value><inject bean="RequestCountLoadMetric"/></value>
- <value><inject bean="ReceiveTrafficLoadMetric"/></value>
- <value><inject bean="SendTrafficLoadMetric"/></value>
- </collection>
- </parameter>
- <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
- <!-- Object name pattern for request processors -->
- <!--parameter>jboss.web:type=GlobalRequestProcessor,*</parameter-->
- </constructor>
- </bean>
- <bean name="SessionLoadMetricSource"
- class="org.jboss.modcluster.load.metric.impl.SessionLoadMetricSource"
- mode="On Demand">
- <constructor>
- <parameter>
- <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
- <value><inject bean="ActiveSessionsLoadMetric"/></value>
- </collection>
- </parameter>
- <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
- <!-- Object name pattern for session managers -->
- <!--parameter>jboss.web:type=Manager,*</parameter-->
- </constructor>
- </bean>
- <bean name="ConnectionPoolLoadMetricSource"
- class="org.jboss.modcluster.load.metric.impl.ConnectionPoolLoadMetricSource"
- mode="On Demand">
- <constructor>
- <parameter>
- <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
- <value><inject bean="ConnectionPoolUsageMetric"/></value>
- </collection>
- </parameter>
- <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
- <!-- Object name pattern for connector thread pools -->
- <!--parameter>jboss.jca:service=ManagedConnectionPool,*</parameter-->
- </constructor>
- </bean>
+ <!-- Alternative load balance factor providers -->
+
+ <!-- Basic impl that returns a static load balance factor -->
+ <bean name="StaticModClusterLoadBalanceFactorProvider" class="org.jboss.modcluster.load.impl.StaticLoadBalanceFactorProvider" mode="On Demand">
+ <property name="loadBalanceFactor">1</property>
+ </bean>
- <!-- Other metrics sources -->
- <bean name="OperatingSystemLoadMetricSource"
- class="org.jboss.modcluster.load.metric.impl.OperatingSystemLoadMetricSource"
- mode="On Demand">
- <constructor>
- <parameter>
- <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
- <value><inject bean="AverageSystemLoadMetric"/></value>
- <value><inject bean="SystemMemoryUsageLoadMetric"/></value>
- </collection>
- </parameter>
- </constructor>
- </bean>
+ <!-- Alternative load metrics, grouped by source -->
+
+ <!-- Uses the platform's OperatingSystemMXBean -->
+ <bean name="OperatingSystemLoadMetricSource" class="org.jboss.modcluster.load.metric.impl.OperatingSystemLoadMetricSource" mode="On Demand">
+ <constructor>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="AverageSystemLoadMetric"/></value>
+ <value><inject bean="SystemMemoryUsageLoadMetric"/></value>
+ </collection>
+ </parameter>
+ </constructor>
+ </bean>
+ <!-- CPU usage -->
+ <!-- Perhaps the best metric for determining system load - but only available on Java 1.6 or later -->
+ <bean name="AverageSystemLoadMetric"
+ class="org.jboss.modcluster.load.metric.impl.AverageSystemLoadMetric"
+ mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=AverageSystemLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ </bean>
+ <!-- The system memory usage as ratio of used memory to total memory size -->
+ <!-- Requires com.sun.management.OperatingSystemMXBean -->
+ <bean name="SystemMemoryUsageLoadMetric"
+ class="org.jboss.modcluster.load.metric.impl.SystemMemoryUsageLoadMetric"
+ mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=SystemMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ </bean>
- <!-- System/JVM metrics -->
- <bean name="AverageSystemLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.AverageSystemLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=AverageSystemLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- </bean>
- <bean name="SystemMemoryUsageLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.SystemMemoryUsageLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=SystemMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- </bean>
- <bean name="HeapMemoryUsageLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.HeapMemoryUsageLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=HeapMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- </bean>
- <bean name="ThreadCountLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.ThreadCountLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ThreadCountLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!-- This metric requires an explicit capacity, e.g. max capacity of 300 threads -->
- <property name="capacity">300</property>
- </bean>
- <bean name="ConnectionPoolUsageMetric"
- class="org.jboss.modcluster.load.metric.impl.ConnectionPoolUsageLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ConnectionPoolUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!--constructor>
- <parameter>InUseConnectionCount</parameter>
- <parameter>MaxSize</parameter>
- </constructor-->
- </bean>
- <!-- Analogous to method=R in mod_jk -->
- <bean name="RequestCountLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.RequestCountLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=RequestCountLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!--constructor>
- <parameter>requestCount</parameter>
- </constructor-->
- <!-- This metric requires an explicit capacity, e.g. maximum capacity of 1000 requests/sec -->
- <property name="capacity">1000</property>
- </bean>
+ <!-- Queries all JBossWeb GlobalRequestProcessor mbeans -->
+ <bean name="RequestProcessorLoadMetricSource" class="org.jboss.modcluster.load.metric.impl.RequestProcessorLoadMetricSource" mode="On Demand">
+ <constructor>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="RequestCountLoadMetric"/></value>
+ <value><inject bean="ReceiveTrafficLoadMetric"/></value>
+ <value><inject bean="SendTrafficLoadMetric"/></value>
+ </collection>
+ </parameter>
+ <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
+ <!-- Object name pattern for request processors -->
+ <!--parameter>jboss.web:type=GlobalRequestProcessor,*</parameter-->
+ </constructor>
+ </bean>
+ <!-- The number of requests/sec processed by the JBossWeb connectors, with respect to the defined capacity -->
+ <!-- Analogous to method=R in mod_jk -->
+ <bean name="RequestCountLoadMetric" class="org.jboss.modcluster.load.metric.impl.RequestCountLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=RequestCountLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!--constructor>
+ <parameter>requestCount</parameter>
+ </constructor-->
+ <!-- This metric requires an explicit capacity, e.g. maximum capacity of 1000 requests/sec -->
+ <property name="capacity">1000</property>
+ </bean>
+ <!-- The incoming traffic received by JBossWeb connectors in KB/sec, with respect to the defined capacity -->
+ <!-- Analogous to method=T in mod_jk -->
+ <bean name="ReceiveTrafficLoadMetric" class="org.jboss.modcluster.load.metric.impl.ReceiveTrafficLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ReceiveTrafficLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!--constructor>
+ <parameter>bytesReceived</parameter>
+ </constructor-->
+ <!-- This metric requires an explicit capacity, e.g. max capacity of 1024 KB/s -->
+ <property name="capacity">1024</property>
+ </bean>
+ <!-- The outgoing traffic sent by JBossWeb connectors in KB/sec, with respect to the defined capacity -->
+ <bean name="SendTrafficLoadMetric" class="org.jboss.modcluster.load.metric.impl.SendTrafficLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=SendTrafficLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!--constructor>
+ <parameter>bytesSent</parameter>
+ </constructor-->
+ <!-- This metric requires an explicit capacity, e.g. max capacity of 512 KB/s -->
+ <property name="capacity">512</property>
+ </bean>
- <!-- Analogous to method=S in mod_jk -->
- <bean name="ActiveSessionsLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.ActiveSessionsLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ActiveSessionsLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!--constructor>
- <parameter>activeSessions</parameter>
- </constructor-->
- <!-- This metric requires an explicit capacity, e.g. max capacity of 1000 active sessions -->
- <property name="capacity">1000</property>
- </bean>
- <!-- Analogous to method=T in mod_jk -->
- <bean name="ReceiveTrafficLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.ReceiveTrafficLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ReceiveTrafficLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!--constructor>
- <parameter>bytesReceived</parameter>
- </constructor-->
- <!-- This metric requires an explicit capacity, e.g. max capacity of 1024 KB/s -->
- <property name="capacity">1024</property>
- </bean>
- <bean name="SendTrafficLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.SendTrafficLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=SendTrafficLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!--constructor>
- <parameter>bytesSent</parameter>
- </constructor-->
- <!-- This metric requires an explicit capacity, e.g. max capacity of 512 KB/s -->
- <property name="capacity">512</property>
- </bean>
+ <!-- Queries all JBossWeb session manager mbeans -->
+ <bean name="SessionLoadMetricSource" class="org.jboss.modcluster.load.metric.impl.SessionLoadMetricSource" mode="On Demand">
+ <constructor>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="ActiveSessionsLoadMetric"/></value>
+ </collection>
+ </parameter>
+ <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
+ <!-- Object name pattern for session managers -->
+ <!--parameter>jboss.web:type=Manager,*</parameter-->
+ </constructor>
+ </bean>
+ <!-- The number of active sessions, with respect to the defined capacity -->
+ <!-- Analogous to method=S in mod_jk -->
+ <bean name="ActiveSessionsLoadMetric" class="org.jboss.modcluster.load.metric.impl.ActiveSessionsLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ActiveSessionsLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!--constructor>
+ <parameter>activeSessions</parameter>
+ </constructor-->
+ <!-- This metric requires an explicit capacity, e.g. max capacity of 1000 active sessions -->
+ <property name="capacity">1000</property>
+ </bean>
- <!-- Analogous to method=B in mod_jk -->
- <bean name="BusyConnectorsLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric"
- mode="On Demand">
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=BusyConnectorsLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <!--constructor>
- <parameter>currentThreadsBusy</parameter>
- <parameter>maxThreads</parameter>
- </constructor-->
- </bean>
-
- <!-- The core ModClusterService -->
- <bean name="ModClusterService"
- class="org.jboss.modcluster.ModClusterService"
- mode="On Demand">
-
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ModCluster",exposedInterface=org.jboss.modcluster.ModClusterServiceMBean.class)</annotation>
-
- <constructor>
- <parameter><inject bean="HAPartition"/></parameter>
- <parameter><inject bean="ModClusterConfig"/></parameter>
- <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
- <parameter><bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"/></parameter>
- </constructor>
-
- </bean>
-
- <!--
- An org.apache.catalina.LifecycleListener impl that notifies
- ModClusterService of events inside JBoss Web (deployments, starts, stops. etc.)
- -->
- <bean name="ModClusterLifecycleListener"
- class="org.jboss.modcluster.BasicClusterListener"
- mode="On Demand">
-
- <constructor>
- <parameter><inject bean="ModClusterService"/></parameter>
- </constructor>
-
- </bean>
+
+ <!-- Queries all JCA connection pools -->
+ <bean name="ConnectionPoolLoadMetricSource" class="org.jboss.modcluster.load.metric.impl.ConnectionPoolLoadMetricSource" mode="On Demand">
+ <constructor>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="ConnectionPoolUsageMetric"/></value>
+ </collection>
+ </parameter>
+ <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
+ <!-- Object name pattern for connector thread pools -->
+ <!--parameter>jboss.jca:service=ManagedConnectionPool,*</parameter-->
+ </constructor>
+ </bean>
+ <!-- Returns the connection pool usage as a ratio of used to max pool size -->
+ <bean name="ConnectionPoolUsageMetric" class="org.jboss.modcluster.load.metric.impl.ConnectionPoolUsageLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ConnectionPoolUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!--constructor>
+ <parameter>InUseConnectionCount</parameter>
+ <parameter>MaxSize</parameter>
+ </constructor-->
+ </bean>
+ <!-- Generic load metrics/sources -->
+
+ <!-- Queries for mbeans matching the specified pattern -->
+ <bean name="MBeanQueryLoadMetricSource" class="org.jboss.modcluster.load.metric.impl.MBeanQueryLoadMetricSource" mode="On Demand">
+ <constructor>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><bean inject="MBeanAttributeLoadMetric"/></value>
+ <value><bean inject="MBeanAttributeRatioLoadMetric"/></value>
+ </collection>
+ </parameter>
+ <parameter><!-- ObjectName pattern --></parameter>
+ <parameter><inject bean="JMXKernel" property="mbeanServer"/></parameter>
+ </constructor>
+ </bean>
+ <!-- Uses the sum of the values of the specified attribute for each
+ mbean matching the query, with respect to a defined capacity. -->
+ <bean name="MBeanAttributeLoadMetric" class="org.jboss.modcluster.load.metric.impl.MBeanAttributeLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=MBeanAttributeLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <constructor>
+ <parameter><!-- mbean attribute --></parameter>
+ </constructor>
+ <property name="capacity">1</property>
+ </bean>
+ <!-- Uses the ratio of the sum of the values of the specified dividend attribute,
+ to the sum of the values of the specified divisor attribute for each mbean
+ matching the query. -->
+ <bean name="MBeanAttributeRatioLoadMetric" class="org.jboss.modcluster.load.metric.impl.MBeanAttributeLoadMetric" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=MBeanAttributeLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <constructor>
+ <parameter><!-- dividend attribute --></parameter>
+ <parameter><!-- divisor attribute --></parameter>
+ </constructor>
+ </bean>
+
</deployment>
\ No newline at end of file
16 years, 2 months
JBoss Native SVN: r1969 - trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 13:36:11 -0400 (Tue, 21 Oct 2008)
New Revision: 1969
Removed:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadCountLoadMetricTestCase.java
Log:
Obsolete
Deleted: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadCountLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadCountLoadMetricTestCase.java 2008-10-21 17:04:25 UTC (rev 1968)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadCountLoadMetricTestCase.java 2008-10-21 17:36:11 UTC (rev 1969)
@@ -1,59 +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;
-
-import java.lang.management.ThreadMXBean;
-
-import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.impl.ThreadCountLoadMetric;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * @author Paul Ferraro
- *
- */
-@SuppressWarnings("boxing")
-public class ThreadCountLoadMetricTestCase
-{
- private ThreadMXBean bean = EasyMock.createStrictMock(ThreadMXBean.class);
-
- private LoadMetric<LoadContext> metric = new ThreadCountLoadMetric(this.bean);
-
- @Test
- public void getLoad() throws Exception
- {
- LoadContext context = EasyMock.createMock(LoadContext.class);
-
- EasyMock.expect(this.bean.getThreadCount()).andReturn(50);
-
- EasyMock.replay(this.bean);
-
- double load = this.metric.getLoad(context);
-
- EasyMock.verify(this.bean);
-
- Assert.assertEquals(50.0, load, 0);
-
- EasyMock.reset(this.bean);
- }
-}
16 years, 2 months
JBoss Native SVN: r1968 - trunk/mod_cluster/native/mod_proxy_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-10-21 13:04:25 -0400 (Tue, 21 Oct 2008)
New Revision: 1968
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Every millisec is too much.
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-10-21 16:07:11 UTC (rev 1967)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-10-21 17:04:25 UTC (rev 1968)
@@ -1159,7 +1159,7 @@
ap_get_module_config(sconf, &proxy_module);
for (;;) {
- apr_sleep(apr_time_make(0, 1000));
+ apr_sleep(apr_time_make(1, 0));
apr_pool_create(&pool, conf->pool);
/* Create new workers if the shared memory changes */
update_workers_node(conf, pool, s);
16 years, 2 months
JBoss Native SVN: r1967 - trunk/mod_cluster/src/main/resources.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 12:07:11 -0400 (Tue, 21 Oct 2008)
New Revision: 1967
Modified:
trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
Log:
Refactored load balance factor, source, metric definitions.
Use BusyConnectorsLoadMetric + HeapMemoryUsageLoadMetric by default.
Modified: trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
===================================================================
--- trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2008-10-21 15:58:07 UTC (rev 1966)
+++ trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2008-10-21 16:07:11 UTC (rev 1967)
@@ -28,9 +28,9 @@
<!-- Whether to listen for advertise messages -->
<property name="advertise">true</property>
<!-- Multicast address to listen on for advertisements -->
- <property name="advertiseGroupAddress">${jboss.modcluster.advertise.address,jboss.partition.udpGroup:224.0.1.105}</property>
+ <!--property name="advertiseGroupAddress">${jboss.modcluster.advertise.address,jboss.partition.udpGroup:224.0.1.105}</property-->
<!-- Port to listen to for advertisements -->
- <property name="advertisePort">${jboss.modcluster.advertise.address:23364}</property>
+ <!--property name="advertisePort">${jboss.modcluster.advertise.address:23364}</property-->
<!-- Key the front-end is going to send with advertise messages.
Default is no key no check.
@@ -70,25 +70,64 @@
class="org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider"
mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=LoadBalanceFactorProvider",exposedInterface=org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProviderMBean.class)</annotation>
+ <constructor>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetricSource">
+ <!-- Define the load metric sources to use in your load balance factor calculation here -->
+ <value><inject bean="ThreadPoolLoadMetricSource"/></value>
+ <value><inject bean="HeapMemoryUsageLoadMetric"/></value><!-- N.B. This load metric is its own source -->
+ </collection>
+ </parameter>
+ </constructor>
+ <!-- The number of historical load values used to determine load factor -->
<!--property name="history">10</property-->
+ <!-- The exponential decay factor for historical load values -->
<!--property name="decayFactor">2</property-->
</bean>
- <!-- Other metrics sources -->
- <bean name="OperatingSystemLoadMetricSource"
- class="org.jboss.modcluster.load.metric.impl.OperatingSystemLoadMetricSource"
+ <bean name="ThreadPoolLoadMetricSource"
+ class="org.jboss.modcluster.load.metric.impl.ThreadPoolLoadMetricSource"
mode="On Demand">
<constructor>
- <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
+ <parameter>
+ <!-- Define the load metrics for this source to use in your load balance factor calculation here -->
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="BusyConnectorsLoadMetric"/></value>
+ </collection>
+ </parameter>
+ <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
+ <!-- Object name pattern for connector thread pools -->
+ <!--parameter>jboss.web:type=ThreadPool,*</parameter-->
</constructor>
</bean>
+ <bean name="BusyConnectorsLoadMetric"
+ class="org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric"
+ mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=BusyConnectorsLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!-- The weight determines the significance of this metric with respect to others in the overall load balance factor calculation -->
+ <property name="weight">2</property>
+ </bean>
+ <bean name="HeapMemoryUsageLoadMetric"
+ class="org.jboss.modcluster.load.metric.impl.HeapMemoryUsageLoadMetric"
+ mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=HeapMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
+ <!-- By default, all metrics have a weight of 1 -->
+ <!-- A metric with weight of 0 will be ignored -->
+ </bean>
- <!-- JBossWeb load metric sources -->
+
+ <!-- Other JBossWeb load metric sources -->
<bean name="RequestProcessorLoadMetricSource"
class="org.jboss.modcluster.load.metric.impl.RequestProcessorLoadMetricSource"
mode="On Demand">
<constructor>
- <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="RequestCountLoadMetric"/></value>
+ <value><inject bean="ReceiveTrafficLoadMetric"/></value>
+ <value><inject bean="SendTrafficLoadMetric"/></value>
+ </collection>
+ </parameter>
<parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
<!-- Object name pattern for request processors -->
<!--parameter>jboss.web:type=GlobalRequestProcessor,*</parameter-->
@@ -98,131 +137,133 @@
class="org.jboss.modcluster.load.metric.impl.SessionLoadMetricSource"
mode="On Demand">
<constructor>
- <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="ActiveSessionsLoadMetric"/></value>
+ </collection>
+ </parameter>
<parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
<!-- Object name pattern for session managers -->
<!--parameter>jboss.web:type=Manager,*</parameter-->
</constructor>
</bean>
- <bean name="ThreadPoolLoadMetricSource"
- class="org.jboss.modcluster.load.metric.impl.ThreadPoolLoadMetricSource"
+ <bean name="ConnectionPoolLoadMetricSource"
+ class="org.jboss.modcluster.load.metric.impl.ConnectionPoolLoadMetricSource"
mode="On Demand">
<constructor>
- <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="ConnectionPoolUsageMetric"/></value>
+ </collection>
+ </parameter>
<parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
<!-- Object name pattern for connector thread pools -->
- <!--parameter>jboss.web:type=ThreadPool,*</parameter-->
+ <!--parameter>jboss.jca:service=ManagedConnectionPool,*</parameter-->
</constructor>
</bean>
- <bean name="ConnectionPoolLoadMetricSource"
- class="org.jboss.modcluster.load.metric.impl.ConnectionPoolLoadMetricSource"
+
+ <!-- Other metrics sources -->
+ <bean name="OperatingSystemLoadMetricSource"
+ class="org.jboss.modcluster.load.metric.impl.OperatingSystemLoadMetricSource"
mode="On Demand">
<constructor>
- <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
- <parameter class="javax.management.MBeanServer"><inject bean="JMXKernel" property="mbeanServer"/></parameter>
- <!-- Object name pattern for connector thread pools -->
- <!--parameter>jboss.jca:service=ManagedConnectionPool,*</parameter-->
+ <parameter>
+ <collection elementClass="org.jboss.modcluster.load.metric.LoadMetric">
+ <value><inject bean="AverageSystemLoadMetric"/></value>
+ <value><inject bean="SystemMemoryUsageLoadMetric"/></value>
+ </collection>
+ </parameter>
</constructor>
</bean>
<!-- System/JVM metrics -->
<bean name="AverageSystemLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.AverageSystemLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.AverageSystemLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=AverageSystemLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="OperatingSystemLoadMetricSource"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <!--property name="capacity">1.0</property-->
</bean>
<bean name="SystemMemoryUsageLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.SystemMemoryUsageLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.SystemMemoryUsageLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=SystemMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="OperatingSystemLoadMetricSource"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <!--property name="capacity">1.0</property-->
</bean>
<bean name="HeapMemoryUsageLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.HeapMemoryUsageLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.HeapMemoryUsageLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=HeapMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <!--property name="capacity">1.0</property-->
</bean>
<bean name="ThreadCountLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.ThreadCountLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.ThreadCountLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ThreadCountLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="DynamicModClusterLoadBalanceFactorProvider"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
+ <!-- This metric requires an explicit capacity, e.g. max capacity of 300 threads -->
<property name="capacity">300</property>
</bean>
<bean name="ConnectionPoolUsageMetric"
- class="org.jboss.modcluster.load.metric.impl.ConnectionPoolUsageLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.ConnectionPoolUsageLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ConnectionPoolUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="ConnectionPoolLoadMetricSource"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <!--property name="capacity">1.0</property-->
+ <!--constructor>
+ <parameter>InUseConnectionCount</parameter>
+ <parameter>MaxSize</parameter>
+ </constructor-->
</bean>
<!-- Analogous to method=R in mod_jk -->
<bean name="RequestCountLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.RequestCountLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.RequestCountLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=RequestCountLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="RequestProcessorLoadMetricSource"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <property name="capacity">1000</property><!-- maximum capacity estimated as 1000 requests/sec -->
+ <!--constructor>
+ <parameter>requestCount</parameter>
+ </constructor-->
+ <!-- This metric requires an explicit capacity, e.g. maximum capacity of 1000 requests/sec -->
+ <property name="capacity">1000</property>
</bean>
<!-- Analogous to method=S in mod_jk -->
<bean name="ActiveSessionsLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.ActiveSessionsLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.ActiveSessionsLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ActiveSessionsLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="SessionLoadMetricSource"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <property name="capacity">1000</property><!-- maximum capacity estimated at 1000 sessions -->
+ <!--constructor>
+ <parameter>activeSessions</parameter>
+ </constructor-->
+ <!-- This metric requires an explicit capacity, e.g. max capacity of 1000 active sessions -->
+ <property name="capacity">1000</property>
</bean>
<!-- Analogous to method=T in mod_jk -->
<bean name="ReceiveTrafficLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.ReceiveTrafficLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.ReceiveTrafficLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ReceiveTrafficLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="RequestProcessorLoadMetricSource"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <property name="capacity">1024</property><!-- maximum capacity estimated at 1024KB/s -->
+ <!--constructor>
+ <parameter>bytesReceived</parameter>
+ </constructor-->
+ <!-- This metric requires an explicit capacity, e.g. max capacity of 1024 KB/s -->
+ <property name="capacity">1024</property>
</bean>
<bean name="SendTrafficLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.SendTrafficLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.SendTrafficLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=SendTrafficLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="RequestProcessorLoadMetricSource"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <property name="capacity">512</property><!-- maximum capacity estimated at 512KB/s -->
+ <!--constructor>
+ <parameter>bytesSent</parameter>
+ </constructor-->
+ <!-- This metric requires an explicit capacity, e.g. max capacity of 512 KB/s -->
+ <property name="capacity">512</property>
</bean>
<!-- Analogous to method=B in mod_jk -->
<bean name="BusyConnectorsLoadMetric"
- class="org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric">
+ class="org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric"
+ mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=BusyConnectorsLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
- <constructor>
- <parameter><inject bean="ThreadPoolLoadMetricSource"/></parameter>
- </constructor>
- <!--property name="weight">0</property-->
- <!--property name="capacity">1.0</property-->
+ <!--constructor>
+ <parameter>currentThreadsBusy</parameter>
+ <parameter>maxThreads</parameter>
+ </constructor-->
</bean>
<!-- The core ModClusterService -->
16 years, 2 months
JBoss Native SVN: r1966 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 11:58:07 -0400 (Tue, 21 Oct 2008)
New Revision: 1966
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetric.java
Log:
Change default weight to 1, since metrics/sources are now explicitly registered with the DynamicLoadBalanceFactorProvider.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetric.java 2008-10-21 15:58:07 UTC (rev 1966)
@@ -32,7 +32,7 @@
*/
public abstract class AbstractLoadMetric<C extends LoadContext> implements LoadMetricMBean<C>
{
- private volatile int weight = 0;
+ private volatile int weight = 1;
private volatile double capacity = 1;
/**
16 years, 2 months
JBoss Native SVN: r1965 - in trunk/mod_cluster/src: main/java/org/jboss/modcluster/load/metric and 3 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 11:20:30 -0400 (Tue, 21 Oct 2008)
New Revision: 1965
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadContext.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanLoadContext.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanLoadMetricSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanQueryLoadContext.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ConnectionPoolLoadMetricSourceTestCase.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/MBeanAttributeRatioLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanLoadContextTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanLoadMetricSourceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanQueryLoadContextTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanQueryLoadMetricSourceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/OperatingSystemLoadMetricSourceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestProcessorLoadMetricSourceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SessionLoadMetricSourceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadPoolLoadMetricSourceTestCase.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricSourceRegistration.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricMBean.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetricSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ActiveSessionsLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AverageSystemLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ConnectionPoolLoadMetricSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ConnectionPoolUsageLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanAttributeLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanAttributeRatioLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanQueryLoadMetricSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java
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/RequestProcessorLoadMetricSource.java
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/SessionLoadMetricSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SingleLoadMetricSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ThreadCountLoadMetric.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/DynamicLoadBalanceFactorProviderTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.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/AverageSystemLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/BusyConnectorsLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ConnectionPoolUsageLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/HeapMemoryUsageLoadMetricTestCase.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
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SystemMemoryUsageLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadCountLoadMetricTestCase.java
Log:
Refactored interaction between metric, source, and provider. The new responsibility of the LoadMetricSource is to create a LoadContext which is passed to each LoadMetric.getLoad(...) for a given source.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -29,35 +29,31 @@
import org.apache.catalina.util.StringManager;
import org.jboss.logging.Logger;
+import org.jboss.modcluster.Constants;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.load.metric.LoadContext;
import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
-import org.jboss.modcluster.Constants;
/**
* {@link LoadBalanceFactorProvider} implementation that periodically aggregates load from a set of {@link LoadMetricSource}s.
*
* @author Paul Ferraro
*/
-public class DynamicLoadBalanceFactorProvider implements LoadBalanceFactorProvider, LoadMetricSourceRegistration, DynamicLoadBalanceFactorProviderMBean
+public class DynamicLoadBalanceFactorProvider implements LoadBalanceFactorProvider, DynamicLoadBalanceFactorProviderMBean
{
private final Logger log = Logger.getLogger(this.getClass());
private final StringManager sm = StringManager.getManager(Constants.Package);
- private final Collection<LoadMetricSource> sources = new ArrayList<LoadMetricSource>();
- private final Map<LoadMetric, List<Double>> loadHistory = new HashMap<LoadMetric, List<Double>>();
+ private final Collection<LoadMetricSource<LoadContext>> sources;
+ private final Map<LoadMetric<LoadContext>, List<Double>> loadHistory = new HashMap<LoadMetric<LoadContext>, List<Double>>();
private volatile int decayFactor = 2;
private volatile int history = 10;
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.MetricRegistration#register(org.jboss.modcluster.load.metric.LoadMetricSource)
- */
- public void add(LoadMetricSource source)
+ public DynamicLoadBalanceFactorProvider(Collection<LoadMetricSource<LoadContext>> sources)
{
- this.sources.add(source);
+ this.sources = sources;
}
/**
@@ -69,14 +65,14 @@
int totalWeight = 0;
double totalWeightedLoad = 0;
- for (LoadMetricSource source: this.sources)
+ for (LoadMetricSource<LoadContext> source: this.sources)
{
- Collection<? extends LoadMetric> metrics = source.getMetrics();
+ Collection<LoadMetric<LoadContext>> metrics = source.getMetrics();
- List<LoadMetric> metricList = new ArrayList<LoadMetric>(metrics.size());
+ List<LoadMetric<LoadContext>> metricList = new ArrayList<LoadMetric<LoadContext>>(metrics.size());
// Prune 0 weights since they will not contribute anything
- for (LoadMetric metric: metrics)
+ for (LoadMetric<LoadContext> metric: metrics)
{
if (metric.getWeight() != 0)
{
@@ -86,16 +82,16 @@
if (!metricList.isEmpty())
{
- source.prepare();
+ LoadContext context = source.createContext();
try
{
- for (LoadMetric metric: metricList)
+ for (LoadMetric<LoadContext> metric: metricList)
{
try
{
// Normalize load with respect to capacity
- List<Double> queue = this.recordLoad(metric, metric.getLoad() / metric.getCapacity());
+ List<Double> queue = this.recordLoad(metric, metric.getLoad(context) / metric.getCapacity());
int weight = metric.getWeight();
@@ -110,7 +106,7 @@
}
finally
{
- source.cleanup();
+ context.close();
}
}
}
@@ -122,7 +118,7 @@
return 100 - Math.max(0, Math.min(load, 100));
}
- private List<Double> recordLoad(LoadMetric metric, double load)
+ private List<Double> recordLoad(LoadMetric<LoadContext> metric, double load)
{
List<Double> queue = this.loadHistory.get(metric);
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadContext.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadContext.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadContext.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface LoadContext
+{
+ public void close();
+}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -25,7 +25,7 @@
* Represents a specific load metric.
* @author Paul Ferraro
*/
-public interface LoadMetric
+public interface LoadMetric<C extends LoadContext>
{
/**
* Returns the "weight" of this metric, i.e. significance of this load metric compared to the other metrics.
@@ -46,5 +46,5 @@
* @return the current load.
* @throws Exception if there was an error fetching this metric.
*/
- double getLoad() throws Exception;
+ double getLoad(C context) throws Exception;
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricMBean.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricMBean.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricMBean.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -26,7 +26,7 @@
* @author Paul Ferraro
*
*/
-public interface LoadMetricMBean extends LoadMetric
+public interface LoadMetricMBean<C extends LoadContext> extends LoadMetric<C>
{
void setWeight(int weight);
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -27,21 +27,16 @@
* A source for obtaining load metrics.
* @author Paul Ferraro
*/
-public interface LoadMetricSource
+public interface LoadMetricSource<C extends LoadContext>
{
/**
* Returns the collection of metrics registered with this source.
* @return the metrics from this source
*/
- Collection<LoadMetric> getMetrics();
+ Collection<LoadMetric<C>> getMetrics();
/**
- * Prepare any resource required to collect load metrics
+ * Prepare any resources required to collect load metrics
*/
- void prepare();
-
- /**
- * Cleanup any resources used to collect load metrics
- */
- void cleanup();
+ C createContext();
}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricSourceRegistration.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricSourceRegistration.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricSourceRegistration.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -1,32 +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;
-
-
-/**
- * @author Paul Ferraro
- *
- */
-public interface LoadMetricSourceRegistration
-{
- void add(LoadMetricSource source);
-}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,6 +21,7 @@
*/
package org.jboss.modcluster.load.metric.impl;
+import org.jboss.modcluster.load.metric.LoadContext;
import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modcluster.load.metric.LoadMetricMBean;
@@ -29,7 +30,7 @@
*
* @author Paul Ferraro
*/
-public abstract class AbstractLoadMetric implements LoadMetricMBean
+public abstract class AbstractLoadMetric<C extends LoadContext> implements LoadMetricMBean<C>
{
private volatile int weight = 0;
private volatile double capacity = 1;
@@ -69,7 +70,7 @@
{
if (capacity <= 0)
{
- throw new IllegalArgumentException("Capacity be greater than zero.");
+ throw new IllegalArgumentException("Capacity must be greater than zero.");
}
this.capacity = capacity;
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AbstractLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -22,55 +22,31 @@
package org.jboss.modcluster.load.metric.impl;
import java.util.Collection;
-import java.util.LinkedList;
+import org.jboss.modcluster.load.metric.LoadContext;
import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
/**
* Abstract {@link LoadMetricSource} that allows a {@link LoadMetric} to register with it.
*
* @author Paul Ferraro
*/
-public abstract class AbstractLoadMetricSource implements LoadMetricSource
+public abstract class AbstractLoadMetricSource<C extends LoadContext> implements LoadMetricSource<C>
{
- private Collection<LoadMetric> metrics = new LinkedList<LoadMetric>();
+ private final Collection<LoadMetric<C>> metrics;
- protected AbstractLoadMetricSource(LoadMetricSourceRegistration registration)
+ protected AbstractLoadMetricSource(Collection<LoadMetric<C>> metrics)
{
- registration.add(this);
+ this.metrics = metrics;
}
- public void add(LoadMetric metric)
- {
- this.metrics.add(metric);
- }
-
/**
* @{inheritDoc}
* @see org.jboss.modcluster.load.metric.LoadMetricSource#getMetrics()
*/
- public Collection<LoadMetric> getMetrics()
+ public Collection<LoadMetric<C>> getMetrics()
{
return this.metrics;
}
-
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.LoadMetricSource#prepare()
- */
- public void prepare()
- {
- // Nothing to open
- }
-
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.LoadMetricSource#cleanup()
- */
- public void cleanup()
- {
- // Nothing to close
- }
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ActiveSessionsLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ActiveSessionsLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ActiveSessionsLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -30,15 +30,15 @@
*/
public class ActiveSessionsLoadMetric extends MBeanAttributeLoadMetric
{
- private static final String DEFAULT_ATTRIBUTE = "activeSessions";
+ public static final String DEFAULT_ATTRIBUTE = "activeSessions";
- public ActiveSessionsLoadMetric(SessionLoadMetricSource source)
+ public ActiveSessionsLoadMetric()
{
- this(source, DEFAULT_ATTRIBUTE);
+ this(DEFAULT_ATTRIBUTE);
}
- public ActiveSessionsLoadMetric(SessionLoadMetricSource source, String attribute)
+ public ActiveSessionsLoadMetric(String attribute)
{
- super(source, attribute);
+ super(attribute);
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AverageSystemLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AverageSystemLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/AverageSystemLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -23,6 +23,7 @@
import java.lang.management.OperatingSystemMXBean;
+import javax.management.AttributeNotFoundException;
import javax.management.JMException;
import org.jboss.logging.Logger;
@@ -33,39 +34,30 @@
*
* @author Paul Ferraro
*/
-public class AverageSystemLoadMetric extends AbstractLoadMetric
+public class AverageSystemLoadMetric extends AbstractLoadMetric<MBeanLoadContext>
{
- private static final String SYSTEM_LOAD_AVERAGE = "SystemLoadAverage";
+ public static final String SYSTEM_LOAD_AVERAGE = "SystemLoadAverage";
- private final OperatingSystemLoadMetricSource source;
- private final Logger log = Logger.getLogger(this.getClass());
+ private Logger logger = Logger.getLogger(this.getClass());
/**
- * Create a new SystemLoadMetric.
- *
- * @param registration
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.metric.LoadMetric#getLoad()
*/
- public AverageSystemLoadMetric(OperatingSystemLoadMetricSource source)
+ public double getLoad(MBeanLoadContext context) throws JMException
{
- this.source = source;
-
- if (this.source.exists(SYSTEM_LOAD_AVERAGE))
+ try
{
- this.source.add(this);
+ return context.getAttribute(SYSTEM_LOAD_AVERAGE, Double.class).doubleValue();
}
- else
+ catch (AttributeNotFoundException e)
{
- this.log.warn(this.getClass().getName() + " discarded. This metric requires the "
- + SYSTEM_LOAD_AVERAGE + " OperatingSystemMXBean attribute found in Java 1.6 or later.");
+ this.logger.warn(this.getClass().getSimpleName() + " requires Java 1.6 or later.");
+
+ // Disable this metric
+ this.setWeight(0);
+
+ return 0;
}
}
-
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.LoadMetric#getLoad()
- */
- public double getLoad() throws JMException
- {
- return this.source.getAttribute(SYSTEM_LOAD_AVERAGE, Double.class).doubleValue();
- }
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -30,11 +30,16 @@
*/
public class BusyConnectorsLoadMetric extends MBeanAttributeRatioLoadMetric
{
- private static final String CURRENT_THREADS_BUSY = "currentThreadsBusy";
- private static final String MAX_THREADS = "maxThreads";
+ public static final String DEFAULT_DIVIDEND_ATTRIBUTE = "currentThreadsBusy";
+ public static final String DEFAULT_DIVISOR_ATTRIBUTE = "maxThreads";
- public BusyConnectorsLoadMetric(ThreadPoolLoadMetricSource source)
+ public BusyConnectorsLoadMetric()
{
- super(source, CURRENT_THREADS_BUSY, MAX_THREADS);
+ super(DEFAULT_DIVIDEND_ATTRIBUTE, DEFAULT_DIVISOR_ATTRIBUTE);
}
+
+ public BusyConnectorsLoadMetric(String currentThreadsBusy, String maxThreads)
+ {
+ super(currentThreadsBusy, maxThreads);
+ }
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ConnectionPoolLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ConnectionPoolLoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ConnectionPoolLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,10 +21,13 @@
*/
package org.jboss.modcluster.load.metric.impl;
+import java.util.Collection;
+
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
+import org.jboss.modcluster.load.metric.LoadMetric;
+import org.jboss.modcluster.load.metric.LoadMetricSource;
/**
* {@link LoadMetricSource} implementation that simplifies generic mbean access to
@@ -32,7 +35,7 @@
*/
public class ConnectionPoolLoadMetricSource extends MBeanQueryLoadMetricSource
{
- private static final String DEFAULT_PATTERN = "jboss.jca:service=ManagedConnectionPool,*";
+ public static final String DEFAULT_PATTERN = "jboss.jca:service=ManagedConnectionPool,*";
/**
* Create a new ConnectionPoolLoadMetricSource.
@@ -41,9 +44,9 @@
* @param server
* @throws MalformedObjectNameException
*/
- public ConnectionPoolLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server) throws MalformedObjectNameException
+ public ConnectionPoolLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, DEFAULT_PATTERN, server);
+ super(metrics, DEFAULT_PATTERN, server);
}
/**
@@ -54,9 +57,9 @@
* @param server
* @throws MalformedObjectNameException
*/
- public ConnectionPoolLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
+ public ConnectionPoolLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, pattern, server);
+ super(metrics, pattern, server);
}
/**
@@ -65,9 +68,9 @@
* @param registration
* @throws MalformedObjectNameException
*/
- public ConnectionPoolLoadMetricSource(LoadMetricSourceRegistration registration) throws MalformedObjectNameException
+ public ConnectionPoolLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics) throws MalformedObjectNameException
{
- super(registration, DEFAULT_PATTERN);
+ super(metrics, DEFAULT_PATTERN);
}
/**
@@ -77,8 +80,8 @@
* @param pattern
* @throws MalformedObjectNameException
*/
- public ConnectionPoolLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+ public ConnectionPoolLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern) throws MalformedObjectNameException
{
- super(registration, pattern);
+ super(metrics, pattern);
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ConnectionPoolUsageLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ConnectionPoolUsageLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ConnectionPoolUsageLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -30,16 +30,16 @@
*/
public class ConnectionPoolUsageLoadMetric extends MBeanAttributeRatioLoadMetric
{
- private static final String DEFAULT_USED_ATTRIBUTE = "InUseConnectionCount";
- private static final String DEFAULT_MAX_ATTRIBUTE = "MaxSize";
+ public static final String DEFAULT_DIVIDEND_ATTRIBUTE = "InUseConnectionCount";
+ public static final String DEFAULT_DIVISOR_ATTRIBUTE = "MaxSize";
- public ConnectionPoolUsageLoadMetric(ConnectionPoolLoadMetricSource source)
+ public ConnectionPoolUsageLoadMetric()
{
- this(source, DEFAULT_USED_ATTRIBUTE, DEFAULT_MAX_ATTRIBUTE);
+ super(DEFAULT_DIVIDEND_ATTRIBUTE, DEFAULT_DIVISOR_ATTRIBUTE);
}
- public ConnectionPoolUsageLoadMetric(ConnectionPoolLoadMetricSource source, String usedAttribute, String maxAttribute)
+ public ConnectionPoolUsageLoadMetric(String usedAttribute, String maxAttribute)
{
- super(source, usedAttribute, maxAttribute);
+ super(usedAttribute, maxAttribute);
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -25,9 +25,9 @@
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
+import org.jboss.modcluster.load.metric.LoadContext;
+import org.jboss.modcluster.load.metric.LoadMetric;
-
/**
* {@link LoadMetric} implementation that returns the heap memory usage ratio.
*
@@ -37,33 +37,21 @@
{
private final MemoryMXBean bean;
- /**
- * Create a new SystemLoadBalanceMetricProvider.
- *
- * @param registration
- */
- public HeapMemoryUsageLoadMetric(LoadMetricSourceRegistration registration)
+ public HeapMemoryUsageLoadMetric()
{
- this(registration, ManagementFactory.getMemoryMXBean());
+ this(ManagementFactory.getMemoryMXBean());
}
-
- /**
- * Create a new SystemLoadBalanceMetricProvider.
- *
- * @param registration
- */
- public HeapMemoryUsageLoadMetric(LoadMetricSourceRegistration registration, MemoryMXBean bean)
+
+ public HeapMemoryUsageLoadMetric(MemoryMXBean bean)
{
- super(registration);
-
this.bean = bean;
}
-
+
/**
* @{inheritDoc}
* @see org.jboss.modcluster.load.metric.LoadMetric#getLoad()
*/
- public double getLoad()
+ public double getLoad(LoadContext context)
{
MemoryUsage usage = this.bean.getHeapMemoryUsage();
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanAttributeLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanAttributeLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanAttributeLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -29,28 +29,24 @@
* Generic {@link LoadMetric} whose load is the aggregated value of an mbean attribute.
* @author Paul Ferraro
*/
-public class MBeanAttributeLoadMetric extends AbstractLoadMetric
+public class MBeanAttributeLoadMetric extends AbstractLoadMetric<MBeanQueryLoadContext>
{
- private final MBeanQueryLoadMetricSource source;
private final String attribute;
- protected MBeanAttributeLoadMetric(MBeanQueryLoadMetricSource source, String attribute)
+ public MBeanAttributeLoadMetric(String attribute)
{
- this.source = source;
this.attribute = attribute;
-
- this.source.add(this);
}
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.LoadMetric#getLoad()
+ * @see org.jboss.modcluster.load.metric.LoadMetric#getLoad(org.jboss.modcluster.load.metric.LoadContext)
*/
- public double getLoad() throws JMException
+ public double getLoad(MBeanQueryLoadContext context) throws JMException
{
double load = 0;
- List<Number> results = this.source.getAttributes(this.attribute, Number.class);
+ List<Number> results = context.getAttributes(this.attribute, Number.class);
for (Number result: results)
{
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanAttributeRatioLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanAttributeRatioLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanAttributeRatioLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -31,30 +31,26 @@
* Generic {@link LoadMetric} whose load is the ratio of 2 aggregated mbean attributes.
* @author Paul Ferraro
*/
-public class MBeanAttributeRatioLoadMetric extends AbstractLoadMetric
+public class MBeanAttributeRatioLoadMetric extends AbstractLoadMetric<MBeanQueryLoadContext>
{
- private final MBeanQueryLoadMetricSource source;
private final String dividendAttribute;
private final String divisorAttribute;
- protected MBeanAttributeRatioLoadMetric(MBeanQueryLoadMetricSource source, String currentAttribute, String maxAttribute)
+ public MBeanAttributeRatioLoadMetric(String currentAttribute, String maxAttribute)
{
- this.source = source;
this.dividendAttribute = currentAttribute;
this.divisorAttribute = maxAttribute;
-
- this.source.add(this);
}
/**
* @{inheritDoc}
* @see org.jboss.modcluster.load.metric.LoadMetric#getLoad()
*/
- public double getLoad() throws JMException
+ public double getLoad(MBeanQueryLoadContext context) throws JMException
{
double dividend = 0;
- List<Number> results = this.source.getAttributes(this.dividendAttribute, Number.class);
+ List<Number> results = context.getAttributes(this.dividendAttribute, Number.class);
for (Number result: results)
{
@@ -63,7 +59,7 @@
double divisor = 0;
- results = this.source.getAttributes(this.divisorAttribute, Number.class);
+ results = context.getAttributes(this.divisorAttribute, Number.class);
for (Number result: results)
{
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanLoadContext.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanLoadContext.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanLoadContext.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,67 @@
+/*
+ * 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 javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.modcluster.load.metric.LoadContext;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class MBeanLoadContext implements LoadContext
+{
+ private final MBeanServer server;
+ private final ObjectName name;
+
+ public MBeanLoadContext(MBeanServer server, ObjectName name)
+ {
+ this.server = server;
+ this.name = name;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.metric.LoadContext#close()
+ */
+ public void close()
+ {
+ // nothing to close
+ }
+
+ /**
+ * Returns the value of the specified attribute, casted to the specified type.
+ *
+ * @param <T> the type of the attribute
+ * @param attribute an attribute name
+ * @param targetClass the type of the attribute
+ * @return the attribute value
+ * @throws JMException
+ */
+ public <T> T getAttribute(String attribute, Class<T> targetClass) throws JMException
+ {
+ return targetClass.cast(this.server.getAttribute(this.name, attribute));
+ }
+}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanLoadMetricSource.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,61 @@
+/*
+ * 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.lang.management.ManagementFactory;
+import java.util.Collection;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.modcluster.load.metric.LoadMetric;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class MBeanLoadMetricSource extends AbstractLoadMetricSource<MBeanLoadContext>
+{
+ private final MBeanLoadContext context;
+
+ public MBeanLoadMetricSource(Collection<LoadMetric<MBeanLoadContext>> metrics, String name) throws MalformedObjectNameException
+ {
+ this(metrics, name, ManagementFactory.getPlatformMBeanServer());
+ }
+
+ public MBeanLoadMetricSource(Collection<LoadMetric<MBeanLoadContext>> metrics, String name, MBeanServer server) throws MalformedObjectNameException
+ {
+ super(metrics);
+
+ this.context = new MBeanLoadContext(server, ObjectName.getInstance(name));
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.metric.LoadMetricSource#createContext()
+ */
+ public MBeanLoadContext createContext()
+ {
+ return this.context;
+ }
+}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanQueryLoadContext.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanQueryLoadContext.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanQueryLoadContext.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,79 @@
+/*
+ * 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.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.modcluster.load.metric.LoadContext;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class MBeanQueryLoadContext implements LoadContext
+{
+ private final MBeanServer server;
+ private final Set<ObjectName> names;
+
+ @SuppressWarnings("unchecked")
+ public MBeanQueryLoadContext(MBeanServer server, ObjectName pattern)
+ {
+ this.server = server;
+ this.names = pattern.isPattern() ? server.queryNames(pattern, null) : Collections.singleton(pattern);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.metric.LoadContext#close()
+ */
+ public void close()
+ {
+ // nothing to close
+ }
+
+ /**
+ * Collects the attribute values for each mbean matching the object name pattern
+ * @param <T> the type of the attribute
+ * @param attribute the mbean attribute name
+ * @param targetClass the type of the attribute
+ * @return a list of attribute values for each mbean
+ * @throws JMException
+ */
+ public <T> List<T> getAttributes(String attribute, Class<T> targetClass) throws JMException
+ {
+ List<T> list = new ArrayList<T>(this.names.size());
+
+ for (ObjectName name: this.names)
+ {
+ list.add(targetClass.cast(this.server.getAttribute(name, attribute)));
+ }
+
+ return list;
+ }
+}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanQueryLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanQueryLoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/MBeanQueryLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -22,91 +22,44 @@
package org.jboss.modcluster.load.metric.impl;
import java.lang.management.ManagementFactory;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
+import java.util.Collection;
-import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
/**
* Abstract {@link LoadMetricSource} that queries the mbean server for the set of beans to be made available to its registered {@link LoadMetric}s.
*
* @author Paul Ferraro
*/
-public abstract class MBeanQueryLoadMetricSource extends AbstractLoadMetricSource
+public class MBeanQueryLoadMetricSource extends AbstractLoadMetricSource<MBeanQueryLoadContext>
{
private final MBeanServer server;
- private final ObjectName pattern;
+ private final ObjectName name;
- private transient Set<ObjectName> objectNames;
-
- protected MBeanQueryLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+ public MBeanQueryLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern) throws MalformedObjectNameException
{
- this(registration, pattern, ManagementFactory.getPlatformMBeanServer());
+ this(metrics, pattern, ManagementFactory.getPlatformMBeanServer());
}
- protected MBeanQueryLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
+ public MBeanQueryLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern, MBeanServer server) throws MalformedObjectNameException
{
- super(registration);
+ super(metrics);
- this.pattern = ObjectName.getInstance(pattern);
this.server = server;
+ this.name = ObjectName.getInstance(pattern);
}
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.impl.AbstractLoadMetricSource#prepare()
+ * @see org.jboss.modcluster.load.metric.LoadMetricSource#createContext()
*/
- @Override
- public void prepare()
+ public MBeanQueryLoadContext createContext()
{
- this.objectNames = this.queryNames();
+ return new MBeanQueryLoadContext(this.server, this.name);
}
-
- @SuppressWarnings("unchecked")
- private Set<ObjectName> queryNames()
- {
- return this.pattern.isPattern() ? this.server.queryNames(this.pattern, null) : Collections.singleton(this.pattern);
- }
-
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.impl.AbstractLoadMetricSource#cleanup()
- */
- @Override
- public void cleanup()
- {
- this.objectNames = null;
- }
-
- /**
- * Collects the attribute values for each mbean matching the object name pattern
- * @param <T> the type of the attribute
- * @param attribute the mbean attribute name
- * @param targetClass the type of the attribute
- * @return a list of attribute values for each mbean
- * @throws JMException
- */
- public <T> List<T> getAttributes(String attribute, Class<T> targetClass) throws JMException
- {
- // In case load was queried via mbean
- Set<ObjectName> names = (this.objectNames != null) ? this.objectNames : this.queryNames();
-
- List<T> list = new ArrayList<T>(names.size());
-
- for (ObjectName name: names)
- {
- list.add(targetClass.cast(this.server.getAttribute(name, attribute)));
- }
-
- return list;
- }
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -22,105 +22,40 @@
package org.jboss.modcluster.load.metric.impl;
import java.lang.management.ManagementFactory;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.Collection;
-import javax.management.JMException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
+import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
/**
* Abstract {@link LoadMetricSource} implementation that simplifies generic access to the {@link java.lang.management.OperatingSystemMXBean}.
*
* @author Paul Ferraro
*/
-public class OperatingSystemLoadMetricSource extends AbstractLoadMetricSource
+public class OperatingSystemLoadMetricSource extends MBeanLoadMetricSource
{
- private final MBeanServer server;
- private final ObjectName name;
-
/**
* Create a new OperatingSystemLoadMetricSource.
*
* @param registration
+ * @throws MalformedObjectNameException
*/
- public OperatingSystemLoadMetricSource(LoadMetricSourceRegistration registration)
+ public OperatingSystemLoadMetricSource(Collection<LoadMetric<MBeanLoadContext>> metrics) throws MalformedObjectNameException
{
- this(registration, ManagementFactory.getPlatformMBeanServer());
+ super(metrics, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
}
/**
* Create a new OperatingSystemLoadMetricSource.
*
* @param registration
+ * @throws MalformedObjectNameException
*/
- public OperatingSystemLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server)
+ public OperatingSystemLoadMetricSource(Collection<LoadMetric<MBeanLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
{
- super(registration);
-
- this.server = server;
-
- try
- {
- this.name = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
- }
- catch (MalformedObjectNameException e)
- {
- // Should never happen for a platform mxbean
- throw new RuntimeException(e);
- }
+ super(metrics, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, server);
}
-
- /**
- * Indicates whether or not all of the specified attributes exist on this mbean
- *
- * @param attributes any number of attributes
- * @return true if all of the specified attributes exist, false otherwise
- */
- public boolean exists(String... attributes)
- {
- Set<String> missingAttributes = new TreeSet<String>();
-
- for (String attribute: attributes)
- {
- missingAttributes.add(attribute);
- }
-
- try
- {
- MBeanInfo info = this.server.getMBeanInfo(this.name);
-
- for (MBeanAttributeInfo attribute: info.getAttributes())
- {
- missingAttributes.remove(attribute.getName());
- }
-
- return missingAttributes.isEmpty();
- }
- catch (JMException e)
- {
- // Should never happen for a platform mxbean
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Returns the value of the specified attribute, casted to the specified type.
- *
- * @param <T> the type of the attribute
- * @param attribute an attribute name
- * @param targetClass the type of the attribute
- * @return the attribute value
- * @throws JMException
- */
- public <T> T getAttribute(String attribute, Class<T> targetClass) throws JMException
- {
- return targetClass.cast(this.server.getAttribute(this.name, attribute));
- }
}
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 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -31,23 +31,27 @@
*/
public class ReceiveTrafficLoadMetric extends MBeanAttributeLoadMetric
{
- private static final String RECEIVE_COUNT = "bytesReceived";
+ public static final String DEFAULT_ATTRIBUTE = "bytesReceived";
private final DeterministicLoadState state = new DeterministicLoadState();
- public ReceiveTrafficLoadMetric(RequestProcessorLoadMetricSource source)
+ public ReceiveTrafficLoadMetric()
{
- super(source, RECEIVE_COUNT);
+ super(DEFAULT_ATTRIBUTE);
}
+ public ReceiveTrafficLoadMetric(String attribute)
+ {
+ super(attribute);
+ }
+
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.impl.MBeanAttributeLoadMetric#getLoad()
+ * @see org.jboss.modcluster.load.metric.impl.MBeanAttributeLoadMetric#getLoad(org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext)
*/
@Override
- public double getLoad() throws JMException
+ public double getLoad(MBeanQueryLoadContext context) throws JMException
{
- // Convert to KB/sec
- return this.state.delta(super.getLoad() / 1000);
+ return this.state.delta(super.getLoad(context) / 1000);
}
}
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 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/RequestCountLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -32,22 +32,27 @@
*/
public class RequestCountLoadMetric extends MBeanAttributeLoadMetric
{
- private static final String REQUEST_COUNT = "requestCount";
+ public static final String DEFAULT_ATTRIBUTE = "requestCount";
private final DeterministicLoadState state = new DeterministicLoadState();
- public RequestCountLoadMetric(RequestProcessorLoadMetricSource source)
+ public RequestCountLoadMetric()
{
- super(source, REQUEST_COUNT);
+ super(DEFAULT_ATTRIBUTE);
}
+ public RequestCountLoadMetric(String attribute)
+ {
+ super(attribute);
+ }
+
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.impl.MBeanAttributeLoadMetric#getLoad()
+ * @see org.jboss.modcluster.load.metric.impl.MBeanAttributeLoadMetric#getLoad(org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext)
*/
@Override
- public double getLoad() throws JMException
+ public double getLoad(MBeanQueryLoadContext context) throws JMException
{
- return this.state.delta(super.getLoad());
+ return this.state.delta(super.getLoad(context));
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,10 +21,13 @@
*/
package org.jboss.modcluster.load.metric.impl;
+import java.util.Collection;
+
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
+import org.jboss.modcluster.load.metric.LoadMetric;
+import org.jboss.modcluster.load.metric.LoadMetricSource;
/**
* {@link LoadMetricSource} implementation that simplifies generic mbean access to
@@ -34,7 +37,7 @@
*/
public class RequestProcessorLoadMetricSource extends MBeanQueryLoadMetricSource
{
- private static final String DEFAULT_PATTERN = "jboss.web:type=GlobalRequestProcessor,*";
+ public static final String DEFAULT_PATTERN = "jboss.web:type=GlobalRequestProcessor,*";
/**
* Create a new GlobalRequestProcessorLoadMetricSource.
@@ -42,9 +45,9 @@
* @param registration
* @throws MalformedObjectNameException
*/
- public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration) throws MalformedObjectNameException
+ public RequestProcessorLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics) throws MalformedObjectNameException
{
- super(registration, DEFAULT_PATTERN);
+ super(metrics, DEFAULT_PATTERN);
}
/**
@@ -54,9 +57,9 @@
* @param pattern
* @throws MalformedObjectNameException
*/
- public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+ public RequestProcessorLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern) throws MalformedObjectNameException
{
- super(registration, pattern);
+ super(metrics, pattern);
}
/**
@@ -66,9 +69,9 @@
* @param server
* @throws MalformedObjectNameException
*/
- public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server) throws MalformedObjectNameException
+ public RequestProcessorLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, DEFAULT_PATTERN, server);
+ super(metrics, DEFAULT_PATTERN, server);
}
/**
@@ -79,8 +82,8 @@
* @param server
* @throws MalformedObjectNameException
*/
- public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
+ public RequestProcessorLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, pattern, server);
+ super(metrics, pattern, server);
}
}
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 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SendTrafficLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -32,23 +32,28 @@
*/
public class SendTrafficLoadMetric extends MBeanAttributeLoadMetric
{
- private static final String SEND_COUNT = "bytesSent";
+ public static final String DEFAULT_ATTRIBUTE = "bytesSent";
private final DeterministicLoadState state = new DeterministicLoadState();
- public SendTrafficLoadMetric(RequestProcessorLoadMetricSource source)
+ public SendTrafficLoadMetric()
{
- super(source, SEND_COUNT);
+ this(DEFAULT_ATTRIBUTE);
}
+ public SendTrafficLoadMetric(String attribute)
+ {
+ super(attribute);
+ }
+
/**
* @{inheritDoc}
* @see org.jboss.modcluster.load.metric.impl.MBeanAttributeLoadMetric#getLoad()
*/
@Override
- public double getLoad() throws JMException
+ public double getLoad(MBeanQueryLoadContext context) throws JMException
{
// Convert to KB/sec
- return this.state.delta(super.getLoad() / 1000);
+ return this.state.delta(super.getLoad(context) / 1000);
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SessionLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SessionLoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SessionLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,10 +21,13 @@
*/
package org.jboss.modcluster.load.metric.impl;
+import java.util.Collection;
+
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
+import org.jboss.modcluster.load.metric.LoadMetric;
+import org.jboss.modcluster.load.metric.LoadMetricSource;
/**
* {@link LoadMetricSource} implementation that simplifies generic mbean access to
@@ -34,7 +37,7 @@
*/
public class SessionLoadMetricSource extends MBeanQueryLoadMetricSource
{
- private static final String DEFAULT_PATTERN = "jboss.web:type=Manager,*";
+ public static final String DEFAULT_PATTERN = "jboss.web:type=Manager,*";
/**
* Create a new SessionLoadMetricSource.
@@ -42,9 +45,9 @@
* @param registration
* @throws MalformedObjectNameException
*/
- public SessionLoadMetricSource(LoadMetricSourceRegistration registration) throws MalformedObjectNameException
+ public SessionLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics) throws MalformedObjectNameException
{
- super(registration, DEFAULT_PATTERN);
+ super(metrics, DEFAULT_PATTERN);
}
/**
@@ -54,9 +57,9 @@
* @param pattern
* @throws MalformedObjectNameException
*/
- public SessionLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+ public SessionLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern) throws MalformedObjectNameException
{
- super(registration, pattern);
+ super(metrics, pattern);
}
/**
@@ -66,9 +69,9 @@
* @param server
* @throws MalformedObjectNameException
*/
- public SessionLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server) throws MalformedObjectNameException
+ public SessionLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, DEFAULT_PATTERN, server);
+ super(metrics, DEFAULT_PATTERN, server);
}
/**
@@ -79,8 +82,8 @@
* @param server
* @throws MalformedObjectNameException
*/
- public SessionLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
+ public SessionLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, pattern, server);
+ super(metrics, pattern, server);
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SingleLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SingleLoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SingleLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -24,48 +24,42 @@
import java.util.Collection;
import java.util.Collections;
+import org.jboss.modcluster.load.metric.LoadContext;
import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
-
/**
* Abstract {@link LoadMetricSource} + {@link LoadMetric} implementation that returns a single metric.
*
* @author Paul Ferraro
*/
-public abstract class SingleLoadMetricSource extends AbstractLoadMetric implements LoadMetricSource
+public abstract class SingleLoadMetricSource extends AbstractLoadMetric<LoadContext> implements LoadMetricSource<LoadContext>
{
- protected SingleLoadMetricSource(LoadMetricSourceRegistration registration)
+ // We don't need to use a load context since there's only one metric in this source
+ private final LoadContext context = new LoadContext()
{
- registration.add(this);
- }
-
+ public void close()
+ {
+ // nothing to close
+ }
+ };
+
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.LoadMetricSource#prepare()
+ * @see org.jboss.modcluster.load.metric.LoadMetricSource#createContext()
*/
- public void prepare()
+ public LoadContext createContext()
{
- // Nothing to prepare
+ return this.context;
}
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.LoadMetricSource#cleanup()
- */
- public void cleanup()
- {
- // Nothing to cleanup
- }
-
- /**
- * @{inheritDoc}
* @see org.jboss.modcluster.load.metric.LoadMetricSource#getMetrics()
*/
- public Collection<LoadMetric> getMetrics()
+ public Collection<LoadMetric<LoadContext>> getMetrics()
{
- // Silly that we need to cast to prevent a compiler error, no?
- return Collections.singleton((LoadMetric) this);
+ // Silly that we need to down cast to prevent a compiler error, no?
+ return Collections.singleton((LoadMetric<LoadContext>) this);
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,58 +21,45 @@
*/
package org.jboss.modcluster.load.metric.impl;
-import java.util.Arrays;
-
+import javax.management.AttributeNotFoundException;
import javax.management.JMException;
import org.jboss.logging.Logger;
import org.jboss.modcluster.load.metric.LoadMetric;
-
/**
* {@link LoadMetric} implementation that uses {@link com.sun.management.OperatingSystemMXBean}
* to determine system memory usage.
*
* @author Paul Ferraro
*/
-public class SystemMemoryUsageLoadMetric extends AbstractLoadMetric
+public class SystemMemoryUsageLoadMetric extends AbstractLoadMetric<MBeanLoadContext>
{
- private static final String FREE_MEMORY = "FreePhysicalMemorySize";
- private static final String TOTAL_MEMORY = "TotalPhysicalMemorySize";
+ public static final String FREE_MEMORY = "FreePhysicalMemorySize";
+ public static final String TOTAL_MEMORY = "TotalPhysicalMemorySize";
- private final OperatingSystemLoadMetricSource source;
- private final Logger log = Logger.getLogger(this.getClass());
-
+ private Logger logger = Logger.getLogger(this.getClass());
+
/**
- * Create a new SystemMemoryUsageLoadMetric.
- *
- * @param registration
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.metric.LoadMetric#getLoad()
*/
- public SystemMemoryUsageLoadMetric(OperatingSystemLoadMetricSource source)
+ public double getLoad(MBeanLoadContext context) throws JMException
{
- this.source = source;
-
- if (this.source.exists(FREE_MEMORY, TOTAL_MEMORY))
+ try
{
- this.source.add(this);
+ double free = context.getAttribute(FREE_MEMORY, Number.class).doubleValue();
+ double total = context.getAttribute(TOTAL_MEMORY, Number.class).doubleValue();
+
+ return free / total;
}
- else
+ catch (AttributeNotFoundException e)
{
- this.log.warn(this.getClass().getName() + " discarded."
- + "This metric requires the following OperatingSystemMXBean attributes: "
- + Arrays.asList(FREE_MEMORY, TOTAL_MEMORY));
+ this.logger.warn(this.getClass().getSimpleName() + " requires com.sun.management.OperatingSystemMXBean.");
+
+ this.setWeight(0);
+
+ return 0;
}
}
-
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.load.metric.LoadMetric#getLoad()
- */
- public double getLoad() throws JMException
- {
- long free = this.source.getAttribute(FREE_MEMORY, Long.class).longValue();
- long total = this.source.getAttribute(TOTAL_MEMORY, Long.class).longValue();
-
- return ((double) free) / total;
- }
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ThreadCountLoadMetric.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ThreadCountLoadMetric.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ThreadCountLoadMetric.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -24,7 +24,7 @@
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
+import org.jboss.modcluster.load.metric.LoadContext;
/**
* @author Paul Ferraro
@@ -33,34 +33,22 @@
public class ThreadCountLoadMetric extends SingleLoadMetricSource
{
private final ThreadMXBean bean;
-
- /**
- * Create a new ThreadCountLoadMetric.
- *
- * @param registration
- */
- public ThreadCountLoadMetric(LoadMetricSourceRegistration registration)
+
+ public ThreadCountLoadMetric()
{
- this(registration, ManagementFactory.getThreadMXBean());
+ this(ManagementFactory.getThreadMXBean());
}
- /**
- * Create a new ThreadCountLoadMetric.
- *
- * @param registration
- */
- public ThreadCountLoadMetric(LoadMetricSourceRegistration registration, ThreadMXBean bean)
+ public ThreadCountLoadMetric(ThreadMXBean bean)
{
- super(registration);
-
this.bean = bean;
}
-
+
/**
* @{inheritDoc}
* @see org.jboss.modcluster.load.metric.LoadMetric#getLoad()
*/
- public double getLoad()
+ public double getLoad(LoadContext context)
{
return this.bean.getThreadCount();
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,10 +21,13 @@
*/
package org.jboss.modcluster.load.metric.impl;
+import java.util.Collection;
+
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
+import org.jboss.modcluster.load.metric.LoadMetric;
+import org.jboss.modcluster.load.metric.LoadMetricSource;
/**
* {@link LoadMetricSource} implementation that simplifies generic mbean access to
@@ -34,7 +37,7 @@
*/
public class ThreadPoolLoadMetricSource extends MBeanQueryLoadMetricSource
{
- private static final String DEFAULT_PATTERN = "jboss.web:type=ThreadPool,*";
+ public static final String DEFAULT_PATTERN = "jboss.web:type=ThreadPool,*";
/**
* Create a new ThreadPoolLoadMetricSource.
@@ -42,9 +45,9 @@
* @param registration
* @throws MalformedObjectNameException
*/
- public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration) throws MalformedObjectNameException
+ public ThreadPoolLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics) throws MalformedObjectNameException
{
- super(registration, DEFAULT_PATTERN);
+ super(metrics, DEFAULT_PATTERN);
}
/**
@@ -54,9 +57,9 @@
* @param patterh
* @throws MalformedObjectNameException
*/
- public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+ public ThreadPoolLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern) throws MalformedObjectNameException
{
- super(registration, pattern);
+ super(metrics, pattern);
}
/**
@@ -66,9 +69,9 @@
* @param server
* @throws MalformedObjectNameException
*/
- public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server) throws MalformedObjectNameException
+ public ThreadPoolLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, DEFAULT_PATTERN, server);
+ super(metrics, DEFAULT_PATTERN, server);
}
/**
@@ -79,8 +82,8 @@
* @param server
* @throws MalformedObjectNameException
*/
- public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
+ public ThreadPoolLoadMetricSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, String pattern, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, pattern, server);
+ super(metrics, pattern, server);
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/DynamicLoadBalanceFactorProviderTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/DynamicLoadBalanceFactorProviderTestCase.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/DynamicLoadBalanceFactorProviderTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -24,135 +24,138 @@
import java.util.Arrays;
import java.util.Collections;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
import org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider;
+import org.jboss.modcluster.load.metric.LoadContext;
import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modcluster.load.metric.LoadMetricSource;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class DynamicLoadBalanceFactorProviderTestCase extends TestCase
+@SuppressWarnings({ "unchecked", "boxing" })
+public class DynamicLoadBalanceFactorProviderTestCase
{
- private final LoadMetricSource source1 = EasyMock.createStrictMock(LoadMetricSource.class);
- private final LoadMetricSource source2 = EasyMock.createStrictMock(LoadMetricSource.class);
- private final LoadMetric metric1 = EasyMock.createStrictMock(LoadMetric.class);
- private final LoadMetric metric2 = EasyMock.createStrictMock(LoadMetric.class);
- private final LoadMetric metric3 = EasyMock.createStrictMock(LoadMetric.class);
+ private final LoadMetricSource<LoadContext> source1 = EasyMock.createStrictMock(LoadMetricSource.class);
+ private final LoadMetricSource<LoadContext> source2 = EasyMock.createStrictMock(LoadMetricSource.class);
- private final DynamicLoadBalanceFactorProvider provider = new DynamicLoadBalanceFactorProvider();
+ private final DynamicLoadBalanceFactorProvider provider = new DynamicLoadBalanceFactorProvider(Arrays.asList(this.source1, this.source2));
/**
* @{inheritDoc}
* @see junit.framework.TestCase#setUp()
*/
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void init() throws Exception
{
- this.provider.add(this.source1);
- this.provider.add(this.source2);
this.provider.setHistory(2);
}
-
- public void testGetLoadBalanceFactor() throws Exception
+ @Test
+ public void getLoadBalanceFactor() throws Exception
{
- EasyMock.expect(this.source1.getMetrics()).andReturn(Arrays.asList(this.metric1, this.metric2));
+ LoadContext context1 = EasyMock.createStrictMock(LoadContext.class);
+ LoadMetric<LoadContext> metric1 = EasyMock.createStrictMock(LoadMetric.class);
+ LoadMetric<LoadContext> metric2 = EasyMock.createStrictMock(LoadMetric.class);
+ LoadMetric<LoadContext> metric3 = EasyMock.createStrictMock(LoadMetric.class);
- EasyMock.expect(this.metric1.getWeight()).andReturn(1);
- EasyMock.expect(this.metric2.getWeight()).andReturn(2);
+ EasyMock.expect(this.source1.getMetrics()).andReturn(Arrays.asList(metric1, metric2));
- this.source1.prepare();
+ EasyMock.expect(metric1.getWeight()).andReturn(1);
+ EasyMock.expect(metric2.getWeight()).andReturn(2);
+
+ EasyMock.expect(this.source1.createContext()).andReturn(context1);
- EasyMock.expect(this.metric1.getLoad()).andReturn(0.2);
- EasyMock.expect(this.metric1.getCapacity()).andReturn(1d);
- EasyMock.expect(this.metric1.getWeight()).andReturn(1);
+ EasyMock.expect(metric1.getLoad(context1)).andReturn(0.2);
+ EasyMock.expect(metric1.getCapacity()).andReturn(1d);
+ EasyMock.expect(metric1.getWeight()).andReturn(1);
- EasyMock.expect(this.metric2.getLoad()).andReturn(400d);
- EasyMock.expect(this.metric2.getCapacity()).andReturn(1000d);
- EasyMock.expect(this.metric2.getWeight()).andReturn(2);
+ EasyMock.expect(metric2.getLoad(context1)).andReturn(400d);
+ EasyMock.expect(metric2.getCapacity()).andReturn(1000d);
+ EasyMock.expect(metric2.getWeight()).andReturn(2);
- this.source1.cleanup();
+ context1.close();
- EasyMock.expect(this.source2.getMetrics()).andReturn(Collections.singleton(this.metric3));
+ EasyMock.expect(this.source2.getMetrics()).andReturn(Collections.singleton(metric3));
- EasyMock.expect(this.metric3.getWeight()).andReturn(0);
+ EasyMock.expect(metric3.getWeight()).andReturn(0);
- EasyMock.replay(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.replay(this.source1, this.source2, context1, metric1, metric2, metric3);
int loadBalanceFactor = this.provider.getLoadBalanceFactor();
- EasyMock.verify(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.verify(this.source1, this.source2, context1, metric1, metric2, metric3);
- assertEquals(67, loadBalanceFactor);
+ Assert.assertEquals(67, loadBalanceFactor);
- EasyMock.reset(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.reset(this.source1, this.source2, context1, metric1, metric2, metric3);
// Test time-decay function
- EasyMock.expect(this.source1.getMetrics()).andReturn(Arrays.asList(this.metric1, this.metric2));
+ EasyMock.expect(this.source1.getMetrics()).andReturn(Arrays.asList(metric1, metric2));
- EasyMock.expect(this.metric1.getWeight()).andReturn(1);
- EasyMock.expect(this.metric2.getWeight()).andReturn(2);
+ EasyMock.expect(metric1.getWeight()).andReturn(1);
+ EasyMock.expect(metric2.getWeight()).andReturn(2);
- this.source1.prepare();
+ EasyMock.expect(this.source1.createContext()).andReturn(context1);
- EasyMock.expect(this.metric1.getLoad()).andReturn(0.4);
- EasyMock.expect(this.metric1.getCapacity()).andReturn(1d);
- EasyMock.expect(this.metric1.getWeight()).andReturn(1);
+ EasyMock.expect(metric1.getLoad(context1)).andReturn(0.4);
+ EasyMock.expect(metric1.getCapacity()).andReturn(1d);
+ EasyMock.expect(metric1.getWeight()).andReturn(1);
- EasyMock.expect(this.metric2.getLoad()).andReturn(600d);
- EasyMock.expect(this.metric2.getCapacity()).andReturn(1000d);
- EasyMock.expect(this.metric2.getWeight()).andReturn(2);
+ EasyMock.expect(metric2.getLoad(context1)).andReturn(600d);
+ EasyMock.expect(metric2.getCapacity()).andReturn(1000d);
+ EasyMock.expect(metric2.getWeight()).andReturn(2);
- this.source1.cleanup();
+ context1.close();
- EasyMock.expect(this.source2.getMetrics()).andReturn(Collections.singleton(this.metric3));
+ EasyMock.expect(this.source2.getMetrics()).andReturn(Collections.singleton(metric3));
- EasyMock.expect(this.metric3.getWeight()).andReturn(0);
+ EasyMock.expect(metric3.getWeight()).andReturn(0);
- EasyMock.replay(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.replay(this.source1, this.source2, context1, metric1, metric2, metric3);
loadBalanceFactor = this.provider.getLoadBalanceFactor();
- EasyMock.verify(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.verify(this.source1, this.source2, context1, metric1, metric2, metric3);
- assertEquals(53, loadBalanceFactor);
+ Assert.assertEquals(53, loadBalanceFactor);
- EasyMock.reset(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.reset(this.source1, this.source2, context1, metric1, metric2, metric3);
//Test decay queue overflow
- EasyMock.expect(this.source1.getMetrics()).andReturn(Arrays.asList(this.metric1, this.metric2));
+ EasyMock.expect(this.source1.getMetrics()).andReturn(Arrays.asList(metric1, metric2));
- EasyMock.expect(this.metric1.getWeight()).andReturn(1);
- EasyMock.expect(this.metric2.getWeight()).andReturn(2);
+ EasyMock.expect(metric1.getWeight()).andReturn(1);
+ EasyMock.expect(metric2.getWeight()).andReturn(2);
- this.source1.prepare();
+ EasyMock.expect(this.source1.createContext()).andReturn(context1);
- EasyMock.expect(this.metric1.getLoad()).andReturn(0.3);
- EasyMock.expect(this.metric1.getCapacity()).andReturn(1d);
- EasyMock.expect(this.metric1.getWeight()).andReturn(1);
+ EasyMock.expect(metric1.getLoad(context1)).andReturn(0.3);
+ EasyMock.expect(metric1.getCapacity()).andReturn(1d);
+ EasyMock.expect(metric1.getWeight()).andReturn(1);
- EasyMock.expect(this.metric2.getLoad()).andReturn(300d);
- EasyMock.expect(this.metric2.getCapacity()).andReturn(1000d);
- EasyMock.expect(this.metric2.getWeight()).andReturn(2);
+ EasyMock.expect(metric2.getLoad(context1)).andReturn(300d);
+ EasyMock.expect(metric2.getCapacity()).andReturn(1000d);
+ EasyMock.expect(metric2.getWeight()).andReturn(2);
- this.source1.cleanup();
+ context1.close();
- EasyMock.expect(this.source2.getMetrics()).andReturn(Collections.singleton(this.metric3));
+ EasyMock.expect(this.source2.getMetrics()).andReturn(Collections.singleton(metric3));
- EasyMock.expect(this.metric3.getWeight()).andReturn(0);
+ EasyMock.expect(metric3.getWeight()).andReturn(0);
- EasyMock.replay(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.replay(this.source1, this.source2, context1, metric1, metric2, metric3);
loadBalanceFactor = this.provider.getLoadBalanceFactor();
- EasyMock.verify(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.verify(this.source1, this.source2, context1, metric1, metric2, metric3);
- assertEquals(62, loadBalanceFactor);
+ Assert.assertEquals(62, loadBalanceFactor);
- EasyMock.reset(this.source1, this.source2, this.metric1, this.metric2, this.metric3);
+ EasyMock.reset(this.source1, this.source2, context1, metric1, metric2, metric3);
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -22,27 +22,28 @@
package org.jboss.modcluster.load;
import org.jboss.modcluster.load.impl.StaticLoadBalanceFactorProvider;
+import org.junit.Assert;
+import org.junit.Test;
-import junit.framework.TestCase;
-
/**
* @author Paul Ferraro
*
*/
-public class StaticLoadBalanceFactorProviderTestCase extends TestCase
+public class StaticLoadBalanceFactorProviderTestCase
{
private StaticLoadBalanceFactorProvider provider = new StaticLoadBalanceFactorProvider();
-
- public void testGetLoadBalanceFactor()
+
+ @Test
+ public void getLoadBalanceFactor()
{
int factor = this.provider.getLoadBalanceFactor();
- assertEquals(1, factor);
+ Assert.assertEquals(1, factor);
this.provider.setLoadBalanceFactor(3);
factor = this.provider.getLoadBalanceFactor();
- assertEquals(3, factor);
+ Assert.assertEquals(3, factor);
}
}
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 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ActiveSessionsLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,113 +21,16 @@
*/
package org.jboss.modcluster.load.metric;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
import org.jboss.modcluster.load.metric.impl.ActiveSessionsLoadMetric;
-import org.jboss.modcluster.load.metric.impl.SessionLoadMetricSource;
/**
* @author Paul Ferraro
*
*/
-public class ActiveSessionsLoadMetricTestCase extends TestCase
+public class ActiveSessionsLoadMetricTestCase extends MBeanAttributeLoadMetricTestCase
{
- private final MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
-
- private LoadMetricSource source;
- private LoadMetric metric;
-
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ public ActiveSessionsLoadMetricTestCase()
{
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
-
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.server);
-
- SessionLoadMetricSource source = new SessionLoadMetricSource(registration, this.server);
-
- EasyMock.verify(registration, this.server);
-
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.server);
-
- this.source = source;
- this.metric = new ActiveSessionsLoadMetric(source);
-
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertSame(this.metric, metrics.iterator().next());
+ super(new ActiveSessionsLoadMetric(), ActiveSessionsLoadMetric.DEFAULT_ATTRIBUTE);
}
-
- public void testGetLoad() throws Exception
- {
- ObjectName pattern = ObjectName.getInstance("jboss.web:type=Manager,*");
- ObjectName name1 = ObjectName.getInstance("jboss.web:type=Manager,path=/app1,host=localhost");
- ObjectName name2 = ObjectName.getInstance("jboss.web:type=Manager,path=/app2,host=localhost");
-
- Comparator<ObjectName> comparator = new Comparator<ObjectName>()
- {
- public int compare(ObjectName name1, ObjectName name2)
- {
- return name1.getCanonicalName().compareTo(name2.getCanonicalName());
- }
- };
-
- Set<ObjectName> names = new TreeSet<ObjectName>(comparator);
- names.addAll(Arrays.asList(name1, name2));
-
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
-
- EasyMock.replay(this.server);
-
- this.source.prepare();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
-
- EasyMock.expect(this.server.getAttribute(name1, "activeSessions")).andReturn(1);
- EasyMock.expect(this.server.getAttribute(name2, "activeSessions")).andReturn(2);
-
- EasyMock.replay(this.server);
-
- double load = this.metric.getLoad();
-
- EasyMock.verify(this.server);
-
- assertEquals(3.0, load);
-
- EasyMock.reset(this.server);
-
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
- }
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/AverageSystemLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/AverageSystemLoadMetricTestCase.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/AverageSystemLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -22,130 +22,66 @@
package org.jboss.modcluster.load.metric;
import java.lang.management.ManagementFactory;
-import java.lang.management.OperatingSystemMXBean;
-import java.util.Collection;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
+import javax.management.AttributeNotFoundException;
import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
import org.jboss.modcluster.load.metric.impl.AverageSystemLoadMetric;
-import org.jboss.modcluster.load.metric.impl.OperatingSystemLoadMetricSource;
+import org.jboss.modcluster.load.metric.impl.MBeanLoadContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class AverageSystemLoadMetricTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class AverageSystemLoadMetricTestCase
{
private final MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
- private LoadMetricSource source;
- private LoadMetric metric;
+ private LoadMetric<MBeanLoadContext> metric = new AverageSystemLoadMetric();
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ private ObjectName name;
+ private MBeanLoadContext context;
+
+ @Before
+ public void prepare() throws MalformedObjectNameException
{
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
+ this.name = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
+ this.context = new MBeanLoadContext(this.server, this.name);
+ }
+
+ @Test
+ public void getLoad() throws Exception
+ {
+ EasyMock.expect(this.server.getAttribute(this.name, AverageSystemLoadMetric.SYSTEM_LOAD_AVERAGE)).andReturn(0.1);
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.server);
-
- OperatingSystemLoadMetricSource source = new OperatingSystemLoadMetricSource(registration, this.server);
-
- EasyMock.verify(registration, this.server);
-
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.server);
-
- this.source = source;
-
- ObjectName name = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
-
- // Test Java 1.5 case
- MBeanInfo info = new MBeanInfo(OperatingSystemMXBean.class.getName(), null, null, null, null, null);
-
- EasyMock.expect(this.server.getMBeanInfo(name)).andReturn(info);
-
EasyMock.replay(this.server);
- this.metric = new AverageSystemLoadMetric(source);
+ double load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
+ Assert.assertEquals(0.1, load, 0.0);
- assertNotNull(metrics);
- assertTrue(metrics.isEmpty());
-
EasyMock.reset(this.server);
- // Test Java 1.6 case
- MBeanAttributeInfo attribute = new MBeanAttributeInfo("SystemLoadAverage", Double.TYPE.getName(), null, true, false, false);
-
- info = new MBeanInfo(OperatingSystemMXBean.class.getName(), "", new MBeanAttributeInfo[] { attribute }, null, null, null);
- EasyMock.expect(this.server.getMBeanInfo(name)).andReturn(info);
+ // Test Java 1.5 behavior
+ EasyMock.expect(this.server.getAttribute(this.name, AverageSystemLoadMetric.SYSTEM_LOAD_AVERAGE)).andThrow(new AttributeNotFoundException());
EasyMock.replay(this.server);
- this.metric = new AverageSystemLoadMetric(source);
+ load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
- metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertSame(this.metric, metrics.iterator().next());
-
- EasyMock.reset(this.server);
+ Assert.assertEquals(0.0, load, 0.0);
+ Assert.assertEquals(0, this.metric.getWeight());
}
-
- public void testGetLoad() throws Exception
- {
- ObjectName name = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
-
- EasyMock.replay(this.server);
-
- this.source.prepare();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
-
- EasyMock.expect(this.server.getAttribute(name, "SystemLoadAverage")).andReturn(0.1);
-
- EasyMock.replay(this.server);
-
- double load = this.metric.getLoad();
-
- EasyMock.verify(this.server);
-
- assertEquals(0.1, load);
-
- EasyMock.reset(this.server);
-
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
- }
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/BusyConnectorsLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/BusyConnectorsLoadMetricTestCase.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/BusyConnectorsLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,116 +21,16 @@
*/
package org.jboss.modcluster.load.metric;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
import org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric;
-import org.jboss.modcluster.load.metric.impl.ThreadPoolLoadMetricSource;
/**
* @author Paul Ferraro
*
*/
-public class BusyConnectorsLoadMetricTestCase extends TestCase
+public class BusyConnectorsLoadMetricTestCase extends MBeanAttributeRatioLoadMetricTestCase
{
- private final MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
-
- private LoadMetricSource source;
- private LoadMetric metric;
-
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ public BusyConnectorsLoadMetricTestCase()
{
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
-
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.server);
-
- ThreadPoolLoadMetricSource source = new ThreadPoolLoadMetricSource(registration, this.server);
-
- EasyMock.verify(registration, this.server);
-
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.server);
-
- this.source = source;
- this.metric = new BusyConnectorsLoadMetric(source);
-
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertEquals(this.metric, metrics.iterator().next());
+ super(new BusyConnectorsLoadMetric(), BusyConnectorsLoadMetric.DEFAULT_DIVIDEND_ATTRIBUTE, BusyConnectorsLoadMetric.DEFAULT_DIVISOR_ATTRIBUTE);
}
-
- public void testGetLoad() throws Exception
- {
- ObjectName pattern = ObjectName.getInstance("jboss.web:type=ThreadPool,*");
- ObjectName name1 = ObjectName.getInstance("jboss.web:type=ThreadPool,name=http-8080");
- ObjectName name2 = ObjectName.getInstance("jboss.web:type=ThreadPool,name=jk-8009");
-
- Comparator<ObjectName> comparator = new Comparator<ObjectName>()
- {
- public int compare(ObjectName name1, ObjectName name2)
- {
- return name1.getCanonicalName().compareTo(name2.getCanonicalName());
- }
- };
-
- Set<ObjectName> names = new TreeSet<ObjectName>(comparator);
- names.addAll(Arrays.asList(name1, name2));
-
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
-
- EasyMock.replay(this.server);
-
- this.source.prepare();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
-
- EasyMock.expect(this.server.getAttribute(name1, "currentThreadsBusy")).andReturn(1);
- EasyMock.expect(this.server.getAttribute(name2, "currentThreadsBusy")).andReturn(2);
-
- EasyMock.expect(this.server.getAttribute(name1, "maxThreads")).andReturn(2);
- EasyMock.expect(this.server.getAttribute(name2, "maxThreads")).andReturn(2);
-
- EasyMock.replay(this.server);
-
- double load = this.metric.getLoad();
-
- EasyMock.verify(this.server);
-
- assertEquals(0.75, load);
-
- EasyMock.reset(this.server);
-
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
- }
}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ConnectionPoolLoadMetricSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ConnectionPoolLoadMetricSourceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ConnectionPoolLoadMetricSourceTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.modcluster.load.metric.impl.ConnectionPoolLoadMetricSource;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadMetricSource;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ConnectionPoolLoadMetricSourceTestCase extends MBeanQueryLoadMetricSourceTestCase
+{
+ public ConnectionPoolLoadMetricSourceTestCase() throws MalformedObjectNameException
+ {
+ super(ConnectionPoolLoadMetricSource.DEFAULT_PATTERN);
+ }
+
+ @Override
+ protected MBeanQueryLoadMetricSource createSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
+ {
+ return new ConnectionPoolLoadMetricSource(metrics, server);
+ }
+}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ConnectionPoolUsageLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ConnectionPoolUsageLoadMetricTestCase.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ConnectionPoolUsageLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,116 +21,17 @@
*/
package org.jboss.modcluster.load.metric;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
-import org.jboss.modcluster.load.metric.impl.ConnectionPoolLoadMetricSource;
import org.jboss.modcluster.load.metric.impl.ConnectionPoolUsageLoadMetric;
+
/**
* @author Paul Ferraro
*
*/
-public class ConnectionPoolUsageLoadMetricTestCase extends TestCase
+public class ConnectionPoolUsageLoadMetricTestCase extends MBeanAttributeRatioLoadMetricTestCase
{
- private final MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
-
- private LoadMetricSource source;
- private LoadMetric metric;
-
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ public ConnectionPoolUsageLoadMetricTestCase()
{
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
-
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.server);
-
- ConnectionPoolLoadMetricSource source = new ConnectionPoolLoadMetricSource(registration, this.server);
-
- EasyMock.verify(registration, this.server);
-
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.server);
-
- this.source = source;
- this.metric = new ConnectionPoolUsageLoadMetric(source);
-
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertEquals(this.metric, metrics.iterator().next());
+ super(new ConnectionPoolUsageLoadMetric(), ConnectionPoolUsageLoadMetric.DEFAULT_DIVIDEND_ATTRIBUTE, ConnectionPoolUsageLoadMetric.DEFAULT_DIVISOR_ATTRIBUTE);
}
-
- public void testGetLoad() throws Exception
- {
- ObjectName pattern = ObjectName.getInstance("jboss.jca:service=ManagedConnectionPool,*");
- ObjectName name1 = ObjectName.getInstance("jboss.jca:service=ManagedConnectionPool,name=DS1");
- ObjectName name2 = ObjectName.getInstance("jboss.jca:service=ManagedConnectionPool,name=DS2");
-
- Comparator<ObjectName> comparator = new Comparator<ObjectName>()
- {
- public int compare(ObjectName name1, ObjectName name2)
- {
- return name1.getCanonicalName().compareTo(name2.getCanonicalName());
- }
- };
-
- Set<ObjectName> names = new TreeSet<ObjectName>(comparator);
- names.addAll(Arrays.asList(name1, name2));
-
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
-
- EasyMock.replay(this.server);
-
- this.source.prepare();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
-
- EasyMock.expect(this.server.getAttribute(name1, "InUseConnectionCount")).andReturn(10);
- EasyMock.expect(this.server.getAttribute(name2, "InUseConnectionCount")).andReturn(20);
-
- EasyMock.expect(this.server.getAttribute(name1, "MaxSize")).andReturn(20);
- EasyMock.expect(this.server.getAttribute(name2, "MaxSize")).andReturn(20);
-
- EasyMock.replay(this.server);
-
- double load = this.metric.getLoad();
-
- EasyMock.verify(this.server);
-
- assertEquals(0.75, load);
-
- EasyMock.reset(this.server);
-
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
- }
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/HeapMemoryUsageLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/HeapMemoryUsageLoadMetricTestCase.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/HeapMemoryUsageLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -23,69 +23,25 @@
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
-import java.util.Collection;
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
import org.jboss.modcluster.load.metric.impl.HeapMemoryUsageLoadMetric;
+import org.junit.Assert;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class HeapMemoryUsageLoadMetricTestCase extends TestCase
+public class HeapMemoryUsageLoadMetricTestCase
{
- private final MemoryMXBean bean = EasyMock.createStrictMock(MemoryMXBean.class);
-
- private LoadMetricSource source;
- private LoadMetric metric;
-
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
- {
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
-
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.bean);
-
- HeapMemoryUsageLoadMetric source = new HeapMemoryUsageLoadMetric(registration, this.bean);
-
- EasyMock.verify(registration, this.bean);
+ private MemoryMXBean bean = EasyMock.createStrictMock(MemoryMXBean.class);
+ private HeapMemoryUsageLoadMetric metric = new HeapMemoryUsageLoadMetric(this.bean);
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.bean);
-
- this.source = source;
- this.metric = source;
-
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertSame(this.metric, metrics.iterator().next());
- }
-
- public void testGetLoad() throws Exception
+ @Test
+ public void getLoad() throws Exception
{
- EasyMock.replay(this.bean);
-
- this.source.prepare();
-
- EasyMock.verify(this.bean);
- EasyMock.reset(this.bean);
+ LoadContext context = EasyMock.createMock(LoadContext.class);
MemoryUsage usage = new MemoryUsage(0, 1000, 2000, 5000);
@@ -93,19 +49,20 @@
EasyMock.replay(this.bean);
- double load = this.metric.getLoad();
+ double load = this.metric.getLoad(context);
EasyMock.verify(this.bean);
- assertEquals(0.2, load);
+ Assert.assertEquals(0.2, load, 0.0);
EasyMock.reset(this.bean);
+ }
+
+ @Test
+ public void createContext()
+ {
+ LoadContext context = this.metric.createContext();
- EasyMock.replay(this.bean);
-
- this.source.cleanup();
-
- EasyMock.verify(this.bean);
- EasyMock.reset(this.bean);
+ Assert.assertNotNull(context);
}
}
Added: 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 (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanAttributeLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,102 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanAttributeLoadMetric;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+@SuppressWarnings("boxing")
+public class MBeanAttributeLoadMetricTestCase
+{
+ MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
+ ObjectName name1;
+ ObjectName name2;
+ MBeanQueryLoadContext context;
+
+ private String attribute;
+ LoadMetric<MBeanQueryLoadContext> metric;
+
+ public MBeanAttributeLoadMetricTestCase()
+ {
+ this("attribute");
+ }
+
+ private MBeanAttributeLoadMetricTestCase(String attribute)
+ {
+ this(new MBeanAttributeLoadMetric(attribute), attribute);
+ }
+
+ protected MBeanAttributeLoadMetricTestCase(LoadMetric<MBeanQueryLoadContext> metric, String attribute)
+ {
+ this.metric = metric;
+ this.attribute = attribute;
+ }
+
+ @Before
+ public void prepare() throws MalformedObjectNameException
+ {
+ ObjectName pattern = ObjectName.getInstance("domain:*");
+ this.name1 = ObjectName.getInstance("domain:name=test1");
+ this.name2 = ObjectName.getInstance("domain:name=test2");
+
+ EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(new LinkedHashSet<ObjectName>(Arrays.asList(this.name1, this.name2)));
+
+ EasyMock.replay(this.server);
+
+ this.context = new MBeanQueryLoadContext(this.server, pattern);
+
+ EasyMock.verify(this.server);
+ EasyMock.reset(this.server);
+ }
+
+ @Test
+ public void getLoad() throws Exception
+ {
+ EasyMock.expect(this.server.getAttribute(this.name1, this.attribute)).andReturn(1);
+ EasyMock.expect(this.server.getAttribute(this.name2, this.attribute)).andReturn(2);
+
+ EasyMock.replay(this.server);
+
+ double load = this.metric.getLoad(this.context);
+
+ EasyMock.verify(this.server);
+
+ Assert.assertEquals(3.0, load, 0.0);
+
+ EasyMock.reset(this.server);
+ }
+}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanAttributeRatioLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanAttributeRatioLoadMetricTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanAttributeRatioLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanAttributeRatioLoadMetric;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+@SuppressWarnings("boxing")
+public class MBeanAttributeRatioLoadMetricTestCase
+{
+ private MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
+ private ObjectName name1;
+ private ObjectName name2;
+ private MBeanQueryLoadContext context;
+
+ private String dividend;
+ private String divisor;
+ private LoadMetric<MBeanQueryLoadContext> metric;
+
+ public MBeanAttributeRatioLoadMetricTestCase()
+ {
+ this("dividend", "divisor");
+ }
+
+ private MBeanAttributeRatioLoadMetricTestCase(String dividend, String divisor)
+ {
+ this(new MBeanAttributeRatioLoadMetric(dividend, divisor), dividend, divisor);
+ }
+
+ protected MBeanAttributeRatioLoadMetricTestCase(LoadMetric<MBeanQueryLoadContext> metric, String dividend, String divisor)
+ {
+ this.metric = metric;
+ this.dividend = dividend;
+ this.divisor = divisor;
+ }
+
+ @Before
+ public void prepare() throws MalformedObjectNameException
+ {
+ ObjectName pattern = ObjectName.getInstance("domain:*");
+ this.name1 = ObjectName.getInstance("domain:name=test1");
+ this.name2 = ObjectName.getInstance("domain:name=test2");
+
+ EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(new LinkedHashSet<ObjectName>(Arrays.asList(this.name1, this.name2)));
+
+ EasyMock.replay(this.server);
+
+ this.context = new MBeanQueryLoadContext(this.server, pattern);
+
+ EasyMock.verify(this.server);
+ EasyMock.reset(this.server);
+ }
+
+ @Test
+ public void getLoad() throws Exception
+ {
+ EasyMock.expect(this.server.getAttribute(this.name1, this.dividend)).andReturn(1);
+ EasyMock.expect(this.server.getAttribute(this.name2, this.dividend)).andReturn(2);
+
+ EasyMock.expect(this.server.getAttribute(this.name1, this.divisor)).andReturn(2);
+ EasyMock.expect(this.server.getAttribute(this.name2, this.divisor)).andReturn(2);
+
+ EasyMock.replay(this.server);
+
+ double load = this.metric.getLoad(this.context);
+
+ EasyMock.verify(this.server);
+
+ Assert.assertEquals(0.75, load, 0.0);
+
+ EasyMock.reset(this.server);
+ }
+}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanLoadContextTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanLoadContextTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanLoadContextTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanLoadContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class MBeanLoadContextTestCase
+{
+ private MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
+ private ObjectName name;
+ private MBeanLoadContext context;
+
+ @Before
+ public void construct() throws MalformedObjectNameException
+ {
+ this.name = ObjectName.getInstance("domain:name=test");
+
+ this.context = new MBeanLoadContext(this.server, this.name);
+ }
+
+ @Test
+ public void getAttribute() throws Exception
+ {
+ String attribute = "attribute";
+ String expected = "value";
+
+ EasyMock.expect(this.server.getAttribute(this.name, attribute)).andReturn(expected);
+
+ EasyMock.replay(this.server);
+
+ String value = this.context.getAttribute(attribute, String.class);
+
+ EasyMock.verify(this.server);
+
+ Assert.assertSame(expected, value);
+
+ EasyMock.reset(this.server);
+ }
+
+ @Test
+ public void close()
+ {
+ EasyMock.replay(this.server);
+
+ this.context.close();
+
+ EasyMock.verify(this.server);
+ EasyMock.reset(this.server);
+ }
+}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanLoadMetricSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanLoadMetricSourceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanLoadMetricSourceTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,94 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+
+import junit.framework.Assert;
+
+import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanLoadContext;
+import org.jboss.modcluster.load.metric.impl.MBeanLoadMetricSource;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+@SuppressWarnings("unchecked")
+public class MBeanLoadMetricSourceTestCase
+{
+ private MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
+ private LoadMetric<MBeanLoadContext> metric1 = EasyMock.createStrictMock(LoadMetric.class);
+ private LoadMetric<MBeanLoadContext> metric2 = EasyMock.createStrictMock(LoadMetric.class);
+
+ private String name;
+ private LoadMetricSource<MBeanLoadContext> source;
+
+ public MBeanLoadMetricSourceTestCase() throws MalformedObjectNameException
+ {
+ this("domain:name=test");
+ }
+
+ protected MBeanLoadMetricSourceTestCase(String name) throws MalformedObjectNameException
+ {
+ this.name = name;
+ this.source = this.createSource(Arrays.asList(this.metric1, this.metric2), this.server);
+ }
+
+ protected MBeanLoadMetricSource createSource(Collection<LoadMetric<MBeanLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
+ {
+ return new MBeanLoadMetricSource(metrics, this.name, server);
+ }
+
+ @Test
+ public void createContext()
+ {
+ EasyMock.replay(this.server);
+
+ MBeanLoadContext context = this.source.createContext();
+
+ EasyMock.verify(this.server);
+
+ Assert.assertNotNull(context);
+
+ EasyMock.reset(this.server);
+ }
+
+ @Test
+ public void getMetrics()
+ {
+ Collection<LoadMetric<MBeanLoadContext>> metrics = this.source.getMetrics();
+
+ Assert.assertEquals(2, metrics.size());
+
+ Iterator<LoadMetric<MBeanLoadContext>> iterator = metrics.iterator();
+
+ Assert.assertSame(this.metric1, iterator.next());
+ Assert.assertSame(this.metric2, iterator.next());
+ }
+}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanQueryLoadContextTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanQueryLoadContextTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanQueryLoadContextTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,131 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class MBeanQueryLoadContextTestCase
+{
+ private MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
+ private ObjectName name1;
+ private ObjectName name2;
+ private MBeanQueryLoadContext context1;
+ private MBeanQueryLoadContext context2;
+
+ @Before
+ public void construct() throws MalformedObjectNameException
+ {
+ this.name1 = ObjectName.getInstance("domain:name=test1");
+ this.name2 = ObjectName.getInstance("domain:name=test2");
+
+ EasyMock.replay(this.server);
+
+ this.context1 = new MBeanQueryLoadContext(this.server, this.name1);
+
+ EasyMock.verify(this.server);
+ EasyMock.reset(this.server);
+
+ ObjectName pattern = ObjectName.getInstance("domain:*");
+
+ EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(new LinkedHashSet<ObjectName>(Arrays.asList(this.name1, this.name2)));
+
+ EasyMock.replay(this.server);
+
+ this.context2 = new MBeanQueryLoadContext(this.server, pattern);
+
+ EasyMock.verify(this.server);
+ EasyMock.reset(this.server);
+ }
+
+ @Test
+ public void getAttributes() throws Exception
+ {
+ String expected = "value";
+
+ EasyMock.expect(this.server.getAttribute(this.name1, "attribute")).andReturn(expected);
+
+ EasyMock.replay(this.server);
+
+ List<String> values = this.context1.getAttributes("attribute", String.class);
+
+ EasyMock.verify(this.server);
+
+ Assert.assertEquals(1, values.size());
+ Assert.assertSame(expected, values.get(0));
+
+ EasyMock.reset(this.server);
+
+
+ String expected1 = "value1";
+ String expected2 = "value2";
+
+ EasyMock.expect(this.server.getAttribute(this.name1, "attribute")).andReturn(expected1);
+ EasyMock.expect(this.server.getAttribute(this.name2, "attribute")).andReturn(expected2);
+
+ EasyMock.replay(this.server);
+
+ values = this.context2.getAttributes("attribute", String.class);
+
+ EasyMock.verify(this.server);
+
+ Assert.assertEquals(2, values.size());
+ Assert.assertSame(expected1, values.get(0));
+ Assert.assertSame(expected2, values.get(1));
+
+ EasyMock.reset(this.server);
+ }
+
+ @Test
+ public void close()
+ {
+ EasyMock.replay(this.server);
+
+ this.context1.close();
+
+ EasyMock.verify(this.server);
+ EasyMock.reset(this.server);
+
+
+ EasyMock.replay(this.server);
+
+ this.context2.close();
+
+ EasyMock.verify(this.server);
+ EasyMock.reset(this.server);
+ }
+}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanQueryLoadMetricSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanQueryLoadMetricSourceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/MBeanQueryLoadMetricSourceTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,104 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.QueryExp;
+
+import junit.framework.Assert;
+
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadMetricSource;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+@SuppressWarnings("unchecked")
+public class MBeanQueryLoadMetricSourceTestCase
+{
+ private MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
+ private LoadMetric<MBeanQueryLoadContext> metric1 = EasyMock.createStrictMock(LoadMetric.class);
+ private LoadMetric<MBeanQueryLoadContext> metric2 = EasyMock.createStrictMock(LoadMetric.class);
+
+ private String pattern;
+ private LoadMetricSource<MBeanQueryLoadContext> source;
+
+ public MBeanQueryLoadMetricSourceTestCase() throws MalformedObjectNameException
+ {
+ this("domain:*");
+ }
+
+ protected MBeanQueryLoadMetricSourceTestCase(String pattern) throws MalformedObjectNameException
+ {
+ this.pattern = pattern;
+ this.source = this.createSource(Arrays.asList(this.metric1, this.metric2), this.server);
+ }
+
+ protected MBeanQueryLoadMetricSource createSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
+ {
+ return new MBeanQueryLoadMetricSource(metrics, this.pattern, server);
+ }
+
+ @Test
+ public void createContext()
+ {
+ Capture<ObjectName> capturedName = new Capture<ObjectName>();
+
+ EasyMock.expect(this.server.queryNames(EasyMock.capture(capturedName), (QueryExp) EasyMock.isNull())).andReturn(Collections.emptySet());
+
+ EasyMock.replay(this.server);
+
+ MBeanQueryLoadContext context = this.source.createContext();
+
+ EasyMock.verify(this.server);
+
+ Assert.assertNotNull(context);
+
+ Assert.assertEquals(this.pattern, capturedName.getValue().toString());
+
+ EasyMock.reset(this.server);
+ }
+
+ @Test
+ public void getMetrics()
+ {
+ Collection<LoadMetric<MBeanQueryLoadContext>> metrics = this.source.getMetrics();
+
+ Assert.assertEquals(2, metrics.size());
+
+ Iterator<LoadMetric<MBeanQueryLoadContext>> iterator = metrics.iterator();
+
+ Assert.assertSame(this.metric1, iterator.next());
+ Assert.assertSame(this.metric2, iterator.next());
+ }
+}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/OperatingSystemLoadMetricSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/OperatingSystemLoadMetricSourceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/OperatingSystemLoadMetricSourceTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import java.lang.management.ManagementFactory;
+import java.util.Collection;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.modcluster.load.metric.impl.MBeanLoadContext;
+import org.jboss.modcluster.load.metric.impl.MBeanLoadMetricSource;
+import org.jboss.modcluster.load.metric.impl.OperatingSystemLoadMetricSource;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class OperatingSystemLoadMetricSourceTestCase extends MBeanLoadMetricSourceTestCase
+{
+ public OperatingSystemLoadMetricSourceTestCase() throws MalformedObjectNameException
+ {
+ super(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.metric.MBeanLoadMetricSourceTestCase#createSource(java.util.Collection, javax.management.MBeanServer)
+ */
+ @Override
+ protected MBeanLoadMetricSource createSource(Collection<LoadMetric<MBeanLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
+ {
+ return new OperatingSystemLoadMetricSource(metrics, server);
+ }
+}
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 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,147 +21,65 @@
*/
package org.jboss.modcluster.load.metric;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
import org.jboss.modcluster.load.metric.impl.ReceiveTrafficLoadMetric;
-import org.jboss.modcluster.load.metric.impl.RequestProcessorLoadMetricSource;
+import org.junit.Assert;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class ReceiveTrafficLoadMetricTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class ReceiveTrafficLoadMetricTestCase extends MBeanAttributeLoadMetricTestCase
{
- private final MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
-
- private LoadMetricSource source;
- private LoadMetric metric;
-
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ public ReceiveTrafficLoadMetricTestCase()
{
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
-
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.server);
-
- RequestProcessorLoadMetricSource source = new RequestProcessorLoadMetricSource(registration, this.server);
-
- EasyMock.verify(registration, this.server);
-
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.server);
-
- this.source = source;
- this.metric = new ReceiveTrafficLoadMetric(source);
-
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertSame(this.metric, metrics.iterator().next());
-
- // Sleep for a sec to prevent infinite load
- Thread.sleep(500);
+ super(new ReceiveTrafficLoadMetric(), ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE);
}
- public void testGetLoad() throws Exception
+ @Test
+ @Override
+ public void getLoad() throws Exception
{
- ObjectName pattern = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,*");
- ObjectName name1 = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,name=http-8080");
- ObjectName name2 = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,name=jk-8009");
+ EasyMock.expect(this.server.getAttribute(this.name1, ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
+ EasyMock.expect(this.server.getAttribute(this.name2, ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
- Comparator<ObjectName> comparator = new Comparator<ObjectName>()
- {
- public int compare(ObjectName name1, ObjectName name2)
- {
- return name1.getCanonicalName().compareTo(name2.getCanonicalName());
- }
- };
+ EasyMock.replay(this.server);
- Set<ObjectName> names = new TreeSet<ObjectName>(comparator);
- names.addAll(Arrays.asList(name1, name2));
+ double load = this.metric.getLoad(this.context);
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
-
- EasyMock.replay(this.server);
-
- this.source.prepare();
-
EasyMock.verify(this.server);
EasyMock.reset(this.server);
- EasyMock.expect(this.server.getAttribute(name1, "bytesReceived")).andReturn(1000L);
- EasyMock.expect(this.server.getAttribute(name2, "bytesReceived")).andReturn(2000L);
+ 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);
- double load = this.metric.getLoad();
+ load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
- assertEquals(6, Math.round(load));
+ Assert.assertEquals(6.0, load, 0.5);
EasyMock.reset(this.server);
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
-
Thread.sleep(500);
- // Test incremental load
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
-
- EasyMock.replay(this.server);
- this.source.prepare();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
+ 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.expect(this.server.getAttribute(name1, "bytesReceived")).andReturn(2000L);
- EasyMock.expect(this.server.getAttribute(name2, "bytesReceived")).andReturn(3000L);
-
EasyMock.replay(this.server);
- load = this.metric.getLoad();
+ load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
- assertEquals(4, Math.round(load));
+ Assert.assertEquals(4.0, load, 0.5);
EasyMock.reset(this.server);
-
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(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 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,148 +21,66 @@
*/
package org.jboss.modcluster.load.metric;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
import org.jboss.modcluster.load.metric.impl.RequestCountLoadMetric;
-import org.jboss.modcluster.load.metric.impl.RequestProcessorLoadMetricSource;
+import org.junit.Assert;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class RequestCountLoadMetricTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class RequestCountLoadMetricTestCase extends MBeanAttributeLoadMetricTestCase
{
- private final MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
-
- private LoadMetricSource source;
- private LoadMetric metric;
-
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ public RequestCountLoadMetricTestCase()
{
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
-
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.server);
-
- RequestProcessorLoadMetricSource source = new RequestProcessorLoadMetricSource(registration, this.server);
-
- EasyMock.verify(registration, this.server);
-
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.server);
-
- this.source = source;
- this.metric = new RequestCountLoadMetric(source);
-
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertSame(this.metric, metrics.iterator().next());
-
- // Sleep for a sec to avoid infinite load.
- Thread.sleep(500);
+ super(new RequestCountLoadMetric(), RequestCountLoadMetric.DEFAULT_ATTRIBUTE);
}
- public void testGetLoad() throws Exception
+ @Test
+ @Override
+ public void getLoad() throws Exception
{
- ObjectName pattern = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,*");
- ObjectName name1 = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,name=http-8080");
- ObjectName name2 = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,name=jk-8009");
+ EasyMock.expect(this.server.getAttribute(this.name1, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
+ EasyMock.expect(this.server.getAttribute(this.name2, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
- Comparator<ObjectName> comparator = new Comparator<ObjectName>()
- {
- public int compare(ObjectName name1, ObjectName name2)
- {
- return name1.getCanonicalName().compareTo(name2.getCanonicalName());
- }
- };
+ EasyMock.replay(this.server);
- Set<ObjectName> names = new TreeSet<ObjectName>(comparator);
- names.addAll(Arrays.asList(name1, name2));
+ double load = this.metric.getLoad(this.context);
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
-
- EasyMock.replay(this.server);
-
- this.source.prepare();
-
EasyMock.verify(this.server);
EasyMock.reset(this.server);
- EasyMock.expect(this.server.getAttribute(name1, "requestCount")).andReturn(1);
- EasyMock.expect(this.server.getAttribute(name2, "requestCount")).andReturn(2);
+ Thread.sleep(500);
+ 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);
- double load = this.metric.getLoad();
+ load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
- assertEquals(6, Math.round(load));
+ Assert.assertEquals(6, load, 0.5);
EasyMock.reset(this.server);
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
-
Thread.sleep(500);
// Test incremental load
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
+ 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);
-
- this.source.prepare();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
- EasyMock.expect(this.server.getAttribute(name1, "requestCount")).andReturn(2);
- EasyMock.expect(this.server.getAttribute(name2, "requestCount")).andReturn(3);
+ load = this.metric.getLoad(this.context);
- EasyMock.replay(this.server);
-
- load = this.metric.getLoad();
-
EasyMock.verify(this.server);
- assertEquals(4, Math.round(load));
+ Assert.assertEquals(4, load, 0.5);
EasyMock.reset(this.server);
-
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
}
}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestProcessorLoadMetricSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestProcessorLoadMetricSourceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestProcessorLoadMetricSourceTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadMetricSource;
+import org.jboss.modcluster.load.metric.impl.RequestProcessorLoadMetricSource;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class RequestProcessorLoadMetricSourceTestCase extends MBeanQueryLoadMetricSourceTestCase
+{
+ public RequestProcessorLoadMetricSourceTestCase() throws MalformedObjectNameException
+ {
+ super(RequestProcessorLoadMetricSource.DEFAULT_PATTERN);
+ }
+
+ @Override
+ protected MBeanQueryLoadMetricSource createSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
+ {
+ return new RequestProcessorLoadMetricSource(metrics, 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 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -21,148 +21,65 @@
*/
package org.jboss.modcluster.load.metric;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
-import org.jboss.modcluster.load.metric.impl.RequestProcessorLoadMetricSource;
import org.jboss.modcluster.load.metric.impl.SendTrafficLoadMetric;
+import org.junit.Assert;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class SendTrafficLoadMetricTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class SendTrafficLoadMetricTestCase extends MBeanAttributeLoadMetricTestCase
{
- private final MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
-
- private LoadMetricSource source;
- private LoadMetric metric;
-
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ public SendTrafficLoadMetricTestCase()
{
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
-
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.server);
-
- RequestProcessorLoadMetricSource source = new RequestProcessorLoadMetricSource(registration, this.server);
-
- EasyMock.verify(registration, this.server);
-
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.server);
-
- this.source = source;
- this.metric = new SendTrafficLoadMetric(source);
-
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertSame(this.metric, metrics.iterator().next());
-
- // Sleep for a bit to avoid infinite load
- Thread.sleep(500);
+ super(new SendTrafficLoadMetric(), SendTrafficLoadMetric.DEFAULT_ATTRIBUTE);
}
- public void testGetLoad() throws Exception
+ @Test
+ @Override
+ public void getLoad() throws Exception
{
- ObjectName pattern = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,*");
- ObjectName name1 = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,name=http-8080");
- ObjectName name2 = ObjectName.getInstance("jboss.web:type=GlobalRequestProcessor,name=jk-8009");
+ EasyMock.expect(this.server.getAttribute(this.name1, SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
+ EasyMock.expect(this.server.getAttribute(this.name2, SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(0);
- Comparator<ObjectName> comparator = new Comparator<ObjectName>()
- {
- public int compare(ObjectName name1, ObjectName name2)
- {
- return name1.getCanonicalName().compareTo(name2.getCanonicalName());
- }
- };
+ EasyMock.replay(this.server);
- Set<ObjectName> names = new TreeSet<ObjectName>(comparator);
- names.addAll(Arrays.asList(name1, name2));
+ double load = this.metric.getLoad(this.context);
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
-
- EasyMock.replay(this.server);
-
- this.source.prepare();
-
EasyMock.verify(this.server);
EasyMock.reset(this.server);
- EasyMock.expect(this.server.getAttribute(name1, "bytesSent")).andReturn(1000L);
- EasyMock.expect(this.server.getAttribute(name2, "bytesSent")).andReturn(2000L);
+ 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);
- double load = this.metric.getLoad();
+ load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
+
+ Assert.assertEquals(6.0, load, 0.5);
- assertEquals(6, Math.round(load));
-
EasyMock.reset(this.server);
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
-
Thread.sleep(500);
-
- // Test incremental load
- EasyMock.expect(this.server.queryNames(pattern, null)).andReturn(names);
-
- EasyMock.replay(this.server);
- this.source.prepare();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
+ 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.expect(this.server.getAttribute(name1, "bytesSent")).andReturn(2000L);
- EasyMock.expect(this.server.getAttribute(name2, "bytesSent")).andReturn(3000L);
-
EasyMock.replay(this.server);
- load = this.metric.getLoad();
+ load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
- assertEquals(4, Math.round(load));
+ Assert.assertEquals(4.0, load, 0.5);
EasyMock.reset(this.server);
-
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
}
}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SessionLoadMetricSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SessionLoadMetricSourceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SessionLoadMetricSourceTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadMetricSource;
+import org.jboss.modcluster.load.metric.impl.SessionLoadMetricSource;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionLoadMetricSourceTestCase extends MBeanQueryLoadMetricSourceTestCase
+{
+ public SessionLoadMetricSourceTestCase() throws MalformedObjectNameException
+ {
+ super(SessionLoadMetricSource.DEFAULT_PATTERN);
+ }
+
+ @Override
+ protected MBeanQueryLoadMetricSource createSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
+ {
+ return new SessionLoadMetricSource(metrics, server);
+ }
+}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SystemMemoryUsageLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SystemMemoryUsageLoadMetricTestCase.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SystemMemoryUsageLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -22,134 +22,67 @@
package org.jboss.modcluster.load.metric;
import java.lang.management.ManagementFactory;
-import java.util.Collection;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
+import javax.management.AttributeNotFoundException;
import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
-import org.jboss.modcluster.load.metric.impl.AverageSystemLoadMetric;
-import org.jboss.modcluster.load.metric.impl.OperatingSystemLoadMetricSource;
+import org.jboss.modcluster.load.metric.impl.MBeanLoadContext;
import org.jboss.modcluster.load.metric.impl.SystemMemoryUsageLoadMetric;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-import com.sun.management.OperatingSystemMXBean;
-
/**
* @author Paul Ferraro
*
*/
-public class SystemMemoryUsageLoadMetricTestCase extends TestCase
+public class SystemMemoryUsageLoadMetricTestCase
{
private final MBeanServer server = EasyMock.createStrictMock(MBeanServer.class);
- private LoadMetricSource source;
- private LoadMetric metric;
+ private LoadMetric<MBeanLoadContext> metric = new SystemMemoryUsageLoadMetric();
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ private ObjectName name;
+ private MBeanLoadContext context;
+
+ @Before
+ public void prepare() throws MalformedObjectNameException
{
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
+ this.name = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
+ this.context = new MBeanLoadContext(this.server, this.name);
+ }
+
+ @SuppressWarnings("boxing")
+ @Test
+ public void getLoad() throws Exception
+ {
+ EasyMock.expect(this.server.getAttribute(this.name, SystemMemoryUsageLoadMetric.FREE_MEMORY)).andReturn(256);
+ EasyMock.expect(this.server.getAttribute(this.name, SystemMemoryUsageLoadMetric.TOTAL_MEMORY)).andReturn(1024L);
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.server);
-
- OperatingSystemLoadMetricSource source = new OperatingSystemLoadMetricSource(registration, this.server);
-
- EasyMock.verify(registration, this.server);
-
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.server);
-
- this.source = source;
-
- ObjectName name = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
-
- // Test non-com.sun.management.OperatingSystemMXBean case
- MBeanInfo info = new MBeanInfo(OperatingSystemMXBean.class.getName(), null, null, null, null, null);
-
- EasyMock.expect(this.server.getMBeanInfo(name)).andReturn(info);
-
EasyMock.replay(this.server);
- this.metric = new AverageSystemLoadMetric(source);
+ double load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertTrue(metrics.isEmpty());
+ Assert.assertEquals(0.25, load, 0.0);
EasyMock.reset(this.server);
-
- // Test com.sun.management.OperatingSystemMXBean case
- MBeanAttributeInfo attribute1 = new MBeanAttributeInfo("FreePhysicalMemorySize", Long.TYPE.getName(), null, true, false, false);
- MBeanAttributeInfo attribute2 = new MBeanAttributeInfo("TotalPhysicalMemorySize", Long.TYPE.getName(), null, true, false, false);
-
- info = new MBeanInfo(OperatingSystemMXBean.class.getName(), "", new MBeanAttributeInfo[] { attribute1, attribute2 }, null, null, null);
-
- EasyMock.expect(this.server.getMBeanInfo(name)).andReturn(info);
-
- EasyMock.replay(this.server);
-
- this.metric = new SystemMemoryUsageLoadMetric(source);
-
- EasyMock.verify(this.server);
-
- metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertSame(this.metric, metrics.iterator().next());
-
- EasyMock.reset(this.server);
- }
- public void testGetLoad() throws Exception
- {
- ObjectName name = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
- EasyMock.replay(this.server);
-
- this.source.prepare();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
+ // Test Java 1.5 behavior
+ EasyMock.expect(this.server.getAttribute(this.name, SystemMemoryUsageLoadMetric.FREE_MEMORY)).andThrow(new AttributeNotFoundException());
- EasyMock.expect(this.server.getAttribute(name, "FreePhysicalMemorySize")).andReturn(1000L);
- EasyMock.expect(this.server.getAttribute(name, "TotalPhysicalMemorySize")).andReturn(5000L);
-
EasyMock.replay(this.server);
- double load = this.metric.getLoad();
+ load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
- assertEquals(0.2, load);
-
- EasyMock.reset(this.server);
-
- EasyMock.replay(this.server);
-
- this.source.cleanup();
-
- EasyMock.verify(this.server);
- EasyMock.reset(this.server);
+ Assert.assertEquals(0.0, load, 0.0);
+ Assert.assertEquals(0, this.metric.getWeight());
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadCountLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadCountLoadMetricTestCase.java 2008-10-20 11:53:50 UTC (rev 1964)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadCountLoadMetricTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -22,87 +22,38 @@
package org.jboss.modcluster.load.metric;
import java.lang.management.ThreadMXBean;
-import java.util.Collection;
-import junit.framework.TestCase;
-
-import org.easymock.Capture;
import org.easymock.EasyMock;
-import org.jboss.modcluster.load.metric.LoadMetric;
-import org.jboss.modcluster.load.metric.LoadMetricSource;
-import org.jboss.modcluster.load.metric.LoadMetricSourceRegistration;
import org.jboss.modcluster.load.metric.impl.ThreadCountLoadMetric;
+import org.junit.Assert;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class ThreadCountLoadMetricTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class ThreadCountLoadMetricTestCase
{
- private final ThreadMXBean bean = EasyMock.createStrictMock(ThreadMXBean.class);
+ private ThreadMXBean bean = EasyMock.createStrictMock(ThreadMXBean.class);
- private LoadMetricSource source;
- private LoadMetric metric;
-
- /**
- * @{inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
- {
- LoadMetricSourceRegistration registration = EasyMock.createStrictMock(LoadMetricSourceRegistration.class);
-
- Capture<LoadMetricSource> captured = new Capture<LoadMetricSource>();
-
- registration.add(EasyMock.capture(captured));
-
- EasyMock.replay(registration, this.bean);
-
- ThreadCountLoadMetric source = new ThreadCountLoadMetric(registration, this.bean);
-
- EasyMock.verify(registration, this.bean);
+ private LoadMetric<LoadContext> metric = new ThreadCountLoadMetric(this.bean);
- assertSame(source, captured.getValue());
-
- EasyMock.reset(registration, this.bean);
-
- this.source = source;
- this.metric = source;
-
- Collection<? extends LoadMetric> metrics = this.source.getMetrics();
-
- assertNotNull(metrics);
- assertEquals(1, metrics.size());
- assertSame(this.metric, metrics.iterator().next());
- }
-
- public void testGetLoad() throws Exception
+ @Test
+ public void getLoad() throws Exception
{
- EasyMock.replay(this.bean);
-
- this.source.prepare();
-
- EasyMock.verify(this.bean);
- EasyMock.reset(this.bean);
+ LoadContext context = EasyMock.createMock(LoadContext.class);
EasyMock.expect(this.bean.getThreadCount()).andReturn(50);
EasyMock.replay(this.bean);
- double load = this.metric.getLoad();
+ double load = this.metric.getLoad(context);
EasyMock.verify(this.bean);
- assertEquals(50.0, load);
+ Assert.assertEquals(50.0, load, 0);
EasyMock.reset(this.bean);
-
- EasyMock.replay(this.bean);
-
- this.source.cleanup();
-
- EasyMock.verify(this.bean);
- EasyMock.reset(this.bean);
}
}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadPoolLoadMetricSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadPoolLoadMetricSourceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ThreadPoolLoadMetricSourceTestCase.java 2008-10-21 15:20:30 UTC (rev 1965)
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadContext;
+import org.jboss.modcluster.load.metric.impl.MBeanQueryLoadMetricSource;
+import org.jboss.modcluster.load.metric.impl.ThreadPoolLoadMetricSource;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ThreadPoolLoadMetricSourceTestCase extends MBeanQueryLoadMetricSourceTestCase
+{
+ public ThreadPoolLoadMetricSourceTestCase() throws MalformedObjectNameException
+ {
+ super(ThreadPoolLoadMetricSource.DEFAULT_PATTERN);
+ }
+
+ @Override
+ protected MBeanQueryLoadMetricSource createSource(Collection<LoadMetric<MBeanQueryLoadContext>> metrics, MBeanServer server) throws MalformedObjectNameException
+ {
+ return new ThreadPoolLoadMetricSource(metrics, server);
+ }
+}
16 years, 2 months