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);
}