JBoss Native SVN: r2208 - trunk/mod_cluster/test/java/org/jboss/mod_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-23 11:51:18 -0500 (Fri, 23 Jan 2009)
New Revision: 2208
Modified:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyForce.java
Log:
Try to use similar ports.
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyForce.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyForce.java 2009-01-23 16:44:17 UTC (rev 2207)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyForce.java 2009-01-23 16:51:18 UTC (rev 2208)
@@ -61,7 +61,7 @@
server.addService(service);
service2 = new JBossWeb("sticky4", "localhost");
- connector2 = service2.addConnector(8888);
+ connector2 = service2.addConnector(8010);
server.addService(service2);
cluster = Maintest.createClusterListener("232.0.0.2", 23364, false);
15 years, 11 months
JBoss Native SVN: r2207 - trunk/mod_cluster/src/main/resources.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2009-01-23 11:44:17 -0500 (Fri, 23 Jan 2009)
New Revision: 2207
Modified:
trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
Log:
Add ROOT to excludedContexts.
Modified: trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
===================================================================
--- trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2009-01-23 16:14:12 UTC (rev 2206)
+++ trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2009-01-23 16:44:17 UTC (rev 2207)
@@ -38,7 +38,7 @@
<!-- List of contexts that should not be auto-registered with httpd delimited by commas. -->
<!-- ROOT indicates the root context. -->
- <property name="excludedContexts">invoker,jbossws,jmx-console,juddi,web-console</property>
+ <property name="excludedContexts">ROOT,invoker,jbossws,jmx-console,juddi,web-console</property>
<!-- Security key the proxy is going to send with advertise messages.
Default is none. -->
@@ -133,7 +133,7 @@
<!-- List of contexts that should not be auto-registered with httpd delimited by commas. -->
<!-- ROOT indicates the root context. -->
- <property name="excludedContexts">invoker,jbossws,jmx-console,juddi,web-console</property>
+ <property name="excludedContexts">ROOT,invoker,jbossws,jmx-console,juddi,web-console</property>
<!-- Security key the proxy is going to send with advertise messages.
Default is none. -->
15 years, 11 months
JBoss Native SVN: r2206 - trunk/mod_cluster/src/main/resources.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2009-01-23 11:14:12 -0500 (Fri, 23 Jan 2009)
New Revision: 2206
Modified:
trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
Log:
Add excludedContexts for ModClusterService too.
Modified: trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
===================================================================
--- trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2009-01-23 16:11:56 UTC (rev 2205)
+++ trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2009-01-23 16:14:12 UTC (rev 2206)
@@ -131,6 +131,10 @@
<!-- Port to listen to for advertisements -->
<property name="advertisePort">${jboss.modcluster.advertise.port:23364}</property>
+ <!-- List of contexts that should not be auto-registered with httpd delimited by commas. -->
+ <!-- ROOT indicates the root context. -->
+ <property name="excludedContexts">invoker,jbossws,jmx-console,juddi,web-console</property>
+
<!-- Security key the proxy is going to send with advertise messages.
Default is none. -->
<!--property name="advertiseSecurityKey"></property-->
15 years, 11 months
JBoss Native SVN: r2205 - in trunk/mod_cluster/src: main/java/org/jboss/modcluster/config and 2 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2009-01-23 11:11:56 -0500 (Fri, 23 Jan 2009)
New Revision: 2205
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/MCMPHandlerConfiguration.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java
trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
Log:
Add excludedContexts config property to enumerate web contexts to exclude from httpd auto-registration.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2009-01-23 11:03:46 UTC (rev 2204)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2009-01-23 16:11:56 UTC (rev 2205)
@@ -24,7 +24,9 @@
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
@@ -51,7 +53,8 @@
*/
public class DefaultJBossWebEventHandler implements JBossWebEventHandler
{
- static Logger log = Logger.getLogger(DefaultJBossWebEventHandler.class);
+ private static final String ROOT_CONTEXT = "ROOT";
+ static final Logger log = Logger.getLogger(DefaultJBossWebEventHandler.class);
// ----------------------------------------------------------------- Fields
@@ -66,7 +69,7 @@
private final MCMPRequestFactory requestFactory;
private final AdvertiseListenerFactory listenerFactory;
private final LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory;
-// private final Set<String> excludedContexts = new HashSet<String>();
+ private final Set<String> excludedContextPaths = new HashSet<String>();
private volatile boolean init;
@@ -92,17 +95,20 @@
{
List<InetSocketAddress> initialProxies = Utils.parseProxies(this.mcmpConfig.getProxyList());
this.mcmpHandler.init(initialProxies);
-/*
+
String contexts = this.mcmpConfig.getExcludedContexts();
- if (contexts != null)
+ if ((contexts != null) && (contexts.length() > 0))
{
for (String context: contexts.split(","))
{
- this.excludedContexts.add(context);
+ String trimmedContext = context.trim();
+ String path = trimmedContext.equals(ROOT_CONTEXT) ? "" : "/" + trimmedContext;
+
+ this.excludedContextPaths.add(path);
}
}
-*/
+
this.loadBalanceFactorProvider = this.loadBalanceFactorProviderFactory.createLoadBalanceFactorProvider();
Boolean advertise = this.mcmpConfig.getAdvertise();
@@ -144,7 +150,7 @@
}
this.mcmpHandler.shutdown();
-// this.excludedContexts.clear();
+ this.excludedContextPaths.clear();
}
/**
@@ -234,8 +240,8 @@
String path = context.getPath();
-// if (!this.excludedContexts.contains(path))
-// {
+ if (!this.excludedContextPaths.contains(path))
+ {
log.debug(this.sm.getString("modcluster.context.enable", path, context.getParent().getName()));
// Send ENABLE-APP if state is started
@@ -245,12 +251,8 @@
this.mcmpHandler.sendRequest(request);
}
-/* }
- else
- {
- log.debug("Exluding context: " + path);
}
-*/ }
+ }
public void startContext(Context context)
{
@@ -258,20 +260,16 @@
String path = context.getPath();
-// if (!this.excludedContexts.contains(path))
-// {
+ if (!this.excludedContextPaths.contains(path))
+ {
log.debug(this.sm.getString("modcluster.context.start", path, context.getParent().getName()));
// Send ENABLE-APP
MCMPRequest request = this.requestFactory.createEnableRequest(context);
this.mcmpHandler.sendRequest(request);
-/* }
- else
- {
- log.debug("Exluding context: " + path);
}
-*/ }
+ }
public void stopContext(Context context)
{
@@ -279,20 +277,16 @@
String path = context.getPath();
-// if (!this.excludedContexts.contains(path))
-// {
+ if (!this.excludedContextPaths.contains(path))
+ {
log.debug(this.sm.getString("modcluster.context.stop", path, context.getParent().getName()));
// Send STOP-APP
MCMPRequest request = this.requestFactory.createStopRequest(context);
this.mcmpHandler.sendRequest(request);
-/* }
- else
- {
- log.debug("Exluding context: " + path);
}
-*/ }
+ }
public void removeContext(Context context)
{
@@ -300,8 +294,8 @@
String path = context.getPath();
-// if (!this.excludedContexts.contains(path))
-// {
+ if (!this.excludedContextPaths.contains(path))
+ {
log.debug(this.sm.getString("modcluster.context.disable", path, context.getParent().getName()));
// JVMRoute can be null here if nothing was ever initialized
@@ -311,12 +305,8 @@
this.mcmpHandler.sendRequest(request);
}
-/* }
- else
- {
- log.debug("Exluding context: " + path);
}
-*/ }
+ }
protected void removeAll(Engine engine)
{
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/MCMPHandlerConfiguration.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/MCMPHandlerConfiguration.java 2009-01-23 11:03:46 UTC (rev 2204)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/MCMPHandlerConfiguration.java 2009-01-23 16:11:56 UTC (rev 2205)
@@ -69,5 +69,7 @@
/**
* Advertise security key.
*/
- String getAdvertiseSecurityKey();
+ String getAdvertiseSecurityKey();
+
+ String getExcludedContexts();
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java 2009-01-23 11:03:46 UTC (rev 2204)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java 2009-01-23 16:11:56 UTC (rev 2205)
@@ -67,6 +67,10 @@
public boolean isSsl() { return this.ssl; }
public void setSsl(boolean ssl) { this.ssl = ssl; }
+ private String excludedContexts = null;
+ public String getExcludedContexts() { return this.excludedContexts; }
+ public void setExcludedContexts(String excludedContexts) { this.excludedContexts = excludedContexts; }
+
// ----------------------------------------------------- SSLConfiguration
private String sslCiphers = null;
Modified: trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
===================================================================
--- trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2009-01-23 11:03:46 UTC (rev 2204)
+++ trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2009-01-23 16:11:56 UTC (rev 2205)
@@ -36,6 +36,10 @@
<!-- Port to listen to for advertisements -->
<property name="advertisePort">${jboss.modcluster.advertise.port:23364}</property>
+ <!-- List of contexts that should not be auto-registered with httpd delimited by commas. -->
+ <!-- ROOT indicates the root context. -->
+ <property name="excludedContexts">invoker,jbossws,jmx-console,juddi,web-console</property>
+
<!-- Security key the proxy is going to send with advertise messages.
Default is none. -->
<!--property name="advertiseSecurityKey"></property-->
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2009-01-23 11:03:46 UTC (rev 2204)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2009-01-23 16:11:56 UTC (rev 2205)
@@ -35,7 +35,6 @@
import org.apache.catalina.Server;
import org.apache.catalina.Service;
import org.apache.catalina.connector.Connector;
-import org.easymock.Capture;
import org.easymock.EasyMock;
import org.jboss.modcluster.advertise.AdvertiseListener;
import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
@@ -47,7 +46,6 @@
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPRequestFactory;
-import org.jboss.modcluster.mcmp.MCMPRequestType;
import org.jboss.modcluster.mcmp.MCMPServerState;
import org.junit.Assert;
import org.junit.Before;
@@ -89,7 +87,7 @@
this.mcmpHandler.init(Collections.singletonList(new InetSocketAddress(localAddress, 8000)));
-// EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn(null);
+ EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn(null);
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
@@ -114,7 +112,7 @@
this.mcmpHandler.init(Collections.singletonList(new InetSocketAddress(localAddress, 8000)));
-// EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("");
+ EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("");
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
@@ -143,7 +141,7 @@
this.mcmpHandler.init(Collections.singletonList(new InetSocketAddress(localAddress, 8000)));
-// EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("/ignored");
+ EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("ignored");
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
@@ -167,7 +165,7 @@
this.mcmpHandler.init(emptyList);
-// EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("/ignored,/");
+ EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("ignored,ROOT");
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
@@ -241,7 +239,7 @@
EasyMock.verify(context);
EasyMock.reset(context);
}
-/*
+
@Test
public void addContextIgnored() throws IOException
{
@@ -258,7 +256,7 @@
EasyMock.verify(context);
EasyMock.reset(context);
}
-*/
+
@Test
public void addContextNotStarted() throws IOException
{
@@ -331,7 +329,7 @@
EasyMock.verify(context);
EasyMock.reset(context);
}
-/*
+
@Test
public void startContextIgnored() throws IOException
{
@@ -349,7 +347,7 @@
EasyMock.verify(context);
EasyMock.reset(context);
}
-*/
+
@Test
public void startContext() throws IOException
{
@@ -397,7 +395,7 @@
EasyMock.verify(context);
EasyMock.reset(context);
}
-/*
+
@Test
public void stopContextIgnored() throws IOException
{
@@ -415,7 +413,7 @@
EasyMock.verify(context);
EasyMock.reset(context);
}
-*/
+
@Test
public void stopContext() throws IOException
{
@@ -463,7 +461,7 @@
EasyMock.verify(context);
EasyMock.reset(context);
}
-/*
+
@Test
public void removeContextIgnored() throws IOException
{
@@ -481,7 +479,7 @@
EasyMock.verify(context);
EasyMock.reset(context);
}
-*/
+
@Test
public void removeContextNoJvmRoute() throws IOException
{
15 years, 11 months
JBoss Native SVN: r2204 - trunk/mod_cluster/test/java.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-23 06:03:46 -0500 (Fri, 23 Jan 2009)
New Revision: 2204
Modified:
trunk/mod_cluster/test/java/build.xml
Log:
Make sure the base.path exists.
Modified: trunk/mod_cluster/test/java/build.xml
===================================================================
--- trunk/mod_cluster/test/java/build.xml 2009-01-22 22:34:01 UTC (rev 2203)
+++ trunk/mod_cluster/test/java/build.xml 2009-01-23 11:03:46 UTC (rev 2204)
@@ -236,6 +236,7 @@
<target name="downloadgz" unless="exist" depends="setproxy,testexist">
<!-- Download and extract the package -->
+ <mkdir dir="${base.path}" />
<get src="${sourcefile}" dest="${base.path}/file.tar.gz" />
<gunzip src="${base.path}/file.tar.gz" dest="${base.path}/file.tar"/>
<untar src="${base.path}/file.tar" dest="${base.path}"/>
15 years, 11 months
JBoss Native SVN: r2203 - in trunk/mod_cluster/src: main/java/org/jboss/modcluster/ha and 6 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2009-01-22 17:34:01 -0500 (Thu, 22 Jan 2009)
New Revision: 2203
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPRequestFactory.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPRequest.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPRequestFactory.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterServiceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/
trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/DefaultMCMPRequestFactoryTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.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/HAModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/AbstractMCMPHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPRequest.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.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
trunk/mod_cluster/src/test/java/org/jboss/modcluster/test/MockProxy.java
Log:
Refactor MCMPUtils into MCMPRequestFactory
Extract interface from MCMPRequest
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -26,12 +26,14 @@
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.ServerFactory;
import org.apache.catalina.Service;
+import org.jboss.modcluster.advertise.impl.AdvertiseListenerFactoryImpl;
import org.jboss.modcluster.config.ModClusterConfig;
import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPUtils;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
+import org.jboss.modcluster.mcmp.impl.DefaultMCMPRequestFactory;
import org.jboss.modcluster.mcmp.impl.ResetRequestSourceImpl;
/**
@@ -43,19 +45,22 @@
{
private final MCMPHandler mcmpHandler;
private final LifecycleListener lifecycleListener;
+ private final MCMPRequestFactory requestFactory;
public AbstractModClusterService()
{
- this.mcmpHandler = new DefaultMCMPHandler(this, new ResetRequestSourceImpl(this, this));
+ this.requestFactory = new DefaultMCMPRequestFactory();
+ this.mcmpHandler = new DefaultMCMPHandler(this, new ResetRequestSourceImpl(this, this, this.requestFactory), this.requestFactory);
- JBossWebEventHandler eventHandler = new DefaultJBossWebEventHandler(this, this, this, this.mcmpHandler, this);
+ JBossWebEventHandler eventHandler = new DefaultJBossWebEventHandler(this, this, this, this.mcmpHandler, this.requestFactory, this, new AdvertiseListenerFactoryImpl());
this.lifecycleListener = new JBossWebEventHandlerAdapter(eventHandler);
}
- protected AbstractModClusterService(MCMPHandler mcmpHandler, LifecycleListener lifecycleListener)
+ protected AbstractModClusterService(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, LifecycleListener lifecycleListener)
{
this.mcmpHandler = mcmpHandler;
+ this.requestFactory = requestFactory;
this.lifecycleListener = lifecycleListener;
}
@@ -133,7 +138,7 @@
{
Engine engine = (Engine) service.getContainer();
// Send DISABLE-APP * request
- MCMPRequest request = MCMPUtils.createDisableEngineRequest(engine);
+ MCMPRequest request = this.requestFactory.createDisableRequest(engine);
this.mcmpHandler.sendRequest(request);
}
@@ -150,7 +155,7 @@
{
Engine engine = (Engine) service.getContainer();
// Send ENABLE-APP * request
- MCMPRequest request = MCMPUtils.createEnableEngineRequest(engine);
+ MCMPRequest request = this.requestFactory.createEnableRequest(engine);
this.mcmpHandler.sendRequest(request);
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -35,7 +35,6 @@
import org.jboss.logging.Logger;
import org.jboss.modcluster.advertise.AdvertiseListener;
import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
-import org.jboss.modcluster.advertise.impl.AdvertiseListenerFactoryImpl;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -43,7 +42,7 @@
import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPUtils;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
/**
* Default implementation of {@link JBossWebEventHandler}.
@@ -64,31 +63,25 @@
private final BalancerConfiguration balancerConfig;
private final MCMPHandlerConfiguration mcmpConfig;
private final MCMPHandler mcmpHandler;
+ private final MCMPRequestFactory requestFactory;
private final AdvertiseListenerFactory listenerFactory;
private final LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory;
+// private final Set<String> excludedContexts = new HashSet<String>();
- private LoadBalanceFactorProvider loadBalanceFactorProvider;
-
private volatile boolean init;
+ private LoadBalanceFactorProvider loadBalanceFactorProvider;
private AdvertiseListener advertiseListener;
-
- // ----------------------------------------------------------- Constructors
-
+
public DefaultJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory)
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory,
+ LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory, AdvertiseListenerFactory listenerFactory)
{
- this(nodeConfig, balancerConfig, mcmpConfig, mcmpHandler, loadBalanceFactorProviderFactory, new AdvertiseListenerFactoryImpl());
- }
-
- protected DefaultJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory,
- AdvertiseListenerFactory listenerFactory)
- {
this.nodeConfig = nodeConfig;
this.balancerConfig = balancerConfig;
this.mcmpConfig = mcmpConfig;
this.mcmpHandler = mcmpHandler;
+ this.requestFactory = requestFactory;
this.loadBalanceFactorProviderFactory = loadBalanceFactorProviderFactory;
this.listenerFactory = listenerFactory;
}
@@ -97,9 +90,19 @@
public synchronized void init()
{
- List<InetSocketAddress> initialProxies = MCMPUtils.parseProxies(this.mcmpConfig.getProxyList());
+ List<InetSocketAddress> initialProxies = Utils.parseProxies(this.mcmpConfig.getProxyList());
this.mcmpHandler.init(initialProxies);
+/*
+ String contexts = this.mcmpConfig.getExcludedContexts();
+ if (contexts != null)
+ {
+ for (String context: contexts.split(","))
+ {
+ this.excludedContexts.add(context);
+ }
+ }
+*/
this.loadBalanceFactorProvider = this.loadBalanceFactorProviderFactory.createLoadBalanceFactorProvider();
Boolean advertise = this.mcmpConfig.getAdvertise();
@@ -141,6 +144,7 @@
}
this.mcmpHandler.shutdown();
+// this.excludedContexts.clear();
}
/**
@@ -207,7 +211,8 @@
this.jvmRouteEstablished(engine);
- MCMPRequest request = MCMPUtils.createConfigRequest(engine, this.nodeConfig, this.balancerConfig);
+ MCMPRequest request = this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig);
+
this.mcmpHandler.sendRequest(request);
}
catch (Exception e)
@@ -227,51 +232,91 @@
{
this.checkInit();
- log.debug(this.sm.getString("modcluster.context.enable", context.getPath(), context.getParent().getName()));
+ String path = context.getPath();
+
+// if (!this.excludedContexts.contains(path))
+// {
+ log.debug(this.sm.getString("modcluster.context.enable", path, context.getParent().getName()));
- // Send ENABLE-APP if state is started
- if (Utils.isContextStarted(context))
+ // Send ENABLE-APP if state is started
+ if (Utils.isContextStarted(context))
+ {
+ MCMPRequest request = this.requestFactory.createEnableRequest(context);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+/* }
+ else
{
- MCMPRequest request = MCMPUtils.createEnableAppRequest(context);
- this.mcmpHandler.sendRequest(request);
+ log.debug("Exluding context: " + path);
}
- }
+*/ }
public void startContext(Context context)
{
this.checkInit();
- log.debug(this.sm.getString("modcluster.context.start", context.getPath(), context.getParent().getName()));
+ String path = context.getPath();
+
+// if (!this.excludedContexts.contains(path))
+// {
+ log.debug(this.sm.getString("modcluster.context.start", path, context.getParent().getName()));
+
+ // Send ENABLE-APP
+ MCMPRequest request = this.requestFactory.createEnableRequest(context);
+
+ this.mcmpHandler.sendRequest(request);
+/* }
+ else
+ {
+ log.debug("Exluding context: " + path);
+ }
+*/ }
- // Send ENABLE-APP
- MCMPRequest request = MCMPUtils.createEnableAppRequest(context);
- this.mcmpHandler.sendRequest(request);
- }
-
public void stopContext(Context context)
{
this.checkInit();
- log.debug(this.sm.getString("modcluster.context.stop", context.getPath(), context.getParent().getName()));
+ String path = context.getPath();
+
+// if (!this.excludedContexts.contains(path))
+// {
+ log.debug(this.sm.getString("modcluster.context.stop", path, context.getParent().getName()));
+
+ // Send STOP-APP
+ MCMPRequest request = this.requestFactory.createStopRequest(context);
+
+ this.mcmpHandler.sendRequest(request);
+/* }
+ else
+ {
+ log.debug("Exluding context: " + path);
+ }
+*/ }
- // Send STOP-APP
- MCMPRequest request = MCMPUtils.createStopAppRequest(context);
- this.mcmpHandler.sendRequest(request);
- }
-
public void removeContext(Context context)
{
this.checkInit();
- log.debug(this.sm.getString("modcluster.context.disable", context.getPath(), context.getParent().getName()));
-
- // JVMRoute can be null here if nothing was ever initialized
- if (Utils.getJvmRoute(context) != null)
+ String path = context.getPath();
+
+// if (!this.excludedContexts.contains(path))
+// {
+ log.debug(this.sm.getString("modcluster.context.disable", path, context.getParent().getName()));
+
+ // JVMRoute can be null here if nothing was ever initialized
+ if (Utils.getJvmRoute(context) != null)
+ {
+ MCMPRequest request = this.requestFactory.createRemoveRequest(context);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+/* }
+ else
{
- MCMPRequest request = MCMPUtils.createRemoveAppRequest(context);
- this.mcmpHandler.sendRequest(request);
+ log.debug("Exluding context: " + path);
}
- }
+*/ }
protected void removeAll(Engine engine)
{
@@ -281,7 +326,8 @@
if (engine.getJvmRoute() != null)
{
// Send REMOVE-APP * request
- MCMPRequest request = MCMPUtils.createRemoveAllRequest(engine);
+ MCMPRequest request = this.requestFactory.createRemoveRequest(engine);
+
this.mcmpHandler.sendRequest(request);
}
}
@@ -296,7 +342,8 @@
// Send STATUS request
int lbf = this.getLoadBalanceFactor();
- MCMPRequest request = MCMPUtils.createStatusRequest(engine, lbf);
+ MCMPRequest request = this.requestFactory.createStatusRequest(engine.getJvmRoute(), lbf);
+
this.mcmpHandler.sendRequest(request);
}
@@ -305,8 +352,6 @@
return this.loadBalanceFactorProvider.getLoadBalanceFactor();
}
- // ---------------------------------------------------------------- Private
-
protected void checkInit()
{
if (!this.init)
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -41,6 +41,7 @@
import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric;
import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
/**
* Non-clustered mod_cluster lifecycle listener for use in JBoss Web standalone.
@@ -86,9 +87,9 @@
super();
}
- protected ModClusterListener(MCMPHandler mcmpHandler, LifecycleListener lifecycleListener)
+ protected ModClusterListener(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, LifecycleListener lifecycleListener)
{
- super(mcmpHandler, lifecycleListener);
+ super(mcmpHandler, requestFactory, lifecycleListener);
}
/**
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -24,6 +24,7 @@
import org.apache.catalina.LifecycleListener;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
/**
* Non-clustered mod_cluster lifecycle listener for use in JBoss AS.
@@ -40,9 +41,9 @@
this.lbfProvider = lbfProvider;
}
- protected ModClusterService(MCMPHandler mcmpHandler, LifecycleListener lifecycleListener, LoadBalanceFactorProvider lbfProvider)
+ protected ModClusterService(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, LifecycleListener lifecycleListener, LoadBalanceFactorProvider lbfProvider)
{
- super(mcmpHandler, lifecycleListener);
+ super(mcmpHandler, requestFactory, lifecycleListener);
this.lbfProvider = lbfProvider;
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -3,9 +3,13 @@
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Set;
import org.apache.catalina.Context;
@@ -23,6 +27,8 @@
public class Utils
{
+ private static final int DEFAULT_PORT = 8000;
+
private static final Logger log = Logger.getLogger(Utils.class);
private static final StringManager sm = StringManager.getManager(Constants.Package);
@@ -219,6 +225,56 @@
}
}
+ public static InetSocketAddress parseSocketAddress(String addressPort)
+ {
+ try
+ {
+ return parseSocketAddress(addressPort, 0);
+ }
+ catch (UnknownHostException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public static List<InetSocketAddress> parseProxies(String proxyList)
+ {
+ if ((proxyList == null) || (proxyList.length() == 0)) return Collections.emptyList();
+
+ String[] tokens = proxyList.split(",");
+
+ List<InetSocketAddress> proxies = new ArrayList<InetSocketAddress>(tokens.length);
+
+ for (String token: tokens)
+ {
+ try
+ {
+ InetSocketAddress addressPort = parseSocketAddress(token.trim(), DEFAULT_PORT);
+
+ proxies.add(addressPort);
+ }
+ catch (UnknownHostException e)
+ {
+ log.error(sm.getString("modcluster.error.invalidHost", token), e);
+ }
+ }
+
+ return proxies;
+ }
+
+ private static InetSocketAddress parseSocketAddress(String addressPort, int defaultPort) throws UnknownHostException
+ {
+ int pos = addressPort.indexOf(':');
+ boolean colonExists = (pos >= 0);
+
+ String address = colonExists ? addressPort.substring(0, pos) : addressPort;
+ int port = colonExists ? Integer.parseInt(addressPort.substring(pos + 1)) : defaultPort;
+
+ InetAddress inetAddress = (address != null) && (address.length() > 0) ? InetAddress.getByName(address) : null;
+
+ return new InetSocketAddress(inetAddress, port);
+ }
+
private Utils()
{
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -55,6 +55,8 @@
import org.jboss.modcluster.JBossWebEventHandler;
import org.jboss.modcluster.JBossWebEventHandlerAdapter;
import org.jboss.modcluster.Utils;
+import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
+import org.jboss.modcluster.advertise.impl.AdvertiseListenerFactoryImpl;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -75,11 +77,12 @@
import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
import org.jboss.modcluster.mcmp.MCMPServer;
import org.jboss.modcluster.mcmp.MCMPServerState;
-import org.jboss.modcluster.mcmp.MCMPUtils;
import org.jboss.modcluster.mcmp.ResetRequestSource;
import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
+import org.jboss.modcluster.mcmp.impl.DefaultMCMPRequestFactory;
/**
* A ModClusterService.
@@ -96,6 +99,7 @@
// ----------------------------------------------------------------- Fields
final MCMPHandler localHandler;
+ final MCMPRequestFactory requestFactory;
final ClusteredMCMPHandler clusteredHandler;
final HASingletonAwareResetRequestSource resetRequestSource;
final Map<ClusterNode, MCMPServerDiscoveryEvent> proxyChangeDigest =
@@ -154,11 +158,12 @@
this.setHAPartition(partition);
this.loadBalanceFactorProvider = loadFactorProvider;
- this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this, this);
- this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource);
+ this.requestFactory = new DefaultMCMPRequestFactory();
+ this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this.requestFactory, this, this);
+ this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource, this.requestFactory);
this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this, this);
- JBossWebEventHandler eventHandler = new ClusteredJBossWebEventHandler(config, config, config, this.clusteredHandler, this);
+ JBossWebEventHandler eventHandler = new ClusteredJBossWebEventHandler(config, config, config, this.clusteredHandler, this.requestFactory, this, new AdvertiseListenerFactoryImpl());
this.lifecycleListener = new JBossWebEventHandlerAdapter(eventHandler);
@@ -192,6 +197,7 @@
MCMPHandlerConfiguration mcmpConfig,
HAConfiguration haConfig,
MCMPHandler localHandler,
+ MCMPRequestFactory requestFactory,
HASingletonAwareResetRequestSource resetRequestSource,
ClusteredMCMPHandler clusteredHandler,
LifecycleListener lifecycleListener,
@@ -202,6 +208,7 @@
assert partition != null : this.sm.getString("modcluster.error.iae.null", "partition");
assert localHandler != null : this.sm.getString("modcluster.error.iae.null", "localHandler");
+ assert requestFactory != null : this.sm.getString("modcluster.error.iae.null", "requestFactory");
assert resetRequestSource != null : this.sm.getString("modcluster.error.iae.null", "resetRequestSource");
assert nodeConfig != null : this.sm.getString("modcluster.error.iae.null", "nodeConfig");
assert mcmpConfig != null : this.sm.getString("modcluster.error.iae.null", "mcmpConfig");
@@ -213,6 +220,7 @@
this.loadBalanceFactorProvider = loadFactorProvider;
this.localHandler = localHandler;
+ this.requestFactory = requestFactory;
this.resetRequestSource = resetRequestSource;
this.clusteredHandler = clusteredHandler;
this.lifecycleListener = lifecycleListener;
@@ -311,7 +319,7 @@
{
Engine engine = (Engine) service.getContainer();
// Send DISABLE-APP * request
- MCMPRequest request = MCMPUtils.createDisableEngineRequest(engine);
+ MCMPRequest request = this.requestFactory.createDisableRequest(engine);
this.clusteredHandler.sendRequest(request);
}
@@ -328,7 +336,7 @@
{
Engine engine = (Engine) service.getContainer();
// Send ENABLE-APP * request
- MCMPRequest request = MCMPUtils.createEnableEngineRequest(engine);
+ MCMPRequest request = this.requestFactory.createEnableRequest(engine);
this.clusteredHandler.sendRequest(request);
}
@@ -720,9 +728,10 @@
* @param loadFactorProvider
*/
public ClusteredJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpConfig, MCMPHandler clusteredHandler, LoadBalanceFactorProviderFactory loadFactorProviderFactory)
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler clusteredHandler, MCMPRequestFactory requestFactory,
+ LoadBalanceFactorProviderFactory loadFactorProviderFactory, AdvertiseListenerFactory listenerFactory)
{
- super(nodeConfig, balancerConfig, mcmpConfig, clusteredHandler, loadFactorProviderFactory);
+ super(nodeConfig, balancerConfig, mcmpConfig, clusteredHandler, requestFactory, loadFactorProviderFactory, listenerFactory);
}
@Override
@@ -923,7 +932,7 @@
List<MCMPRequest> statusRequests = new ArrayList<MCMPRequest>();
for (Map.Entry<String, Integer> entry: loadBalanceFactors.entrySet())
{
- statusRequests.add(MCMPUtils.createStatusRequest(entry.getKey(), entry.getValue().intValue()));
+ statusRequests.add(this.coord.requestFactory.createStatusRequest(entry.getKey(), entry.getValue().intValue()));
}
this.coord.localHandler.sendRequests(statusRequests);
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 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -41,6 +41,7 @@
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.MCMPRequestFactory;
import org.jboss.modcluster.mcmp.ResetRequestSource;
import org.jboss.modcluster.mcmp.impl.ResetRequestSourceImpl;
@@ -65,11 +66,13 @@
private final HASingletonMBean singleton;
private final ResetRequestSourceRpcHandler<List<?>> rpcStub;
- private volatile Server jbossWebServer;
- public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, HASingletonMBean singleton, HAServiceKeyProvider serviceKeyProvider)
+ private volatile Server server;
+
+ public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, MCMPRequestFactory requestFactory, HASingletonMBean singleton, HAServiceKeyProvider serviceKeyProvider)
{
- super(nodeConfig, balancerConfig);
+ super(nodeConfig, balancerConfig, requestFactory);
+
this.singleton = singleton;
this.rpcStub = new RpcStub(serviceKeyProvider);
}
@@ -93,21 +96,21 @@
*/
public List<MCMPRequest> getLocalResetRequests(Map<String, Set<VirtualHost>> response)
{
- if (this.jbossWebServer == null)
+ if (this.server == null)
{
return new ArrayList<MCMPRequest>();
}
- return super.getResetRequests(response, this.jbossWebServer);
+ return super.getResetRequests(response, this.server);
}
/**
* @{inheritDoc}
* @see org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#setJbossWebServer(org.apache.catalina.Server)
*/
- public void setJbossWebServer(Server jbossWebServer)
+ public void setJbossWebServer(Server server)
{
- this.jbossWebServer = jbossWebServer;
+ this.server = server;
}
private void addRemoteRequests(List<MCMPRequest> resets, Map<String, Set<VirtualHost>> resp)
@@ -133,8 +136,7 @@
else
{
log.error(this.sm.getString("modcluster.error.rpc.unexpected", response, METHOD_NAME));
- }
-
+ }
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/AbstractMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/AbstractMCMPHandler.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/AbstractMCMPHandler.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -25,6 +25,8 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
+import org.jboss.modcluster.Utils;
+
/**
* Abstract {@link MCMPHandler} that implements the trivial convenience methods.
*
@@ -38,7 +40,7 @@
*/
public void addProxy(String address)
{
- InetSocketAddress socketAddress = MCMPUtils.parseSocketAddress(address);
+ InetSocketAddress socketAddress = Utils.parseSocketAddress(address);
this.addProxy(socketAddress.getAddress(), socketAddress.getPort());
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPRequest.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPRequest.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPRequest.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -23,69 +23,21 @@
package org.jboss.modcluster.mcmp;
import java.io.Serializable;
-import java.util.Collections;
import java.util.Map;
-import net.jcip.annotations.Immutable;
-
/**
* Encapsulates the parameters for a request over MCMP.
*
* @author Brian Stansberry
* @version $Revision$
*/
-@Immutable
-public class MCMPRequest implements Serializable
+public interface MCMPRequest extends Serializable
{
- /** The serialVersionUID */
- private static final long serialVersionUID = 7107364666635260031L;
-
- private final MCMPRequestType requestType;
- private final boolean wildcard;
- private final Map<String, String> parameters;
- private final String jvmRoute;
-
- /**
- * Create a new ModClusterRequest.
- */
- public MCMPRequest(MCMPRequestType requestType, boolean wildcard, String jvmRoute, Map<String, String> parameters)
- {
- this.requestType = requestType;
- this.wildcard = wildcard;
- this.jvmRoute = jvmRoute;
- this.parameters = Collections.unmodifiableMap(parameters);
- }
+ MCMPRequestType getRequestType();
- public MCMPRequestType getRequestType()
- {
- return this.requestType;
- }
+ boolean isWildcard();
- public boolean isWildcard()
- {
- return this.wildcard;
- }
-
- public String getJvmRoute()
- {
- return this.jvmRoute;
- }
+ String getJvmRoute();
- public Map<String, String> getParameters()
- {
- return this.parameters;
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder(getClass().getName());
- sb.append("{requestType=").append(this.requestType);
- sb.append(",wildcard=").append(this.wildcard);
- sb.append(",jvmRoute=").append(this.jvmRoute);
- sb.append(",parameters=").append(this.parameters);
- sb.append("}");
-
- return sb.toString();
- }
+ Map<String, String> getParameters();
}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPRequestFactory.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPRequestFactory.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPRequestFactory.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.modcluster.mcmp;
+
+import java.util.Set;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface MCMPRequestFactory
+{
+ MCMPRequest createConfigRequest(Engine engine, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig);
+
+ MCMPRequest createEnableRequest(Context context);
+
+ MCMPRequest createDisableRequest(Context context);
+
+ MCMPRequest createStopRequest(Context context);
+
+ MCMPRequest createRemoveRequest(Context context);
+
+ MCMPRequest createStatusRequest(String jvmRoute, int lbf);
+
+ MCMPRequest createEnableRequest(Engine engine);
+
+ MCMPRequest createDisableRequest(Engine engine);
+
+ MCMPRequest createRemoveRequest(Engine engine);
+
+ MCMPRequest createInfoRequest();
+
+ MCMPRequest createDumpRequest();
+
+ MCMPRequest createRequest(MCMPRequestType type, String jvmRoute, Set<String> aliases, String path);
+}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -1,432 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, 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.mcmp;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.catalina.Container;
-import org.apache.catalina.Context;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Host;
-import org.apache.catalina.Server;
-import org.apache.catalina.Service;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.util.StringManager;
-import org.apache.coyote.ProtocolHandler;
-import org.apache.tomcat.util.IntrospectionUtils;
-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.mcmp.ResetRequestSource.VirtualHost;
-
-/**
- * Utility methods related to the Mod-Cluster Management Protocol.
- *
- * @author Brian Stansberry
- * @version $Revision$
- */
-public class MCMPUtils
-{
- public static final int DEFAULT_PORT = 8000;
-
- private static final Map<String, String> EMPTY_MAP = Collections.emptyMap();
- public static final MCMPRequest INFO_REQUEST = new MCMPRequest(MCMPRequestType.INFO, false, null, EMPTY_MAP);
- public static final MCMPRequest DUMP_REQUEST = new MCMPRequest(MCMPRequestType.DUMP, true, null, EMPTY_MAP);
-
- private static final Logger log = Logger.getLogger(MCMPUtils.class);
-
- /**
- * The string manager for this package.
- */
- private static final StringManager sm = StringManager.getManager(Constants.Package);
-
- public static MCMPRequest createConfigRequest(Engine engine, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
- {
- 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();
-
- boolean reverseConnection = Boolean.TRUE.equals(IntrospectionUtils.getProperty(handler, "reverseConnection"));
- boolean ssl = Boolean.TRUE.equals(IntrospectionUtils.getProperty(handler, "SSLEnabled"));
- boolean ajp = ((String) IntrospectionUtils.getProperty(handler, "name")).startsWith("ajp-");
-
- if (reverseConnection)
- {
- parameters.put("Reversed", "true");
- }
- parameters.put("Host", Utils.getAddress(connector));
- parameters.put("Port", "" + connector.getPort());
- if (ajp)
- {
- parameters.put("Type", "ajp");
- }
- else if (ssl)
- {
- parameters.put("Type", "https");
- }
- else
- {
- parameters.put("Type", "http");
- }
-
- // Other configuration parameters
- String domain = nodeConfig.getDomain();
- if (domain != null)
- {
- parameters.put("Domain", domain);
- }
- if (nodeConfig.getFlushPackets())
- {
- parameters.put("flushpackets", "On");
- }
- int flushWait = nodeConfig.getFlushWait();
- if (flushWait != -1)
- {
- parameters.put("flushwait", String.valueOf(flushWait));
- }
- int ping = nodeConfig.getPing();
- if (ping != -1)
- {
- parameters.put("ping", String.valueOf(ping));
- }
- int smax = nodeConfig.getSmax();
- if (smax != -1)
- {
- parameters.put("smax", String.valueOf(smax));
- }
- int ttl = nodeConfig.getTtl();
- if (ttl != -1)
- {
- parameters.put("ttl", String.valueOf(ttl));
- }
- int nodeTimeout = nodeConfig.getNodeTimeout();
- if (nodeTimeout != -1)
- {
- parameters.put("Timeout", String.valueOf(nodeTimeout));
- }
- String balancer = nodeConfig.getBalancer();
- if (balancer != null)
- {
- parameters.put("Balancer", balancer);
- }
- if (!balancerConfig.getStickySession())
- {
- parameters.put("StickySession", "No");
- }
- if (!org.apache.catalina.Globals.SESSION_COOKIE_NAME.equals("JSESSIONID"))
- {
- parameters.put("StickySessionCookie", org.apache.catalina.Globals.SESSION_COOKIE_NAME);
- }
- if (!org.apache.catalina.Globals.SESSION_PARAMETER_NAME.equals("jsessionid"))
- {
- parameters.put("StickySessionPath", org.apache.catalina.Globals.SESSION_PARAMETER_NAME);
- }
- if (balancerConfig.getStickySessionRemove())
- {
- parameters.put("StickySessionRemove", "Yes");
- }
- if (!balancerConfig.getStickySessionForce())
- {
- parameters.put("StickySessionForce", "No");
- }
- int workerTimeout = balancerConfig.getWorkerTimeout();
- if (workerTimeout != -1)
- {
- parameters.put("WaitWorker", "" + workerTimeout);
- }
- int maxAttempts = balancerConfig.getMaxAttempts();
- if (maxAttempts != -1)
- {
- parameters.put("Maxattempts", "" + maxAttempts);
- }
-
- return new MCMPRequest(MCMPRequestType.CONFIG, false, jvmRoute, parameters);
- }
-
- public static MCMPRequest createEnableAppRequest(Context context)
- {
- return createRequest(MCMPRequestType.ENABLE_APP, context);
- }
-
- public static MCMPRequest createDisableAppRequest(Context context)
- {
- return createRequest(MCMPRequestType.DISABLE_APP, context);
- }
-
- public static MCMPRequest createStopAppRequest(Context context)
- {
- return createRequest(MCMPRequestType.STOP_APP, context);
- }
-
- public static MCMPRequest createRemoveAppRequest(Context context)
- {
- return createRequest(MCMPRequestType.REMOVE_APP, context);
- }
-
- private static MCMPRequest createRequest(MCMPRequestType type, Context context)
- {
- return createContextRequest(type, Utils.getJvmRoute(context), Utils.getAliases(context), context.getPath());
- }
-
- private static MCMPRequest createContextRequest(MCMPRequestType type, String jvmRoute, Set<String> aliases, String path)
- {
- Map<String, String> parameters = new HashMap<String, String>();
-
- parameters.put("Context", "".equals(path) ? "/" : path);
-
- StringBuilder builder = new StringBuilder();
- Iterator<String> hosts = aliases.iterator();
- while (hosts.hasNext())
- {
- builder.append(hosts.next());
- if (hosts.hasNext())
- {
- builder.append(',');
- }
- }
- parameters.put("Alias", builder.toString());
-
- return new MCMPRequest(type, false, jvmRoute, parameters);
- }
-
- public static MCMPRequest createStatusRequest(Engine engine, int lbf)
- {
- return createStatusRequest(engine.getJvmRoute(), lbf);
- }
-
- public static MCMPRequest createStatusRequest(String jvmRoute, int lbf)
- {
- return new MCMPRequest(MCMPRequestType.STATUS, false, jvmRoute, Collections.singletonMap("Load", String.valueOf(lbf)));
- }
-
- public static MCMPRequest createEnableEngineRequest(Engine engine)
- {
- return createRequest(MCMPRequestType.ENABLE_APP, engine);
- }
-
- public static MCMPRequest createDisableEngineRequest(Engine engine)
- {
- return createRequest(MCMPRequestType.DISABLE_APP, engine);
- }
-
- public static MCMPRequest createRemoveAllRequest(Engine engine)
- {
- return createRequest(MCMPRequestType.REMOVE_APP, engine);
- }
-
- private static MCMPRequest createRequest(MCMPRequestType type, Engine engine)
- {
- 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(Map<String, Set<ResetRequestSource.VirtualHost>> response, Server server, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
- {
- List<MCMPRequest> requests = new ArrayList<MCMPRequest>();
- List<MCMPRequest> engineRequests = new LinkedList<MCMPRequest>();
-
- for (Service service: server.findServices())
- {
- Engine engine = (Engine) service.getContainer();
- String jvmRoute = engine.getJvmRoute();
-
- engineRequests.add(createConfigRequest(jvmRoute, service.findConnectors(), nodeConfig, balancerConfig));
-
- Set<ResetRequestSource.VirtualHost> responseHosts = Collections.emptySet();
- if (response.containsKey(jvmRoute))
- {
- responseHosts = response.get(jvmRoute);
- }
-
- for (Container child: engine.findChildren())
- {
- Host host = (Host) child;
- String hostName = host.getName();
- Set<String> aliases = Utils.getAliases(host);
-
- VirtualHost responseHost = null;
-
- for (VirtualHost virtualHost: responseHosts)
- {
- if (virtualHost.getAliases().contains(hostName))
- {
- responseHost = virtualHost;
- break;
- }
- }
-
- Set<String> responseAliases = Collections.emptySet();
- Map<String, ResetRequestSource.Status> responseContexts = Collections.emptyMap();
-
- if (responseHost != null)
- {
- responseAliases = responseHost.getAliases();
-
- // If the host(or aliases) is missing - force full reset
- if (!aliases.equals(responseAliases))
- {
- engineRequests.add(0, createEngineRequest(MCMPRequestType.REMOVE_APP, jvmRoute));
- }
- else
- {
- responseContexts = responseHost.getContexts();
- }
- }
-
- Set<String> obsoleteContexts = new HashSet<String>(responseContexts.keySet());
-
- for (Container container: host.findChildren())
- {
- Context context = (Context) container;
- String path = context.getPath();
-
- obsoleteContexts.remove(path);
-
- ResetRequestSource.Status status = responseContexts.get(path);
-
- if (Utils.isContextStarted(context))
- {
- if (status != ResetRequestSource.Status.ENABLED)
- {
- engineRequests.add(createContextRequest(MCMPRequestType.ENABLE_APP, jvmRoute, aliases, path));
- }
- }
- else
- {
- if (status == ResetRequestSource.Status.ENABLED)
- {
- engineRequests.add(createContextRequest(MCMPRequestType.STOP_APP, jvmRoute, aliases, path));
- }
- }
- }
-
- if (!obsoleteContexts.isEmpty())
- {
- // If all contexts from response no longer exist - remove all
- if (obsoleteContexts.size() == responseContexts.size())
- {
- // Send REMOVE-APP * request first
- engineRequests.add(0, createEngineRequest(MCMPRequestType.REMOVE_APP, jvmRoute));
- }
- // otherwise only remove those that no longer exist
- else
- {
- for (String context: obsoleteContexts)
- {
- engineRequests.add(createContextRequest(MCMPRequestType.REMOVE_APP, jvmRoute, responseAliases, context));
- }
- }
- }
- }
-
- requests.addAll(engineRequests);
-
- engineRequests.clear();
- }
-
- return requests;
- }
-
- public static InetSocketAddress parseSocketAddress(String addressPort)
- {
- try
- {
- return parseSocketAddress(addressPort, 0);
- }
- catch (UnknownHostException e)
- {
- throw new IllegalArgumentException(e);
- }
- }
-
- public static List<InetSocketAddress> parseProxies(String proxyList)
- {
- if ((proxyList == null) || (proxyList.length() == 0)) return Collections.emptyList();
-
- String[] tokens = proxyList.split(",");
-
- List<InetSocketAddress> proxies = new ArrayList<InetSocketAddress>(tokens.length);
-
- for (String token: tokens)
- {
- try
- {
- InetSocketAddress addressPort = parseSocketAddress(token.trim(), DEFAULT_PORT);
-
- proxies.add(addressPort);
- }
- catch (UnknownHostException e)
- {
- log.error(sm.getString("modcluster.error.invalidHost", token), e);
- }
- }
-
- return proxies;
- }
-
- private static InetSocketAddress parseSocketAddress(String addressPort, int defaultPort) throws UnknownHostException
- {
- int pos = addressPort.indexOf(':');
- boolean colonExists = (pos >= 0);
-
- String address = colonExists ? addressPort.substring(0, pos) : addressPort;
- int port = colonExists ? Integer.parseInt(addressPort.substring(pos + 1)) : defaultPort;
-
- InetAddress inetAddress = (address != null) && (address.length() > 0) ? InetAddress.getByName(address) : null;
-
- return new InetSocketAddress(inetAddress, port);
- }
-
- /**
- * Disable external instantiation.
- */
- private MCMPUtils()
- {
- }
-}
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 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -63,9 +63,9 @@
import org.jboss.modcluster.mcmp.AbstractMCMPHandler;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
import org.jboss.modcluster.mcmp.MCMPServerState;
import org.jboss.modcluster.mcmp.MCMPURLEncoder;
-import org.jboss.modcluster.mcmp.MCMPUtils;
import org.jboss.modcluster.mcmp.ResetRequestSource;
/**
@@ -91,6 +91,7 @@
private final MCMPHandlerConfiguration config;
/** Source for reset requests when we need to reset a proxy. */
private final ResetRequestSource resetRequestSource;
+ private final MCMPRequestFactory requestFactory;
private final ReadWriteLock proxiesLock = new ReentrantReadWriteLock();
private final Lock addRemoveProxiesLock = new ReentrantLock();
@@ -112,10 +113,11 @@
// ----------------------------------------------------------- Constructors
- public DefaultMCMPHandler(MCMPHandlerConfiguration config, ResetRequestSource source)
+ public DefaultMCMPHandler(MCMPHandlerConfiguration config, ResetRequestSource source, MCMPRequestFactory requestFactory)
{
this.resetRequestSource = source;
this.config = config;
+ this.requestFactory = requestFactory;
}
// ------------------------------------------------------------ MCMPHandler
@@ -321,7 +323,7 @@
public String getProxyConfiguration()
{
// Send DUMP * request
- return this.getProxyMessage(MCMPUtils.DUMP_REQUEST);
+ return this.getProxyMessage(this.requestFactory.createDumpRequest());
}
/**
@@ -332,7 +334,7 @@
public String getProxyInfo()
{
// Send INFO * request
- return this.getProxyMessage(MCMPUtils.INFO_REQUEST);
+ return this.getProxyMessage(this.requestFactory.createInfoRequest());
}
private String getProxyMessage(MCMPRequest request)
@@ -450,7 +452,7 @@
{
proxy.setState(Proxy.State.OK);
- String response = this.sendRequest(MCMPUtils.INFO_REQUEST, proxy);
+ String response = this.sendRequest(this.requestFactory.createInfoRequest(), proxy);
if (proxy.getState() == Proxy.State.OK)
{
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPRequest.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPRequest.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPRequest.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.mcmp.impl;
+
+import java.util.Collections;
+import java.util.Map;
+
+import net.jcip.annotations.Immutable;
+
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestType;
+
+/**
+ * Encapsulates the parameters for a request over MCMP.
+ *
+ * @author Brian Stansberry
+ * @author Paul Ferraro
+ */
+@Immutable
+public class DefaultMCMPRequest implements MCMPRequest
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 7107364666635260031L;
+
+ private final MCMPRequestType requestType;
+ private final boolean wildcard;
+ private final Map<String, String> parameters;
+ private final String jvmRoute;
+
+ /**
+ * Create a new ModClusterRequest.
+ */
+ public DefaultMCMPRequest(MCMPRequestType requestType, boolean wildcard, String jvmRoute, Map<String, String> parameters)
+ {
+ this.requestType = requestType;
+ this.wildcard = wildcard;
+ this.jvmRoute = jvmRoute;
+ this.parameters = Collections.unmodifiableMap(parameters);
+ }
+
+ public MCMPRequestType getRequestType()
+ {
+ return this.requestType;
+ }
+
+ public boolean isWildcard()
+ {
+ return this.wildcard;
+ }
+
+ public String getJvmRoute()
+ {
+ return this.jvmRoute;
+ }
+
+ public Map<String, String> getParameters()
+ {
+ return this.parameters;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder(getClass().getName());
+ sb.append("{requestType=").append(this.requestType);
+ sb.append(",wildcard=").append(this.wildcard);
+ sb.append(",jvmRoute=").append(this.jvmRoute);
+ sb.append(",parameters=").append(this.parameters);
+ sb.append("}");
+
+ return sb.toString();
+ }
+}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPRequestFactory.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPRequestFactory.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPRequestFactory.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -0,0 +1,289 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.modcluster.mcmp.impl;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.connector.Connector;
+import org.apache.coyote.ProtocolHandler;
+import org.apache.tomcat.util.IntrospectionUtils;
+import org.jboss.modcluster.Utils;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
+import org.jboss.modcluster.mcmp.MCMPRequestType;
+
+/**
+ * @author Paul Ferraro
+ */
+public class DefaultMCMPRequestFactory implements MCMPRequestFactory
+{
+ private static final Map<String, String> EMPTY_MAP = Collections.emptyMap();
+
+ private final MCMPRequest infoRequest = new DefaultMCMPRequest(MCMPRequestType.INFO, false, null, EMPTY_MAP);
+ private final MCMPRequest dumpRequest = new DefaultMCMPRequest(MCMPRequestType.DUMP, true, null, EMPTY_MAP);
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createConfigRequest(org.apache.catalina.Engine, org.jboss.modcluster.config.NodeConfiguration, org.jboss.modcluster.config.BalancerConfiguration)
+ */
+ public MCMPRequest createConfigRequest(Engine engine, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
+ {
+ Connector connector = Utils.findProxyConnector(engine.getService().findConnectors());
+ Map<String, String> parameters = new HashMap<String, String>();
+
+ ProtocolHandler handler = connector.getProtocolHandler();
+
+ boolean reverseConnection = Boolean.TRUE.equals(IntrospectionUtils.getProperty(handler, "reverseConnection"));
+ boolean ssl = Boolean.TRUE.equals(IntrospectionUtils.getProperty(handler, "SSLEnabled"));
+ boolean ajp = ((String) IntrospectionUtils.getProperty(handler, "name")).startsWith("ajp-");
+
+ if (reverseConnection)
+ {
+ parameters.put("Reversed", "true");
+ }
+ parameters.put("Host", Utils.getAddress(connector));
+ parameters.put("Port", "" + connector.getPort());
+ if (ajp)
+ {
+ parameters.put("Type", "ajp");
+ }
+ else if (ssl)
+ {
+ parameters.put("Type", "https");
+ }
+ else
+ {
+ parameters.put("Type", "http");
+ }
+
+ // Other configuration parameters
+ String domain = nodeConfig.getDomain();
+ if (domain != null)
+ {
+ parameters.put("Domain", domain);
+ }
+ if (nodeConfig.getFlushPackets())
+ {
+ parameters.put("flushpackets", "On");
+ }
+ int flushWait = nodeConfig.getFlushWait();
+ if (flushWait != -1)
+ {
+ parameters.put("flushwait", String.valueOf(flushWait));
+ }
+ int ping = nodeConfig.getPing();
+ if (ping != -1)
+ {
+ parameters.put("ping", String.valueOf(ping));
+ }
+ int smax = nodeConfig.getSmax();
+ if (smax != -1)
+ {
+ parameters.put("smax", String.valueOf(smax));
+ }
+ int ttl = nodeConfig.getTtl();
+ if (ttl != -1)
+ {
+ parameters.put("ttl", String.valueOf(ttl));
+ }
+ int nodeTimeout = nodeConfig.getNodeTimeout();
+ if (nodeTimeout != -1)
+ {
+ parameters.put("Timeout", String.valueOf(nodeTimeout));
+ }
+ String balancer = nodeConfig.getBalancer();
+ if (balancer != null)
+ {
+ parameters.put("Balancer", balancer);
+ }
+ if (!balancerConfig.getStickySession())
+ {
+ parameters.put("StickySession", "No");
+ }
+ if (!org.apache.catalina.Globals.SESSION_COOKIE_NAME.equals("JSESSIONID"))
+ {
+ parameters.put("StickySessionCookie", org.apache.catalina.Globals.SESSION_COOKIE_NAME);
+ }
+ if (!org.apache.catalina.Globals.SESSION_PARAMETER_NAME.equals("jsessionid"))
+ {
+ parameters.put("StickySessionPath", org.apache.catalina.Globals.SESSION_PARAMETER_NAME);
+ }
+ if (balancerConfig.getStickySessionRemove())
+ {
+ parameters.put("StickySessionRemove", "Yes");
+ }
+ if (!balancerConfig.getStickySessionForce())
+ {
+ parameters.put("StickySessionForce", "No");
+ }
+ int workerTimeout = balancerConfig.getWorkerTimeout();
+ if (workerTimeout != -1)
+ {
+ parameters.put("WaitWorker", "" + workerTimeout);
+ }
+ int maxAttempts = balancerConfig.getMaxAttempts();
+ if (maxAttempts != -1)
+ {
+ parameters.put("Maxattempts", "" + maxAttempts);
+ }
+
+ return new DefaultMCMPRequest(MCMPRequestType.CONFIG, false, engine.getJvmRoute(), parameters);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createDisableRequest(org.apache.catalina.Context)
+ */
+ public MCMPRequest createDisableRequest(Context context)
+ {
+ return this.createRequest(MCMPRequestType.DISABLE_APP, context);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createDisableRequest(org.apache.catalina.Engine)
+ */
+ public MCMPRequest createDisableRequest(Engine engine)
+ {
+ return this.createRequest(MCMPRequestType.DISABLE_APP, engine);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createEnableRequest(org.apache.catalina.Context)
+ */
+ public MCMPRequest createEnableRequest(Context context)
+ {
+ return this.createRequest(MCMPRequestType.ENABLE_APP, context);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createEnableRequest(org.apache.catalina.Engine)
+ */
+ public MCMPRequest createEnableRequest(Engine engine)
+ {
+ return this.createRequest(MCMPRequestType.ENABLE_APP, engine);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createRemoveRequest(org.apache.catalina.Engine)
+ */
+ public MCMPRequest createRemoveRequest(Engine engine)
+ {
+ return this.createRequest(MCMPRequestType.REMOVE_APP, engine);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createRemoveRequest(org.apache.catalina.Context)
+ */
+ public MCMPRequest createRemoveRequest(Context context)
+ {
+ return this.createRequest(MCMPRequestType.REMOVE_APP, context);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createStatusRequest(java.lang.String, int)
+ */
+ public MCMPRequest createStatusRequest(String jvmRoute, int lbf)
+ {
+ return new DefaultMCMPRequest(MCMPRequestType.STATUS, false, jvmRoute, Collections.singletonMap("Load", String.valueOf(lbf)));
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createStopRequest(org.apache.catalina.Context)
+ */
+ public MCMPRequest createStopRequest(Context context)
+ {
+ return this.createRequest(MCMPRequestType.STOP_APP, context);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createDumpRequest()
+ */
+ public MCMPRequest createDumpRequest()
+ {
+ return this.dumpRequest;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createInfoRequest()
+ */
+ public MCMPRequest createInfoRequest()
+ {
+ return this.infoRequest;
+ }
+
+ private MCMPRequest createRequest(MCMPRequestType type, Context context)
+ {
+ return this.createRequest(type, Utils.getJvmRoute(context), Utils.getAliases(context), context.getPath());
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPRequestFactory#createRequest(org.jboss.modcluster.mcmp.MCMPRequestType, java.lang.String, java.util.Set, java.lang.String)
+ */
+ public MCMPRequest createRequest(MCMPRequestType type, String jvmRoute, Set<String> aliases, String path)
+ {
+ Map<String, String> parameters = new HashMap<String, String>();
+
+ parameters.put("Context", "".equals(path) ? "/" : path);
+
+ StringBuilder builder = new StringBuilder();
+ Iterator<String> hosts = aliases.iterator();
+ while (hosts.hasNext())
+ {
+ builder.append(hosts.next());
+ if (hosts.hasNext())
+ {
+ builder.append(',');
+ }
+ }
+ parameters.put("Alias", builder.toString());
+
+ return new DefaultMCMPRequest(type, false, jvmRoute, parameters);
+ }
+
+ private MCMPRequest createRequest(MCMPRequestType type, Engine engine)
+ {
+ return this.createRequest(type, engine.getJvmRoute());
+ }
+
+ private MCMPRequest createRequest(MCMPRequestType type, String jvmRoute)
+ {
+ return new DefaultMCMPRequest(type, true, jvmRoute, EMPTY_MAP);
+ }
+}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -21,16 +21,27 @@
*/
package org.jboss.modcluster.mcmp.impl;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
import org.apache.catalina.Server;
import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.jboss.modcluster.Utils;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPUtils;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
+import org.jboss.modcluster.mcmp.MCMPRequestType;
import org.jboss.modcluster.mcmp.ResetRequestSource;
/**
@@ -41,11 +52,13 @@
{
private final NodeConfiguration nodeConfig;
private final BalancerConfiguration balancerConfig;
+ private final MCMPRequestFactory requestFactory;
- public ResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
+ public ResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, MCMPRequestFactory requestFactory)
{
this.nodeConfig = nodeConfig;
this.balancerConfig = balancerConfig;
+ this.requestFactory = requestFactory;
}
/**
@@ -59,6 +72,109 @@
protected List<MCMPRequest> getResetRequests(Map<String, Set<VirtualHost>> response, Server server)
{
- return MCMPUtils.getResetRequests(response, server, this.nodeConfig, this.balancerConfig);
+ List<MCMPRequest> requests = new ArrayList<MCMPRequest>();
+ List<MCMPRequest> engineRequests = new LinkedList<MCMPRequest>();
+
+ for (Service service: server.findServices())
+ {
+ Engine engine = (Engine) service.getContainer();
+
+ engineRequests.add(this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig));
+
+ Set<ResetRequestSource.VirtualHost> responseHosts = Collections.emptySet();
+ String jvmRoute = engine.getJvmRoute();
+
+ if (response.containsKey(jvmRoute))
+ {
+ responseHosts = response.get(jvmRoute);
+ }
+
+ for (Container child: engine.findChildren())
+ {
+ Host host = (Host) child;
+ String hostName = host.getName();
+ Set<String> aliases = Utils.getAliases(host);
+
+ VirtualHost responseHost = null;
+
+ for (VirtualHost virtualHost: responseHosts)
+ {
+ if (virtualHost.getAliases().contains(hostName))
+ {
+ responseHost = virtualHost;
+ break;
+ }
+ }
+
+ Set<String> responseAliases = Collections.emptySet();
+ Map<String, ResetRequestSource.Status> responseContexts = Collections.emptyMap();
+
+ if (responseHost != null)
+ {
+ responseAliases = responseHost.getAliases();
+
+ // If the host(or aliases) is missing - force full reset
+ if (!aliases.equals(responseAliases))
+ {
+ engineRequests.add(0, this.requestFactory.createRemoveRequest(engine));
+ }
+ else
+ {
+ responseContexts = responseHost.getContexts();
+ }
+ }
+
+ Set<String> obsoleteContexts = new HashSet<String>(responseContexts.keySet());
+
+ for (Container container: host.findChildren())
+ {
+ Context context = (Context) container;
+ String path = context.getPath();
+
+ obsoleteContexts.remove(path);
+
+ ResetRequestSource.Status status = responseContexts.get(path);
+
+ if (Utils.isContextStarted(context))
+ {
+ if (status != ResetRequestSource.Status.ENABLED)
+ {
+ engineRequests.add(this.requestFactory.createEnableRequest(context));
+ }
+ }
+ else
+ {
+ if (status == ResetRequestSource.Status.ENABLED)
+ {
+ engineRequests.add(this.requestFactory.createStopRequest(context));
+ }
+ }
+ }
+
+ if (!obsoleteContexts.isEmpty())
+ {
+ // If all contexts from response no longer exist - remove all
+ if (obsoleteContexts.size() == responseContexts.size())
+ {
+ // Send REMOVE-APP * request first
+ engineRequests.add(0, this.requestFactory.createRemoveRequest(engine));
+ }
+ // otherwise only remove those that no longer exist
+ else
+ {
+ for (String context: obsoleteContexts)
+ {
+ engineRequests.add(this.requestFactory.createRequest(MCMPRequestType.REMOVE_APP, jvmRoute, responseAliases, context));
+ }
+ }
+ }
+ }
+
+ requests.addAll(engineRequests);
+
+ engineRequests.clear();
+ }
+
+ return requests;
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -26,7 +26,6 @@
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.apache.catalina.Container;
@@ -47,6 +46,7 @@
import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
import org.jboss.modcluster.mcmp.MCMPRequestType;
import org.jboss.modcluster.mcmp.MCMPServerState;
import org.junit.Assert;
@@ -64,81 +64,102 @@
private final BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
private final MCMPHandlerConfiguration mcmpConfig = EasyMock.createStrictMock(MCMPHandlerConfiguration.class);
private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
+ private final MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
private final LoadBalanceFactorProviderFactory lbfProviderFactory = EasyMock.createStrictMock(LoadBalanceFactorProviderFactory.class);
private final LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
private final AdvertiseListenerFactory listenerFactory = EasyMock.createStrictMock(AdvertiseListenerFactory.class);
+ private AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
private JBossWebEventHandler handler;
@Before
public void construct() throws Exception
{
- this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.lbfProviderFactory, this.listenerFactory);
+ this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.requestFactory, this.lbfProviderFactory, this.listenerFactory);
}
@Test
- public void init() throws IOException
+ public void initNoAdvertise() throws IOException
{
InetAddress localAddress = InetAddress.getLocalHost();
String localHostName = localAddress.getHostName();
- AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
-
// Test advertise = false
EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
this.mcmpHandler.init(Collections.singletonList(new InetSocketAddress(localAddress, 8000)));
+// EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn(null);
+
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.FALSE);
- EasyMock.replay(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.replay(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
- EasyMock.reset(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.verify(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory);
+ EasyMock.reset(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory);
+ }
+
+ @Test
+ public void initAdvertise() throws IOException
+ {
+ InetAddress localAddress = InetAddress.getLocalHost();
+ String localHostName = localAddress.getHostName();
-
// Test advertise = true
EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
this.mcmpHandler.init(Collections.singletonList(new InetSocketAddress(localAddress, 8000)));
+// EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("");
+
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(listener);
+ EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(this.listener);
- listener.start();
+ this.listener.start();
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, this.listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, this.listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, this.listener);
+ }
+
+ @Test
+ public void init() throws IOException
+ {
+ InetAddress localAddress = InetAddress.getLocalHost();
+ String localHostName = localAddress.getHostName();
-
// Test advertise = null, proxies configured
EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
this.mcmpHandler.init(Collections.singletonList(new InetSocketAddress(localAddress, 8000)));
+// EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("/ignored");
+
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
- EasyMock.replay(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.replay(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
- EasyMock.reset(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
-
-
+ EasyMock.verify(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory);
+ EasyMock.reset(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory);
+ }
+
+ @Test
+ public void initNoProxies() throws IOException
+ {
// Test advertise = null, no proxies configured
EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(null);
@@ -146,24 +167,26 @@
this.mcmpHandler.init(emptyList);
+// EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("/ignored,/");
+
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
- EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(listener);
+ EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(this.listener);
- listener.start();
+ this.listener.start();
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, this.listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, this.listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, this.listener);
}
@Test
- public void shutdown() throws IOException
+ public void shutdownNoAdvertise()
{
// Test w/out advertise listener
this.mcmpHandler.shutdown();
@@ -174,48 +197,30 @@
EasyMock.verify(this.mcmpHandler);
EasyMock.reset(this.mcmpHandler);
-
+ }
+
+ @Test
+ public void shutdownAdvertise() throws IOException
+ {
// Test w/advertise listener
// First init() to create listener
- this.init();
- InetAddress localAddress = InetAddress.getLocalHost();
- String localHostName = localAddress.getHostName();
+ this.initAdvertise();
- AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
-
- EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
- EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
-
- this.mcmpHandler.init(Collections.singletonList(new InetSocketAddress(localAddress, 8000)));
-
- EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.TRUE);
-
- EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(listener);
-
- listener.start();
-
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
-
- this.handler.init();
-
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
-
// Now test shutdown()
- listener.destroy();
+ this.listener.destroy();
this.mcmpHandler.shutdown();
- EasyMock.replay(this.mcmpHandler, listener);
+ EasyMock.replay(this.mcmpHandler, this.listener);
this.handler.shutdown();
- EasyMock.verify(this.mcmpHandler, listener);
- EasyMock.reset(this.mcmpHandler, listener);
+ EasyMock.verify(this.mcmpHandler, this.listener);
+ EasyMock.reset(this.mcmpHandler, this.listener);
}
@Test
- public void addContext() throws IOException
+ public void addContextNotInit()
{
Context context = EasyMock.createStrictMock(Context.class);
@@ -235,25 +240,57 @@
EasyMock.verify(context);
EasyMock.reset(context);
+ }
+/*
+ @Test
+ public void addContextIgnored() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
init();
-
+
+ EasyMock.expect(context.getPath()).andReturn("/ignored");
+
+ EasyMock.replay(context);
+
+ this.handler.addContext(context);
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+ }
+*/
+ @Test
+ public void addContextNotStarted() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
Host host = EasyMock.createStrictMock(Host.class);
+ init();
+
// Test context not started
- recordAddContext(context, host);
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(context.isStarted()).andReturn(false);
+
EasyMock.replay(context, host);
this.handler.addContext(context);
EasyMock.verify(context, host);
EasyMock.reset(context, host);
+ }
+
+ @Test
+ public void addContext() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
- // Test context started
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
+ init();
+
// Expect log message
EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(host);
@@ -261,51 +298,19 @@
EasyMock.expect(context.isStarted()).andReturn(true);
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(this.requestFactory.createEnableRequest(context)).andReturn(request);
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ this.mcmpHandler.sendRequest(request);
- EasyMock.replay(this.mcmpHandler, context, engine, host);
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, context, host);
this.handler.addContext(context);
- EasyMock.verify(this.mcmpHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.mcmpHandler, context, engine, host);
+ EasyMock.verify(this.mcmpHandler, context, host);
}
- private void recordAddContext(Context context, Container container)
- {
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getName()).andReturn("host");
-
- EasyMock.expect(context.isStarted()).andReturn(false);
- }
-
@Test
- public void startContext() throws IOException
+ public void startContextNoInit()
{
Context context = EasyMock.createStrictMock(Context.class);
@@ -325,54 +330,53 @@
EasyMock.verify(context);
EasyMock.reset(context);
+ }
+/*
+ @Test
+ public void startContextIgnored() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
init();
-
- // Test initialized
- Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ // Test ignored context
+ EasyMock.expect(context.getPath()).andReturn("/ignored");
+
+ EasyMock.replay(context);
+
+ this.handler.startContext(context);
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+ }
+*/
+ @Test
+ public void startContext() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
Host host = EasyMock.createStrictMock(Host.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
+ MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
+
+ init();
+
// Expect log message
EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(this.requestFactory.createEnableRequest(context)).andReturn(request);
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ this.mcmpHandler.sendRequest(request);
- EasyMock.replay(this.mcmpHandler, context, engine, host);
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, context, host);
this.handler.startContext(context);
- EasyMock.verify(this.mcmpHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.mcmpHandler, context, engine, host);
+ EasyMock.verify(this.mcmpHandler, this.requestFactory, context, host);
}
@Test
- public void stopContext() throws IOException
+ public void stopContextNoInit()
{
Context context = EasyMock.createStrictMock(Context.class);
@@ -392,54 +396,53 @@
EasyMock.verify(context);
EasyMock.reset(context);
-
+ }
+/*
+ @Test
+ public void stopContextIgnored() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
init();
-
- // Test initialized
- Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ // Test ignored context
+ EasyMock.expect(context.getPath()).andReturn("/ignored");
+
+ EasyMock.replay(context);
+
+ this.handler.stopContext(context);
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+ }
+*/
+ @Test
+ public void stopContext() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+ MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
Host host = EasyMock.createStrictMock(Host.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ init();
+
// Expect log message
EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(this.requestFactory.createStopRequest(context)).andReturn(request);
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ this.mcmpHandler.sendRequest(request);
- EasyMock.replay(this.mcmpHandler, context, engine, host);
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, context, host);
this.handler.stopContext(context);
- EasyMock.verify(this.mcmpHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.mcmpHandler, context, engine, host);
+ EasyMock.verify(this.mcmpHandler, this.requestFactory, context, host);
}
@Test
- public void removeContext() throws IOException
+ public void removeContextNoInit()
{
Context context = EasyMock.createStrictMock(Context.class);
@@ -459,26 +462,63 @@
EasyMock.verify(context);
EasyMock.reset(context);
+ }
+/*
+ @Test
+ public void removeContextIgnored() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
init();
-
- // Test initialized - no jvm route
+
+ // Test ignored context
+ EasyMock.expect(context.getPath()).andReturn("/ignored");
+
+ EasyMock.replay(context);
+
+ this.handler.removeContext(context);
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+ }
+*/
+ @Test
+ public void removeContextNoJvmRoute() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
Host host = EasyMock.createStrictMock(Host.class);
- this.recordRemoveContext(context, host, engine);
+ init();
+
+ // Test initialized - no jvm route
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("parent-container");
+
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn(null);
+
EasyMock.replay(context, host, engine);
this.handler.removeContext(context);
EasyMock.verify(context, host, engine);
EasyMock.reset(context, host, engine);
+ }
+ @Test
+ public void removeContext() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
- // Test initialized - jvm route exists
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
+ init();
+
// Expect log message
EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(host);
@@ -489,53 +529,19 @@
EasyMock.expect(host.getParent()).andReturn(engine);
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(this.requestFactory.createRemoveRequest(context)).andReturn(request);
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ this.mcmpHandler.sendRequest(request);
- EasyMock.replay(this.mcmpHandler, context, engine, host);
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, context, engine, host);
this.handler.removeContext(context);
EasyMock.verify(this.mcmpHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.mcmpHandler, context, engine, host);
}
- private void recordRemoveContext(Context context, Container container, Engine engine)
- {
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getName()).andReturn("parent-container");
-
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn(null);
- }
-
@Test
- public void status() throws IOException
+ public void statusNoInit()
{
Engine engine = EasyMock.createStrictMock(Engine.class);
@@ -555,12 +561,16 @@
EasyMock.verify(engine);
EasyMock.reset(engine);
+ }
+ @Test
+ public void status() throws IOException
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
+
init();
- // Test initialized
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
// Expect log message
EasyMock.expect(engine.getName()).andReturn("engine");
@@ -569,30 +579,19 @@
EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ EasyMock.expect(this.requestFactory.createStatusRequest("host1", 10)).andReturn(request);
- EasyMock.replay(this.mcmpHandler, this.lbfProvider, engine);
+ this.mcmpHandler.sendRequest(request);
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, this.lbfProvider, engine);
+
this.handler.status(engine);
- EasyMock.verify(this.mcmpHandler, this.lbfProvider, engine);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.STATUS, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(1, parameters.size());
- Assert.assertEquals("10", parameters.get("Load"));
-
- EasyMock.reset(this.mcmpHandler, this.lbfProvider, engine);
+ EasyMock.verify(this.mcmpHandler, this.requestFactory, this.lbfProvider, engine);
}
@Test
- public void startServer() throws Exception
+ public void startServerNoInit()
{
Server server = EasyMock.createStrictMock(Server.class);
@@ -612,17 +611,22 @@
EasyMock.verify(server);
EasyMock.reset(server);
+ }
- init();
-
- // Test initialized
+ @Test
+ public void startServer() throws Exception
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
Host host = EasyMock.createStrictMock(Host.class);
Context context = EasyMock.createStrictMock(Context.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
Connector connector = new Connector("AJP/1.3");
+ init();
+
+ // Test initialized
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -635,70 +639,32 @@
Set<MCMPServerState> states = Collections.emptySet();
EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(engine.getService()).andReturn(service);
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+ EasyMock.expect(this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig)).andReturn(request);
- EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
- EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.nodeConfig.getFlushWait()).andReturn(1);
- EasyMock.expect(this.nodeConfig.getPing()).andReturn(2);
- EasyMock.expect(this.nodeConfig.getSmax()).andReturn(3);
- EasyMock.expect(this.nodeConfig.getTtl()).andReturn(4);
- EasyMock.expect(this.nodeConfig.getNodeTimeout()).andReturn(5);
- EasyMock.expect(this.nodeConfig.getBalancer()).andReturn("S");
-
- EasyMock.expect(this.balancerConfig.getStickySession()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getStickySessionRemove()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.balancerConfig.getStickySessionForce()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getWorkerTimeout()).andReturn(6);
- EasyMock.expect(this.balancerConfig.getMaxAttempts()).andReturn(7);
-
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ this.mcmpHandler.sendRequest(request);
EasyMock.expect(engine.findChildren()).andReturn(new Container[] { host });
EasyMock.expect(host.findChildren()).andReturn(new Container[] { context });
- this.recordAddContext(context, host);
- EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, host, context);
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
- this.handler.startServer(server);
+ EasyMock.expect(context.isStarted()).andReturn(false);
- EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, host, context);
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, server, service, engine, host, context);
- MCMPRequest request = capturedRequest.getValue();
+ this.handler.startServer(server);
- Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- 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"));
-
- EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, host, context);
+ EasyMock.verify(this.mcmpHandler, this.requestFactory, server, service, engine, host, context);
}
@Test
- public void stopServer() throws IOException
+ public void stopServerNoInit()
{
Server server = EasyMock.createStrictMock(Server.class);
+
+ EasyMock.replay(server);
// Test not initialized
try
@@ -712,42 +678,56 @@
// Expected
}
- init();
+ EasyMock.verify(server);
+ EasyMock.reset(server);
+ }
- // Test initialized
+ @Test
+ public void stopServer() throws IOException
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
- Container container = EasyMock.createStrictMock(Container.class);
+ Host host = EasyMock.createStrictMock(Host.class);
Context context = EasyMock.createStrictMock(Context.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
+ MCMPRequest contextRequest = EasyMock.createStrictMock(MCMPRequest.class);
+ MCMPRequest engineRequest = EasyMock.createStrictMock(MCMPRequest.class);
+
+ init();
+
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
- EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- this.recordRemoveContext(context, container, engine);
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { host });
+ EasyMock.expect(host.findChildren()).andReturn(new Container[] { context });
// Expect log message
- EasyMock.expect(engine.getName()).andReturn("engine");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
+ // jvm route null check
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ EasyMock.expect(this.requestFactory.createRemoveRequest(context)).andReturn(contextRequest);
- EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+ this.mcmpHandler.sendRequest(contextRequest);
- this.handler.stopServer(server);
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
-
- MCMPRequest request = capturedRequest.getValue();
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
+ EasyMock.expect(this.requestFactory.createRemoveRequest(engine)).andReturn(engineRequest);
- EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+ this.mcmpHandler.sendRequest(engineRequest);
+
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, server, service, engine, host, context);
+
+ this.handler.stopServer(server);
+
+ EasyMock.verify(this.mcmpHandler, this.requestFactory, server, service, engine, host, context);
}
}
\ No newline at end of file
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -28,7 +28,6 @@
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Service;
-import org.easymock.Capture;
import org.easymock.EasyMock;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
import org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProviderMBean;
@@ -36,7 +35,7 @@
import org.jboss.modcluster.load.metric.impl.ActiveSessionsLoadMetric;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPRequestType;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
import org.junit.Assert;
import org.junit.Test;
@@ -49,9 +48,10 @@
private static final ModClusterServiceTestCase.LifecycleServer server = ModClusterServiceTestCase.server;
private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
+ private final MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
private final LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
- private final ModClusterListener listener = new ModClusterListener(this.mcmpHandler, this.lifecycleListener);
+ private final ModClusterListener listener = new ModClusterListener(this.mcmpHandler, this.requestFactory, this.lifecycleListener);
@Test
public void createLoadBalanceFactorProvider()
@@ -183,31 +183,26 @@
{
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ EasyMock.expect(this.requestFactory.createEnableRequest(engine)).andReturn(request);
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ this.mcmpHandler.sendRequest(request);
+
EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.mcmpHandler, server, service, engine);
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, server, service, engine);
boolean result = this.listener.enable();
- EasyMock.verify(this.mcmpHandler, server, service, engine);
+ EasyMock.verify(this.mcmpHandler, this.requestFactory, server, service, engine);
Assert.assertTrue(result);
- MCMPRequest request = capturedRequest.getValue();
-
- 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);
+ EasyMock.reset(this.mcmpHandler, this.requestFactory, server);
}
@SuppressWarnings("boxing")
@@ -216,30 +211,25 @@
{
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ EasyMock.expect(this.requestFactory.createDisableRequest(engine)).andReturn(request);
+
+ this.mcmpHandler.sendRequest(request);
+
EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.mcmpHandler, server, service, engine);
+ EasyMock.replay(this.mcmpHandler, this.requestFactory, server, service, engine);
boolean result = this.listener.disable();
- EasyMock.verify(this.mcmpHandler, server, service, engine);
+ EasyMock.verify(this.mcmpHandler, this.requestFactory, server, service, engine);
Assert.assertTrue(result);
- MCMPRequest request = capturedRequest.getValue();
-
- 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);
+ EasyMock.reset(this.mcmpHandler, this.requestFactory, server);
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -28,12 +28,11 @@
import org.apache.catalina.Server;
import org.apache.catalina.ServerFactory;
import org.apache.catalina.Service;
-import org.easymock.Capture;
import org.easymock.EasyMock;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPRequestType;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
import org.junit.Assert;
import org.junit.Test;
@@ -52,8 +51,9 @@
private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
private final LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
private final LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
+ private final MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
- private final ModClusterService listener = new ModClusterService(this.mcmpHandler, this.lifecycleListener, this.lbfProvider);
+ private final ModClusterService listener = new ModClusterService(this.mcmpHandler, this.requestFactory, this.lifecycleListener, this.lbfProvider);
@Test
public void createLoadBalanceFactorProvider()
@@ -168,33 +168,28 @@
{
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
Assert.assertSame(server, ServerFactory.getServer());
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ EasyMock.expect(this.requestFactory.createEnableRequest(engine)).andReturn(request);
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ this.mcmpHandler.sendRequest(request);
+
EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.mcmpHandler, server, service, engine);
+ EasyMock.replay(this.requestFactory, this.mcmpHandler, server, service, engine);
boolean result = this.listener.enable();
- EasyMock.verify(this.mcmpHandler, server, service, engine);
+ EasyMock.verify(this.requestFactory, this.mcmpHandler, server, service, engine);
Assert.assertTrue(result);
- MCMPRequest request = capturedRequest.getValue();
-
- 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);
+ EasyMock.reset(this.requestFactory, this.mcmpHandler, server);
}
@SuppressWarnings("boxing")
@@ -203,33 +198,28 @@
{
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
Assert.assertSame(server, ServerFactory.getServer());
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ EasyMock.expect(this.requestFactory.createDisableRequest(engine)).andReturn(request);
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ this.mcmpHandler.sendRequest(request);
+
EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.mcmpHandler, server, service, engine);
+ EasyMock.replay(this.requestFactory, this.mcmpHandler, server, service, engine);
boolean result = this.listener.disable();
- EasyMock.verify(this.mcmpHandler, server, service, engine);
+ EasyMock.verify(this.requestFactory, this.mcmpHandler, server, service, engine);
Assert.assertTrue(result);
- MCMPRequest request = capturedRequest.getValue();
-
- 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);
+ EasyMock.reset(this.requestFactory, this.mcmpHandler, server);
}
public interface LifecycleServer extends Server, Lifecycle
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 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -43,7 +43,6 @@
import org.jboss.modcluster.ha.rpc.StringGroupRpcResponse;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPRequestType;
import org.jboss.modcluster.mcmp.MCMPServer;
import org.jboss.modcluster.mcmp.MCMPServerState;
import org.junit.Assert;
@@ -678,7 +677,7 @@
@Test
public void sendRequest() throws Exception
{
- MCMPRequest request = new MCMPRequest(MCMPRequestType.INFO, false, "route", Collections.singletonMap("name", "value"));
+ MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
// Test master use case
EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
Deleted: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -1,1035 +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.ha;
-
-import org.apache.catalina.Engine;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.ServerFactory;
-import org.apache.catalina.Service;
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.jboss.ha.framework.interfaces.ClusterNode;
-import org.jboss.ha.framework.interfaces.HAPartition;
-import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
-import org.jboss.modcluster.ModClusterServiceTestCase;
-import org.jboss.modcluster.config.BalancerConfiguration;
-import org.jboss.modcluster.config.MCMPHandlerConfiguration;
-import org.jboss.modcluster.config.NodeConfiguration;
-import org.jboss.modcluster.config.ha.HAConfiguration;
-import org.jboss.modcluster.ha.ClusteredMCMPHandler;
-import org.jboss.modcluster.ha.HAModClusterService;
-import org.jboss.modcluster.ha.HASingletonAwareResetRequestSource;
-import org.jboss.modcluster.load.LoadBalanceFactorProvider;
-import org.jboss.modcluster.mcmp.MCMPHandler;
-import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPRequestType;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Paul Ferraro
- *
- */
-@SuppressWarnings("boxing")
-public class HAModClusterListenerTestCase
-{
- private static final ModClusterServiceTestCase.LifecycleServer server = ModClusterServiceTestCase.server;
-
- private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
- private NodeConfiguration nodeConfig = EasyMock.createMock(NodeConfiguration.class);
- private BalancerConfiguration balancerConfig = EasyMock.createMock(BalancerConfiguration.class);
- private MCMPHandlerConfiguration mcmpConfig = EasyMock.createMock(MCMPHandlerConfiguration.class);
- private HAConfiguration haConfig = EasyMock.createMock(HAConfiguration.class);
- private MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
- private HASingletonAwareResetRequestSource resetRequestSource = EasyMock.createStrictMock(HASingletonAwareResetRequestSource.class);
- private ClusteredMCMPHandler clusteredMCMPHandler = EasyMock.createStrictMock(ClusteredMCMPHandler.class);
- private LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
- private HASingletonElectionPolicy electionPolicy = EasyMock.createStrictMock(HASingletonElectionPolicy.class);
- private ClusterNode node = EasyMock.createStrictMock(ClusterNode.class);
- private LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
-
- private static final boolean MASTER_PER_DOMAIN = true;
- private static final String SERVICE_HA_NAME = "myservice";
- private static final String DOMAIN = "domain";
-
- private HAModClusterService listener;
-
- @Before
- public void setUp() throws Exception
- {
- EasyMock.expect(this.haConfig.isMasterPerDomain()).andReturn(MASTER_PER_DOMAIN);
- EasyMock.expect(this.nodeConfig.getDomain()).andReturn(DOMAIN);
-
- EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node).times(2);
-
- EasyMock.replay(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
-
- this.listener = new HAModClusterService(this.partition, this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.haConfig, this.mcmpHandler, this.resetRequestSource, this.clusteredMCMPHandler, this.lifecycleListener, this.lbfProvider, this.electionPolicy);
- this.listener.setServiceHAName(SERVICE_HA_NAME);
-
- EasyMock.verify(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
- EasyMock.reset(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
- }
-
- @Test
- public void addProxy()
- {
- String host = "127.0.0.1";
- int port = 0;
-
- this.clusteredMCMPHandler.addProxy(host, port);
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- this.listener.addProxy(host, port);
-
- EasyMock.verify(this.clusteredMCMPHandler);
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void removeProxy()
- {
- String host = "127.0.0.1";
- int port = 0;
-
- this.clusteredMCMPHandler.removeProxy(host, port);
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- this.listener.removeProxy(host, port);
-
- EasyMock.verify(this.clusteredMCMPHandler);
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void getProxyConfiguration()
- {
- EasyMock.expect(this.clusteredMCMPHandler.getProxyConfiguration()).andReturn("configuration");
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- String result = this.listener.getProxyConfiguration();
-
- EasyMock.verify(this.clusteredMCMPHandler);
-
- Assert.assertEquals("configuration", result);
-
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void getProxyInfo()
- {
- EasyMock.expect(this.clusteredMCMPHandler.getProxyInfo()).andReturn("info");
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- String result = this.listener.getProxyInfo();
-
- EasyMock.verify(this.clusteredMCMPHandler);
-
- Assert.assertEquals("info", result);
-
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void reset()
- {
- this.clusteredMCMPHandler.reset();
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- this.listener.reset();
-
- EasyMock.verify(this.clusteredMCMPHandler);
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void refresh()
- {
- this.clusteredMCMPHandler.markProxiesInError();
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- this.listener.refresh();
-
- EasyMock.verify(this.clusteredMCMPHandler);
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void enable()
- {
- Service service = EasyMock.createStrictMock(Service.class);
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- Assert.assertSame(server, ServerFactory.getServer());
-
- EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
- EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
- EasyMock.expect(this.clusteredMCMPHandler.isProxyHealthOK()).andReturn(true);
-
- EasyMock.replay(this.clusteredMCMPHandler, server, service, engine);
-
- boolean result = this.listener.enable();
-
- EasyMock.verify(this.clusteredMCMPHandler, server, service, engine);
-
- Assert.assertTrue(result);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
-
- EasyMock.reset(this.clusteredMCMPHandler, server, service, engine);
- }
-
- @Test
- public void disable()
- {
- Service service = EasyMock.createStrictMock(Service.class);
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- Assert.assertSame(server, ServerFactory.getServer());
-
- EasyMock.expect(ModClusterServiceTestCase.server.findServices()).andReturn(new Service[] { service });
- EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
- EasyMock.expect(this.clusteredMCMPHandler.isProxyHealthOK()).andReturn(true);
-
- EasyMock.replay(this.clusteredMCMPHandler, server, service, engine);
-
- boolean result = this.listener.disable();
-
- EasyMock.verify(this.clusteredMCMPHandler, server, service, engine);
-
- Assert.assertTrue(result);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
-
- EasyMock.reset(this.clusteredMCMPHandler, server, service, engine);
- }
-
- @Test
- public void lifecycleEvent()
- {
- LifecycleEvent event = new LifecycleEvent(EasyMock.createMock(Lifecycle.class), Lifecycle.INIT_EVENT);
-
- this.lifecycleListener.lifecycleEvent(event);
-
- EasyMock.replay(this.lifecycleListener);
-
- this.listener.lifecycleEvent(event);
-
- EasyMock.verify(this.lifecycleListener);
- EasyMock.reset(this.lifecycleListener);
- }
-
- @Test
- public void createLoadBalanceFactorProvider()
- {
- LoadBalanceFactorProvider lbfProvider = this.listener.createLoadBalanceFactorProvider();
-
- Assert.assertSame(this.lbfProvider, lbfProvider);
- }
-
-/*
- @Test
- public void init() throws UnknownHostException
- {
- InetAddress localAddress = InetAddress.getLocalHost();
- String localHostName = localAddress.getHostName();
-
- AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
-
- // Test advertise = false
- EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
-
- this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
-
- EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.FALSE);
-
- EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
-
- this.listener.init();
-
- EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
- EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
-
-
- // Test advertise = null, proxies configured
- EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
-
- this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
-
- EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
-
- EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
-
- this.listener.init();
-
- EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
- EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
- }
-
- @Test
- public void startServer() throws Exception
- {
- Server server = EasyMock.createStrictMock(Server.class);
-
- this.resetRequestSource.setJbossWebServer(server);
-
- EasyMock.replay(this.resetRequestSource);
-
- // Test not initialized
- try
- {
- this.listener.startServer(server);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(this.resetRequestSource);
- EasyMock.reset(this.resetRequestSource);
-
- init();
-
- // Test initialized
- Service service = EasyMock.createStrictMock(Service.class);
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Container container = EasyMock.createStrictMock(Container.class);
- Context context = EasyMock.createStrictMock(Context.class);
- DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
- Connector connector = new Connector("AJP/1.3");
-
- this.resetRequestSource.setJbossWebServer(server);
-
- EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
-
- EasyMock.expect(service.getContainer()).andReturn(engine);
-
- // Expect log message
- EasyMock.expect(engine.getName()).andReturn("engine");
-
- EasyMock.expect(engine.getService()).andReturn(service);
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
- EasyMock.expect(engine.getJvmRoute()).andReturn(null);
- Set<MCMPServerState> states = Collections.emptySet();
- EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("route");
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- drm.add("myservice:domain", this.listener.drmEntry);
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(engine.getService()).andReturn(service);
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
-
- EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
- EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.nodeConfig.getFlushWait()).andReturn(1);
- EasyMock.expect(this.nodeConfig.getPing()).andReturn(2);
- EasyMock.expect(this.nodeConfig.getSmax()).andReturn(3);
- EasyMock.expect(this.nodeConfig.getTtl()).andReturn(4);
- EasyMock.expect(this.nodeConfig.getNodeTimeout()).andReturn(5);
- EasyMock.expect(this.nodeConfig.getBalancer()).andReturn("S");
-
- EasyMock.expect(this.balancerConfig.getStickySession()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getStickySessionRemove()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.balancerConfig.getStickySessionForce()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getWorkerTimeout()).andReturn(6);
- EasyMock.expect(this.balancerConfig.getMaxAttempts()).andReturn(7);
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
- EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- this.recordAddContext(context, container);
-
- EasyMock.replay(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
-
- this.listener.startServer(server);
-
- EasyMock.verify(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Map<String, String> parameters = request.getParameters();
-
- 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.listener.drmEntry.getJvmRoutes();
- Assert.assertEquals(1, routes.size());
- Assert.assertEquals("route", routes.iterator().next());
-
- 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)
- {
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getName()).andReturn("parent-container");
-
- EasyMock.expect(context.isStarted()).andReturn(false);
- }
-
- @Test
- public void stopServer() throws Exception
- {
- Server server = EasyMock.createStrictMock(Server.class);
-
- // Test not initialized
- try
- {
- this.listener.stopServer(server);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- init();
-
- this.listener.drmEntry.addJvmRoute("route");
-
- // Test initialized
- Service service = EasyMock.createStrictMock(Service.class);
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Container container = EasyMock.createStrictMock(Container.class);
- Context context = EasyMock.createStrictMock(Context.class);
- DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
- EasyMock.expect(service.getContainer()).andReturn(engine);
-
- // Expect log message
- EasyMock.expect(engine.getName()).andReturn("engine");
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("route");
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- drm.add("myservice:domain", this.listener.drmEntry);
-
- EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
- EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- this.recordRemoveContext(context, container, engine);
-
- EasyMock.replay(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
-
- this.listener.stopServer(server);
-
- EasyMock.verify(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
-
- Assert.assertTrue(this.listener.drmEntry.getJvmRoutes().isEmpty());
-
- EasyMock.reset(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
- }
-
- private void recordRemoveContext(Context context, Container container, Engine engine)
- {
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getName()).andReturn("parent-container");
-
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn(null);
- }
-
- @Test
- public void addContext() throws UnknownHostException
- {
- Context context = EasyMock.createStrictMock(Context.class);
-
- EasyMock.replay(context);
-
- // Test not initialized
- try
- {
- this.listener.addContext(context);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(context);
- EasyMock.reset(context);
-
- init();
-
- // Test context not started
- Host host = EasyMock.createStrictMock(Host.class);
-
- recordAddContext(context, host);
-
- EasyMock.replay(context, host);
-
- this.listener.addContext(context);
-
- EasyMock.verify(context, host);
- EasyMock.reset(context, host);
-
- // Test context started
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
-
- EasyMock.expect(context.isStarted()).andReturn(true);
-
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
-
- this.listener.addContext(context);
-
- EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
- }
-
- @Test
- public void startContext() throws UnknownHostException
- {
- Context context = EasyMock.createStrictMock(Context.class);
-
- EasyMock.replay(context);
-
- // Test not initialized
- try
- {
- this.listener.startContext(context);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(context);
- EasyMock.reset(context);
-
- init();
-
- // Test initialized
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Host host = EasyMock.createStrictMock(Host.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
-
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
-
- this.listener.startContext(context);
-
- EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
- }
-
- @Test
- public void stopContext() throws UnknownHostException
- {
- Context context = EasyMock.createStrictMock(Context.class);
-
- EasyMock.replay(context);
-
- // Test not initialized
- try
- {
- this.listener.stopContext(context);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(context);
- EasyMock.reset(context);
-
- init();
-
- // Test initialized
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Host host = EasyMock.createStrictMock(Host.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
-
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
-
- this.listener.stopContext(context);
-
- EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
- }
-
- @Test
- public void removeContext() throws UnknownHostException
- {
- Context context = EasyMock.createStrictMock(Context.class);
-
- // Test not initialized
- try
- {
- this.listener.removeContext(context);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- init();
-
- // Test initialized - no jvm route
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Host host = EasyMock.createStrictMock(Host.class);
-
- this.recordRemoveContext(context, host, engine);
-
- EasyMock.replay(context, host, engine);
-
- this.listener.removeContext(context);
-
- EasyMock.verify(context, host, engine);
- EasyMock.reset(context, host, engine);
-
-
- // Test initialized - jvm route exists
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
-
- // jvm route null check
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
-
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
-
- this.listener.removeContext(context);
-
- EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void status() throws Exception
- {
- Engine engine = EasyMock.createStrictMock(Engine.class);
-
- EasyMock.replay(engine);
-
- // Test not initialized
- try
- {
- this.listener.status(engine);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(engine);
- EasyMock.reset(engine);
-
- init();
-
- // Test non-master status
- EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
-
- EasyMock.replay(this.lbfProvider, engine);
-
- this.listener.status(engine);
-
- EasyMock.verify(this.lbfProvider, engine);
- EasyMock.reset(this.lbfProvider, engine);
-
-
- // Make master
- String key = SERVICE_HA_NAME + ":" + DOMAIN;
- DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
-
- this.listener.setElectionPolicy(null);
-
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- EasyMock.expect(drm.isMasterReplica(key)).andReturn(true);
-
- this.partition.callAsynchMethodOnCluster(EasyMock.eq("myservice"), EasyMock.eq("stopOldMaster"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new Class[0]), EasyMock.eq(true));
-
- EasyMock.replay(this.partition, drm);
-
- this.listener.replicantsChanged(key, Collections.EMPTY_LIST, 1, false);
-
- EasyMock.verify(this.partition, drm);
-
- Assert.assertTrue(this.listener.isMasterNode());
-
- EasyMock.reset(this.partition, drm);
-
- // Create drm entries
- ClusterNode remoteNode1 = EasyMock.createMock(ClusterNode.class);
- MCMPServerState remoteState1 = EasyMock.createMock(MCMPServerState.class);
-
- EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
- EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
-
- EasyMock.replay(remoteState1);
-
- ModClusterServiceDRMEntry drmEntry1 = new ModClusterServiceDRMEntry(remoteNode1, Collections.singleton(remoteState1));
- drmEntry1.addJvmRoute("host1");
-
- EasyMock.verify(remoteState1);
- EasyMock.reset(remoteState1);
-
-
- MCMPServerState remoteState2 = EasyMock.createMock(MCMPServerState.class);
- ClusterNode remoteNode2 = EasyMock.createMock(ClusterNode.class);
-
- EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
- EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
-
- EasyMock.replay(remoteState2);
-
- ModClusterServiceDRMEntry drmEntry2 = new ModClusterServiceDRMEntry(remoteNode2, Collections.singleton(remoteState2));
- drmEntry2.addJvmRoute("host2");
-
- EasyMock.verify(remoteState2);
- EasyMock.reset(remoteState2);
-
- // Test master status
- MCMPServerState localState = EasyMock.createMock(MCMPServerState.class);
- ModClusterServiceDRMEntry drmEntry = new ModClusterServiceDRMEntry(this.node, null);
- InetAddress address1 = InetAddress.getByName("127.0.0.1");
- InetAddress address2 = InetAddress.getByName("127.0.1.1");
- MCMPServerDiscoveryEvent event1 = new MCMPServerDiscoveryEvent(remoteNode1, new AddressPort(address1, 1), true, 1);
- MCMPServerDiscoveryEvent event2 = new MCMPServerDiscoveryEvent(remoteNode2, new AddressPort(address2, 2), false, 2);
-
- Map<String, String> emptyMap = Collections.emptyMap();
- MCMPRequest request1 = new MCMPRequest(MCMPRequestType.ENABLE_APP, false, "route", emptyMap);
- MCMPRequest request2 = new MCMPRequest(MCMPRequestType.DISABLE_APP, false, "route", emptyMap);
- Capture<List<MCMPRequest>> capturedRequests = new Capture<List<MCMPRequest>>();
- Capture<ModClusterServiceDRMEntry> capturedEntry = new Capture<ModClusterServiceDRMEntry>();
- Capture<Object[]> capturedArgs = new Capture<Object[]>();
-
- ModClusterServiceStateGroupRpcResponse response1 = new ModClusterServiceStateGroupRpcResponse(remoteNode1, 10, new TreeSet<MCMPServerState>(), Collections.singletonList(event1), new ArrayList<MCMPRequest>());
- ModClusterServiceStateGroupRpcResponse response2 = new ModClusterServiceStateGroupRpcResponse(remoteNode2, 20, new TreeSet<MCMPServerState>(), Collections.singletonList(event2), new ArrayList<MCMPRequest>());
-
- EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
-
- this.mcmpHandler.status();
-
- EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(new TreeSet<MCMPServerState>());
-
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- EasyMock.expect(drm.lookupReplicants(key)).andReturn(Collections.singletonList(drmEntry));
- EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
- EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(SERVICE_HA_NAME), EasyMock.eq("getClusterCoordinatorState"), EasyMock.aryEq(new Object[] { new TreeSet<MCMPServerState>() }), EasyMock.aryEq(new Class[] { Set.class }), EasyMock.eq(true))).andReturn(new ArrayList<Object>(Arrays.asList(response1, response2)));
-
- // Process discovery events
- this.mcmpHandler.addProxy(address1, 1);
- this.mcmpHandler.removeProxy(address2, 2);
-
- // Start over - this time with no discovery events
- response1 = new ModClusterServiceStateGroupRpcResponse(remoteNode1, 10, Collections.singleton(remoteState1), new ArrayList<MCMPServerDiscoveryEvent>(), Collections.singletonList(request1));
- response2 = new ModClusterServiceStateGroupRpcResponse(remoteNode2, 20, Collections.singleton(remoteState2), new ArrayList<MCMPServerDiscoveryEvent>(), Collections.singletonList(request2));
-
- this.mcmpHandler.status();
-
- Set<MCMPServerState> states = new LinkedHashSet<MCMPServerState>(Arrays.asList(remoteState1, remoteState2));
-
- EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
-
- EasyMock.expect(drm.lookupReplicants(key)).andReturn(Arrays.asList(drmEntry1, drmEntry2));
- EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
- EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(SERVICE_HA_NAME), EasyMock.eq("getClusterCoordinatorState"), EasyMock.aryEq(new Object[] { states }), EasyMock.aryEq(new Class[] { Set.class }), EasyMock.eq(true))).andReturn(new ArrayList<Object>(Arrays.asList(response1, response2)));
-
- EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
- EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
- EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
- EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
-
- this.mcmpHandler.sendRequests(Arrays.asList(request1, request2));
- this.mcmpHandler.sendRequests(EasyMock.capture(capturedRequests));
-
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- EasyMock.expect(drm.lookupLocalReplicant(key)).andReturn(drmEntry);
-
- EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
-
- EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
- EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
- EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
- EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
-
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
-
- drm.add(EasyMock.eq(key), EasyMock.capture(capturedEntry));
-
- EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq("myservice"), EasyMock.eq("clusterStatusComplete"), EasyMock.capture(capturedArgs), EasyMock.aryEq(new Class[] { Map.class }), EasyMock.eq(true))).andReturn(null);
-
- EasyMock.replay(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
-
- this.listener.status(engine);
-
- EasyMock.verify(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
-
- List<MCMPRequest> requests = capturedRequests.getValue();
-
- Assert.assertEquals(2, requests.size());
-
- 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"));
-
- 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();
-
- Assert.assertSame(this.node, entry.getPeer());
- Assert.assertEquals(states, entry.getMCMPServerStates());
- Assert.assertTrue(entry.getJvmRoutes().isEmpty());
-
- Object[] args = capturedArgs.getValue();
- Assert.assertEquals(1, args.length);
- Assert.assertTrue(args[0] instanceof Map);
-
- Map<ClusterNode, PeerMCMPDiscoveryStatus> map = (Map<ClusterNode, PeerMCMPDiscoveryStatus>) args[0];
-
- Assert.assertEquals(2, map.size());
- Assert.assertTrue(map.containsKey(remoteNode1));
- Assert.assertTrue(map.containsKey(remoteNode2));
-
- PeerMCMPDiscoveryStatus status1 = map.get(remoteNode1);
-
- 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);
-
-
- // Test master status, but off-frequency
- this.listener.setProcessStatusFrequency(2);
-
- EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
-
- EasyMock.replay(this.lbfProvider, engine);
-
- this.listener.status(engine);
-
- EasyMock.verify(this.lbfProvider, engine);
- EasyMock.reset(this.lbfProvider, engine);
- }
-*/
-}
Copied: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterServiceTestCase.java (from rev 2187, trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java)
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterServiceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterServiceTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -0,0 +1,1022 @@
+/*
+ * 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.ha;
+
+import org.apache.catalina.Engine;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.easymock.EasyMock;
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
+import org.jboss.modcluster.ModClusterServiceTestCase;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.MCMPHandlerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.config.ha.HAConfiguration;
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+@SuppressWarnings("boxing")
+public class HAModClusterServiceTestCase
+{
+ private static final ModClusterServiceTestCase.LifecycleServer server = ModClusterServiceTestCase.server;
+
+ private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
+ private NodeConfiguration nodeConfig = EasyMock.createMock(NodeConfiguration.class);
+ private BalancerConfiguration balancerConfig = EasyMock.createMock(BalancerConfiguration.class);
+ private MCMPHandlerConfiguration mcmpConfig = EasyMock.createMock(MCMPHandlerConfiguration.class);
+ private HAConfiguration haConfig = EasyMock.createMock(HAConfiguration.class);
+ private MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
+ private HASingletonAwareResetRequestSource resetRequestSource = EasyMock.createStrictMock(HASingletonAwareResetRequestSource.class);
+ private ClusteredMCMPHandler clusteredMCMPHandler = EasyMock.createStrictMock(ClusteredMCMPHandler.class);
+ private LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
+ private HASingletonElectionPolicy electionPolicy = EasyMock.createStrictMock(HASingletonElectionPolicy.class);
+ private ClusterNode node = EasyMock.createStrictMock(ClusterNode.class);
+ private LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
+ private MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
+
+ private static final boolean MASTER_PER_DOMAIN = true;
+ private static final String SERVICE_HA_NAME = "myservice";
+ private static final String DOMAIN = "domain";
+
+ private HAModClusterService service;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ EasyMock.expect(this.haConfig.isMasterPerDomain()).andReturn(MASTER_PER_DOMAIN);
+ EasyMock.expect(this.nodeConfig.getDomain()).andReturn(DOMAIN);
+
+ EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node).times(2);
+
+ EasyMock.replay(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
+
+ this.service = new HAModClusterService(this.partition, this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.haConfig, this.mcmpHandler, this.requestFactory, this.resetRequestSource, this.clusteredMCMPHandler, this.lifecycleListener, this.lbfProvider, this.electionPolicy);
+ this.service.setServiceHAName(SERVICE_HA_NAME);
+
+ EasyMock.verify(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
+ EasyMock.reset(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
+ }
+
+ @Test
+ public void addProxy()
+ {
+ String host = "127.0.0.1";
+ int port = 0;
+
+ this.clusteredMCMPHandler.addProxy(host, port);
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ this.service.addProxy(host, port);
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void removeProxy()
+ {
+ String host = "127.0.0.1";
+ int port = 0;
+
+ this.clusteredMCMPHandler.removeProxy(host, port);
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ this.service.removeProxy(host, port);
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void getProxyConfiguration()
+ {
+ EasyMock.expect(this.clusteredMCMPHandler.getProxyConfiguration()).andReturn("configuration");
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ String result = this.service.getProxyConfiguration();
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+
+ Assert.assertEquals("configuration", result);
+
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void getProxyInfo()
+ {
+ EasyMock.expect(this.clusteredMCMPHandler.getProxyInfo()).andReturn("info");
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ String result = this.service.getProxyInfo();
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+
+ Assert.assertEquals("info", result);
+
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void reset()
+ {
+ this.clusteredMCMPHandler.reset();
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ this.service.reset();
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void refresh()
+ {
+ this.clusteredMCMPHandler.markProxiesInError();
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ this.service.refresh();
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void enable()
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
+
+ Assert.assertSame(server, ServerFactory.getServer());
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ EasyMock.expect(this.requestFactory.createEnableRequest(engine)).andReturn(request);
+
+ this.clusteredMCMPHandler.sendRequest(request);
+
+ EasyMock.expect(this.clusteredMCMPHandler.isProxyHealthOK()).andReturn(true);
+
+ EasyMock.replay(this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
+
+ boolean result = this.service.enable();
+
+ EasyMock.verify(this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
+
+ Assert.assertTrue(result);
+
+ EasyMock.reset(this.requestFactory, this.clusteredMCMPHandler, server);
+ }
+
+ @Test
+ public void disable()
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
+
+ Assert.assertSame(server, ServerFactory.getServer());
+
+ EasyMock.expect(ModClusterServiceTestCase.server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ EasyMock.expect(this.requestFactory.createDisableRequest(engine)).andReturn(request);
+
+ this.clusteredMCMPHandler.sendRequest(request);
+
+ EasyMock.expect(this.clusteredMCMPHandler.isProxyHealthOK()).andReturn(true);
+
+ EasyMock.replay(this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
+
+ boolean result = this.service.disable();
+
+ EasyMock.verify(this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
+
+ Assert.assertTrue(result);
+
+ EasyMock.reset(this.requestFactory, this.clusteredMCMPHandler, server);
+ }
+
+ @Test
+ public void lifecycleEvent()
+ {
+ LifecycleEvent event = new LifecycleEvent(EasyMock.createMock(Lifecycle.class), Lifecycle.INIT_EVENT);
+
+ this.lifecycleListener.lifecycleEvent(event);
+
+ EasyMock.replay(this.lifecycleListener);
+
+ this.service.lifecycleEvent(event);
+
+ EasyMock.verify(this.lifecycleListener);
+ EasyMock.reset(this.lifecycleListener);
+ }
+
+ @Test
+ public void createLoadBalanceFactorProvider()
+ {
+ LoadBalanceFactorProvider lbfProvider = this.service.createLoadBalanceFactorProvider();
+
+ Assert.assertSame(this.lbfProvider, lbfProvider);
+ }
+
+/*
+ @Test
+ public void init() throws UnknownHostException
+ {
+ InetAddress localAddress = InetAddress.getLocalHost();
+ String localHostName = localAddress.getHostName();
+
+ AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
+
+ // Test advertise = false
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
+
+ this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.FALSE);
+
+ EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+
+ this.listener.init();
+
+ EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+ EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+
+
+ // Test advertise = null, proxies configured
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
+
+ this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
+
+ EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+
+ this.listener.init();
+
+ EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+ EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+ }
+
+ @Test
+ public void startServer() throws Exception
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
+
+ this.resetRequestSource.setJbossWebServer(server);
+
+ EasyMock.replay(this.resetRequestSource);
+
+ // Test not initialized
+ try
+ {
+ this.listener.startServer(server);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(this.resetRequestSource);
+ EasyMock.reset(this.resetRequestSource);
+
+ init();
+
+ // Test initialized
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ Context context = EasyMock.createStrictMock(Context.class);
+ DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ Connector connector = new Connector("AJP/1.3");
+
+ this.resetRequestSource.setJbossWebServer(server);
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
+
+ EasyMock.expect(engine.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+ EasyMock.expect(engine.getJvmRoute()).andReturn(null);
+ Set<MCMPServerState> states = Collections.emptySet();
+ EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("route");
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ drm.add("myservice:domain", this.listener.drmEntry);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(engine.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+
+ EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
+ EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
+ EasyMock.expect(this.nodeConfig.getFlushWait()).andReturn(1);
+ EasyMock.expect(this.nodeConfig.getPing()).andReturn(2);
+ EasyMock.expect(this.nodeConfig.getSmax()).andReturn(3);
+ EasyMock.expect(this.nodeConfig.getTtl()).andReturn(4);
+ EasyMock.expect(this.nodeConfig.getNodeTimeout()).andReturn(5);
+ EasyMock.expect(this.nodeConfig.getBalancer()).andReturn("S");
+
+ EasyMock.expect(this.balancerConfig.getStickySession()).andReturn(Boolean.FALSE);
+ EasyMock.expect(this.balancerConfig.getStickySessionRemove()).andReturn(Boolean.TRUE);
+ EasyMock.expect(this.balancerConfig.getStickySessionForce()).andReturn(Boolean.FALSE);
+ EasyMock.expect(this.balancerConfig.getWorkerTimeout()).andReturn(6);
+ EasyMock.expect(this.balancerConfig.getMaxAttempts()).andReturn(7);
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
+ this.recordAddContext(context, container);
+
+ EasyMock.replay(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ this.listener.startServer(server);
+
+ EasyMock.verify(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Map<String, String> parameters = request.getParameters();
+
+ 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.listener.drmEntry.getJvmRoutes();
+ Assert.assertEquals(1, routes.size());
+ Assert.assertEquals("route", routes.iterator().next());
+
+ 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)
+ {
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ EasyMock.expect(context.isStarted()).andReturn(false);
+ }
+
+ @Test
+ public void stopServer() throws Exception
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
+
+ // Test not initialized
+ try
+ {
+ this.listener.stopServer(server);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ init();
+
+ this.listener.drmEntry.addJvmRoute("route");
+
+ // Test initialized
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ Context context = EasyMock.createStrictMock(Context.class);
+ DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("route");
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ drm.add("myservice:domain", this.listener.drmEntry);
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
+ this.recordRemoveContext(context, container, engine);
+
+ EasyMock.replay(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ this.listener.stopServer(server);
+
+ EasyMock.verify(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+
+ Assert.assertTrue(this.listener.drmEntry.getJvmRoutes().isEmpty());
+
+ EasyMock.reset(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+ }
+
+ private void recordRemoveContext(Context context, Container container, Engine engine)
+ {
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn(null);
+ }
+
+ @Test
+ public void addContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ EasyMock.replay(context);
+
+ // Test not initialized
+ try
+ {
+ this.listener.addContext(context);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
+
+ // Test context not started
+ Host host = EasyMock.createStrictMock(Host.class);
+
+ recordAddContext(context, host);
+
+ EasyMock.replay(context, host);
+
+ this.listener.addContext(context);
+
+ EasyMock.verify(context, host);
+ EasyMock.reset(context, host);
+
+ // Test context started
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ EasyMock.expect(context.isStarted()).andReturn(true);
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
+
+ this.listener.addContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
+ }
+
+ @Test
+ public void startContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ EasyMock.replay(context);
+
+ // Test not initialized
+ try
+ {
+ this.listener.startContext(context);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
+
+ // Test initialized
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
+
+ this.listener.startContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
+ }
+
+ @Test
+ public void stopContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ EasyMock.replay(context);
+
+ // Test not initialized
+ try
+ {
+ this.listener.stopContext(context);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
+
+ // Test initialized
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
+
+ this.listener.stopContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
+ }
+
+ @Test
+ public void removeContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ // Test not initialized
+ try
+ {
+ this.listener.removeContext(context);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ init();
+
+ // Test initialized - no jvm route
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+
+ this.recordRemoveContext(context, host, engine);
+
+ EasyMock.replay(context, host, engine);
+
+ this.listener.removeContext(context);
+
+ EasyMock.verify(context, host, engine);
+ EasyMock.reset(context, host, engine);
+
+
+ // Test initialized - jvm route exists
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ // jvm route null check
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
+
+ this.listener.removeContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void status() throws Exception
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.replay(engine);
+
+ // Test not initialized
+ try
+ {
+ this.listener.status(engine);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(engine);
+ EasyMock.reset(engine);
+
+ init();
+
+ // Test non-master status
+ EasyMock.expect(engine.getName()).andReturn("engine");
+ EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
+
+ EasyMock.replay(this.lbfProvider, engine);
+
+ this.listener.status(engine);
+
+ EasyMock.verify(this.lbfProvider, engine);
+ EasyMock.reset(this.lbfProvider, engine);
+
+
+ // Make master
+ String key = SERVICE_HA_NAME + ":" + DOMAIN;
+ DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
+
+ this.listener.setElectionPolicy(null);
+
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ EasyMock.expect(drm.isMasterReplica(key)).andReturn(true);
+
+ this.partition.callAsynchMethodOnCluster(EasyMock.eq("myservice"), EasyMock.eq("stopOldMaster"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new Class[0]), EasyMock.eq(true));
+
+ EasyMock.replay(this.partition, drm);
+
+ this.listener.replicantsChanged(key, Collections.EMPTY_LIST, 1, false);
+
+ EasyMock.verify(this.partition, drm);
+
+ Assert.assertTrue(this.listener.isMasterNode());
+
+ EasyMock.reset(this.partition, drm);
+
+ // Create drm entries
+ ClusterNode remoteNode1 = EasyMock.createMock(ClusterNode.class);
+ MCMPServerState remoteState1 = EasyMock.createMock(MCMPServerState.class);
+
+ EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
+ EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
+
+ EasyMock.replay(remoteState1);
+
+ ModClusterServiceDRMEntry drmEntry1 = new ModClusterServiceDRMEntry(remoteNode1, Collections.singleton(remoteState1));
+ drmEntry1.addJvmRoute("host1");
+
+ EasyMock.verify(remoteState1);
+ EasyMock.reset(remoteState1);
+
+
+ MCMPServerState remoteState2 = EasyMock.createMock(MCMPServerState.class);
+ ClusterNode remoteNode2 = EasyMock.createMock(ClusterNode.class);
+
+ EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
+ EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
+
+ EasyMock.replay(remoteState2);
+
+ ModClusterServiceDRMEntry drmEntry2 = new ModClusterServiceDRMEntry(remoteNode2, Collections.singleton(remoteState2));
+ drmEntry2.addJvmRoute("host2");
+
+ EasyMock.verify(remoteState2);
+ EasyMock.reset(remoteState2);
+
+ // Test master status
+ MCMPServerState localState = EasyMock.createMock(MCMPServerState.class);
+ ModClusterServiceDRMEntry drmEntry = new ModClusterServiceDRMEntry(this.node, null);
+ InetAddress address1 = InetAddress.getByName("127.0.0.1");
+ InetAddress address2 = InetAddress.getByName("127.0.1.1");
+ MCMPServerDiscoveryEvent event1 = new MCMPServerDiscoveryEvent(remoteNode1, new AddressPort(address1, 1), true, 1);
+ MCMPServerDiscoveryEvent event2 = new MCMPServerDiscoveryEvent(remoteNode2, new AddressPort(address2, 2), false, 2);
+
+ Map<String, String> emptyMap = Collections.emptyMap();
+ MCMPRequest request1 = new MCMPRequest(MCMPRequestType.ENABLE_APP, false, "route", emptyMap);
+ MCMPRequest request2 = new MCMPRequest(MCMPRequestType.DISABLE_APP, false, "route", emptyMap);
+ Capture<List<MCMPRequest>> capturedRequests = new Capture<List<MCMPRequest>>();
+ Capture<ModClusterServiceDRMEntry> capturedEntry = new Capture<ModClusterServiceDRMEntry>();
+ Capture<Object[]> capturedArgs = new Capture<Object[]>();
+
+ ModClusterServiceStateGroupRpcResponse response1 = new ModClusterServiceStateGroupRpcResponse(remoteNode1, 10, new TreeSet<MCMPServerState>(), Collections.singletonList(event1), new ArrayList<MCMPRequest>());
+ ModClusterServiceStateGroupRpcResponse response2 = new ModClusterServiceStateGroupRpcResponse(remoteNode2, 20, new TreeSet<MCMPServerState>(), Collections.singletonList(event2), new ArrayList<MCMPRequest>());
+
+ EasyMock.expect(engine.getName()).andReturn("engine");
+ EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
+
+ this.mcmpHandler.status();
+
+ EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(new TreeSet<MCMPServerState>());
+
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ EasyMock.expect(drm.lookupReplicants(key)).andReturn(Collections.singletonList(drmEntry));
+ EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
+ EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(SERVICE_HA_NAME), EasyMock.eq("getClusterCoordinatorState"), EasyMock.aryEq(new Object[] { new TreeSet<MCMPServerState>() }), EasyMock.aryEq(new Class[] { Set.class }), EasyMock.eq(true))).andReturn(new ArrayList<Object>(Arrays.asList(response1, response2)));
+
+ // Process discovery events
+ this.mcmpHandler.addProxy(address1, 1);
+ this.mcmpHandler.removeProxy(address2, 2);
+
+ // Start over - this time with no discovery events
+ response1 = new ModClusterServiceStateGroupRpcResponse(remoteNode1, 10, Collections.singleton(remoteState1), new ArrayList<MCMPServerDiscoveryEvent>(), Collections.singletonList(request1));
+ response2 = new ModClusterServiceStateGroupRpcResponse(remoteNode2, 20, Collections.singleton(remoteState2), new ArrayList<MCMPServerDiscoveryEvent>(), Collections.singletonList(request2));
+
+ this.mcmpHandler.status();
+
+ Set<MCMPServerState> states = new LinkedHashSet<MCMPServerState>(Arrays.asList(remoteState1, remoteState2));
+
+ EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
+
+ EasyMock.expect(drm.lookupReplicants(key)).andReturn(Arrays.asList(drmEntry1, drmEntry2));
+ EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
+ EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(SERVICE_HA_NAME), EasyMock.eq("getClusterCoordinatorState"), EasyMock.aryEq(new Object[] { states }), EasyMock.aryEq(new Class[] { Set.class }), EasyMock.eq(true))).andReturn(new ArrayList<Object>(Arrays.asList(response1, response2)));
+
+ EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
+ EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
+ EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
+ EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
+
+ this.mcmpHandler.sendRequests(Arrays.asList(request1, request2));
+ this.mcmpHandler.sendRequests(EasyMock.capture(capturedRequests));
+
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ EasyMock.expect(drm.lookupLocalReplicant(key)).andReturn(drmEntry);
+
+ EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
+
+ EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
+ EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
+ EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
+ EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
+
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+
+ drm.add(EasyMock.eq(key), EasyMock.capture(capturedEntry));
+
+ EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq("myservice"), EasyMock.eq("clusterStatusComplete"), EasyMock.capture(capturedArgs), EasyMock.aryEq(new Class[] { Map.class }), EasyMock.eq(true))).andReturn(null);
+
+ EasyMock.replay(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
+
+ this.listener.status(engine);
+
+ EasyMock.verify(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
+
+ List<MCMPRequest> requests = capturedRequests.getValue();
+
+ Assert.assertEquals(2, requests.size());
+
+ 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"));
+
+ 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();
+
+ Assert.assertSame(this.node, entry.getPeer());
+ Assert.assertEquals(states, entry.getMCMPServerStates());
+ Assert.assertTrue(entry.getJvmRoutes().isEmpty());
+
+ Object[] args = capturedArgs.getValue();
+ Assert.assertEquals(1, args.length);
+ Assert.assertTrue(args[0] instanceof Map);
+
+ Map<ClusterNode, PeerMCMPDiscoveryStatus> map = (Map<ClusterNode, PeerMCMPDiscoveryStatus>) args[0];
+
+ Assert.assertEquals(2, map.size());
+ Assert.assertTrue(map.containsKey(remoteNode1));
+ Assert.assertTrue(map.containsKey(remoteNode2));
+
+ PeerMCMPDiscoveryStatus status1 = map.get(remoteNode1);
+
+ 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);
+
+
+ // Test master status, but off-frequency
+ this.listener.setProcessStatusFrequency(2);
+
+ EasyMock.expect(engine.getName()).andReturn("engine");
+ EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
+
+ EasyMock.replay(this.lbfProvider, engine);
+
+ this.listener.status(engine);
+
+ EasyMock.verify(this.lbfProvider, engine);
+ EasyMock.reset(this.lbfProvider, engine);
+ }
+*/
+}
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 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -34,7 +34,6 @@
import org.apache.catalina.Host;
import org.apache.catalina.Server;
import org.apache.catalina.Service;
-import org.apache.catalina.connector.Connector;
import org.easymock.EasyMock;
import org.jboss.ha.framework.interfaces.ClusterNode;
import org.jboss.ha.framework.interfaces.HAPartition;
@@ -44,7 +43,7 @@
import org.jboss.modcluster.config.NodeConfiguration;
import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPRequestType;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
import org.jboss.modcluster.mcmp.ResetRequestSource;
import org.junit.Assert;
import org.junit.Test;
@@ -61,225 +60,182 @@
private HAServiceKeyProvider key = EasyMock.createStrictMock(HAServiceKeyProvider.class);
private HASingletonMBean singleton = EasyMock.createStrictMock(HASingletonMBean.class);
private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
+ private MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
- private HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.singleton, this.key);
+ @Test
+ public void getResetRequestsNonMaster()
+ {
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
+ EasyMock.replay(this.singleton);
+
+ Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
+
+ List<MCMPRequest> requests = source.getResetRequests(emptyResponseMap);
+
+ EasyMock.verify(this.singleton);
+
+ Assert.assertTrue(requests.isEmpty());
+
+ EasyMock.reset(this.singleton);
+ }
+
@Test
- public void getResetRequests() throws Exception
+ public void getResetRequestsNoServer() throws Exception
{
- Map<String, String> emptyMap = Collections.emptyMap();
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+
Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
- MCMPRequest request1 = new MCMPRequest(MCMPRequestType.ENABLE_APP, false, "host1", emptyMap);
- MCMPRequest request2 = new MCMPRequest(MCMPRequestType.REMOVE_APP, false, "host2", emptyMap);
+ MCMPRequest request1 = EasyMock.createMock(MCMPRequest.class);
+ MCMPRequest request2 = EasyMock.createMock(MCMPRequest.class);
ResetRequestGroupRpcResponse response1 = new ResetRequestGroupRpcResponse(EasyMock.createMock(ClusterNode.class), Collections.singletonList(request1));
ResetRequestGroupRpcResponse response2 = new ResetRequestGroupRpcResponse(EasyMock.createMock(ClusterNode.class), Collections.singletonList(request2));
- // Test master - w/out server
EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
EasyMock.expect(this.key.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.key.getHAServiceKey()).andReturn("service:domain");
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq("service:domain"), EasyMock.eq("getResetRequests"), EasyMock.aryEq(new Object[] { emptyResponseMap }), EasyMock.aryEq(new Class[] { Map.class }), EasyMock.eq(true))).andReturn(new ArrayList<ResetRequestGroupRpcResponse>(Arrays.asList(response1, response2)));
- EasyMock.replay(this.singleton, this.key, this.partition);
+ EasyMock.replay(this.key, this.singleton, this.partition);
- List<MCMPRequest> results = this.source.getResetRequests(emptyResponseMap);
+ List<MCMPRequest> results = source.getResetRequests(emptyResponseMap);
- EasyMock.verify(this.singleton, this.key, this.partition);
+ EasyMock.verify(this.key, this.singleton, this.partition);
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);
+ EasyMock.reset(this.key, this.singleton, this.partition);
+ }
+
+ @Test
+ public void getResetRequests() throws Exception
+ {
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+
+ Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
+ MCMPRequest request1 = EasyMock.createMock(MCMPRequest.class);
+ MCMPRequest request2 = EasyMock.createMock(MCMPRequest.class);
+ ResetRequestGroupRpcResponse response1 = new ResetRequestGroupRpcResponse(EasyMock.createMock(ClusterNode.class), Collections.singletonList(request1));
+ ResetRequestGroupRpcResponse response2 = new ResetRequestGroupRpcResponse(EasyMock.createMock(ClusterNode.class), Collections.singletonList(request2));
- // Test master - w/server
Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
Context context = EasyMock.createStrictMock(Context.class);
Host host = EasyMock.createStrictMock(Host.class);
- Connector connector = new Connector("AJP/1.3");
+ MCMPRequest configRequest = EasyMock.createStrictMock(MCMPRequest.class);
+ MCMPRequest contextRequest = EasyMock.createStrictMock(MCMPRequest.class);
- this.source.setJbossWebServer(server);
+ source.setJbossWebServer(server);
EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
- EasyMock.expect(this.key.getHAPartition()).andReturn(this.partition);
- EasyMock.expect(this.key.getHAServiceKey()).andReturn("service:domain");
- EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq("service:domain"), EasyMock.eq("getResetRequests"), EasyMock.aryEq(new Object[] { emptyResponseMap }), EasyMock.aryEq(new Class[] { Map.class }), EasyMock.eq(true))).andReturn(new ArrayList<ResetRequestGroupRpcResponse>(Arrays.asList(response1, response2)));
-
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ EasyMock.expect(this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig)).andReturn(configRequest);
+
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
- EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
- EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.nodeConfig.getFlushWait()).andReturn(1);
- EasyMock.expect(this.nodeConfig.getPing()).andReturn(2);
- EasyMock.expect(this.nodeConfig.getSmax()).andReturn(3);
- EasyMock.expect(this.nodeConfig.getTtl()).andReturn(4);
- EasyMock.expect(this.nodeConfig.getNodeTimeout()).andReturn(5);
- EasyMock.expect(this.nodeConfig.getBalancer()).andReturn("S");
-
- EasyMock.expect(this.balancerConfig.getStickySession()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getStickySessionRemove()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.balancerConfig.getStickySessionForce()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getWorkerTimeout()).andReturn(6);
- EasyMock.expect(this.balancerConfig.getMaxAttempts()).andReturn(7);
-
EasyMock.expect(engine.findChildren()).andReturn(new Container[] { host });
EasyMock.expect(host.getName()).andReturn("host").times(2);
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
EasyMock.expect(host.findChildren()).andReturn(new Container[] { context });
EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.isStarted()).andReturn(true);
-
- EasyMock.replay(this.singleton, this.key, this.partition, server, service, engine, context, host, this.nodeConfig, this.balancerConfig);
- results = this.source.getResetRequests(emptyResponseMap);
+ EasyMock.expect(this.requestFactory.createEnableRequest(context)).andReturn(contextRequest);
- EasyMock.verify(this.singleton, this.key, this.partition, server, service, engine, context, host, this.nodeConfig, this.balancerConfig);
+ EasyMock.expect(this.key.getHAPartition()).andReturn(this.partition);
+ EasyMock.expect(this.key.getHAServiceKey()).andReturn("service:domain");
+ EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq("service:domain"), EasyMock.eq("getResetRequests"), EasyMock.aryEq(new Object[] { emptyResponseMap }), EasyMock.aryEq(new Class[] { Map.class }), EasyMock.eq(true))).andReturn(new ArrayList<ResetRequestGroupRpcResponse>(Arrays.asList(response1, response2)));
- Assert.assertEquals(4, results.size());
+ EasyMock.replay(this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
- MCMPRequest request = results.get(0);
- Map<String, String> parameters = request.getParameters();
+ List<MCMPRequest> requests = source.getResetRequests(emptyResponseMap);
- 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"));
+ EasyMock.verify(this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
- request = results.get(1);
- parameters = request.getParameters();
+ Assert.assertEquals(4, requests.size());
- 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"));
+ Assert.assertSame(configRequest, requests.get(0));
+ Assert.assertSame(contextRequest, requests.get(1));
+ Assert.assertSame(request1, requests.get(2));
+ Assert.assertSame(request2, requests.get(3));
- Assert.assertSame(request1, results.get(2));
- Assert.assertSame(request2, results.get(3));
+ EasyMock.reset(this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
+ }
+
+ @Test
+ public void getLocalResetRequestsNoServer() throws Exception
+ {
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
- EasyMock.reset(this.singleton, this.key, this.partition, server, service, engine, context, host, this.nodeConfig, this.balancerConfig);
+ Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
+
+ EasyMock.replay(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
- // Test non-master
- results = this.source.getResetRequests(emptyResponseMap);
+ List<MCMPRequest> requests = source.getLocalResetRequests(emptyResponseMap);
+
+ EasyMock.verify(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
- Assert.assertTrue(results.isEmpty());
+ Assert.assertTrue(requests.isEmpty());
+
+ EasyMock.reset(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
}
@Test
public void getLocalResetRequests() throws Exception
{
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+
Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
- // Test w/out server
- List<MCMPRequest> results = this.source.getLocalResetRequests(emptyResponseMap);
- Assert.assertTrue(results.isEmpty());
-
-
// Test w/server
Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
Context context = EasyMock.createStrictMock(Context.class);
Host host = EasyMock.createStrictMock(Host.class);
- Connector connector = new Connector("AJP/1.3");
+ MCMPRequest configRequest = EasyMock.createStrictMock(MCMPRequest.class);
+ MCMPRequest contextRequest = EasyMock.createStrictMock(MCMPRequest.class);
- this.source.setJbossWebServer(server);
-
+ source.setJbossWebServer(server);
+
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ EasyMock.expect(this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig)).andReturn(configRequest);
+
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
- EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
- EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.nodeConfig.getFlushWait()).andReturn(1);
- EasyMock.expect(this.nodeConfig.getPing()).andReturn(2);
- EasyMock.expect(this.nodeConfig.getSmax()).andReturn(3);
- EasyMock.expect(this.nodeConfig.getTtl()).andReturn(4);
- EasyMock.expect(this.nodeConfig.getNodeTimeout()).andReturn(5);
- EasyMock.expect(this.nodeConfig.getBalancer()).andReturn("S");
-
- EasyMock.expect(this.balancerConfig.getStickySession()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getStickySessionRemove()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.balancerConfig.getStickySessionForce()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getWorkerTimeout()).andReturn(6);
- EasyMock.expect(this.balancerConfig.getMaxAttempts()).andReturn(7);
-
EasyMock.expect(engine.findChildren()).andReturn(new Container[] { host });
EasyMock.expect(host.getName()).andReturn("host").times(2);
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
EasyMock.expect(host.findChildren()).andReturn(new Container[] { context });
EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.isStarted()).andReturn(true);
-
- EasyMock.replay(this.singleton, this.key, this.partition, server, service, engine, context, host, this.nodeConfig, this.balancerConfig);
- results = this.source.getLocalResetRequests(emptyResponseMap);
+ EasyMock.expect(this.requestFactory.createEnableRequest(context)).andReturn(contextRequest);
- EasyMock.verify(this.singleton, this.key, this.partition, server, service, engine, context, host, this.nodeConfig, this.balancerConfig);
+ EasyMock.replay(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
- Assert.assertEquals(2, results.size());
+ List<MCMPRequest> requests = source.getLocalResetRequests(emptyResponseMap);
- MCMPRequest request = results.get(0);
- Map<String, String> parameters = request.getParameters();
+ EasyMock.verify(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
- 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"));
+ Assert.assertEquals(2, requests.size());
- request = results.get(1);
- parameters = request.getParameters();
+ Assert.assertSame(configRequest, requests.get(0));
+ Assert.assertSame(contextRequest, requests.get(1));
- 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, context, host, this.nodeConfig, this.balancerConfig);
+ EasyMock.reset(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
}
}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/DefaultMCMPRequestFactoryTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/DefaultMCMPRequestFactoryTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/DefaultMCMPRequestFactoryTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -0,0 +1,349 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.modcluster.mcmp;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.Service;
+import org.apache.catalina.connector.Connector;
+import org.easymock.EasyMock;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.mcmp.impl.DefaultMCMPRequestFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class DefaultMCMPRequestFactoryTestCase
+{
+ private MCMPRequestFactory factory = new DefaultMCMPRequestFactory();
+
+ @Test
+ public void testCreateEnableRequestContext()
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ EasyMock.replay(context, host, engine);
+
+ MCMPRequest request = this.factory.createEnableRequest(context);
+
+ EasyMock.verify(context, host, engine);
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ }
+
+ @Test
+ public void testCreateDisableRequestContext()
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ EasyMock.replay(context, host, engine);
+
+ MCMPRequest request = this.factory.createDisableRequest(context);
+
+ EasyMock.verify(context, host, engine);
+
+ Assert.assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ }
+
+ @Test
+ public void testCreateStopRequest()
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ EasyMock.replay(context, host, engine);
+
+ MCMPRequest request = this.factory.createStopRequest(context);
+
+ EasyMock.verify(context, host, engine);
+
+ Assert.assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ }
+
+ @Test
+ public void testCreateRemoveRequestContext()
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ EasyMock.replay(context, host, engine);
+
+ MCMPRequest request = this.factory.createRemoveRequest(context);
+
+ EasyMock.verify(context, host, engine);
+
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ }
+
+ @Test
+ public void testCreateStatusRequest()
+ {
+ MCMPRequest request = this.factory.createStatusRequest("route", 10);
+
+ Assert.assertSame(MCMPRequestType.STATUS, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("route", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(1, parameters.size());
+ Assert.assertEquals("10", parameters.get("Load"));
+ }
+
+ @Test
+ public void testCreateConfigRequest() throws Exception
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Service service = EasyMock.createStrictMock(Service.class);
+ NodeConfiguration nodeConfig = EasyMock.createStrictMock(NodeConfiguration.class);
+ BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
+ Connector connector = new Connector("AJP/1.3");
+
+ EasyMock.expect(engine.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+
+ EasyMock.expect(nodeConfig.getDomain()).andReturn("domain");
+ EasyMock.expect(nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
+ EasyMock.expect(nodeConfig.getFlushWait()).andReturn(1);
+ EasyMock.expect(nodeConfig.getPing()).andReturn(2);
+ EasyMock.expect(nodeConfig.getSmax()).andReturn(3);
+ EasyMock.expect(nodeConfig.getTtl()).andReturn(4);
+ EasyMock.expect(nodeConfig.getNodeTimeout()).andReturn(5);
+ EasyMock.expect(nodeConfig.getBalancer()).andReturn("S");
+
+ EasyMock.expect(balancerConfig.getStickySession()).andReturn(Boolean.FALSE);
+ EasyMock.expect(balancerConfig.getStickySessionRemove()).andReturn(Boolean.TRUE);
+ EasyMock.expect(balancerConfig.getStickySessionForce()).andReturn(Boolean.FALSE);
+ EasyMock.expect(balancerConfig.getWorkerTimeout()).andReturn(6);
+ EasyMock.expect(balancerConfig.getMaxAttempts()).andReturn(7);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ EasyMock.replay(engine, service, nodeConfig, balancerConfig);
+
+ MCMPRequest request = this.factory.createConfigRequest(engine, nodeConfig, balancerConfig);
+
+ EasyMock.verify(engine, service, nodeConfig, balancerConfig);
+
+ Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ 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"));
+ }
+
+ @Test
+ public void testCreateInfoRequest()
+ {
+ MCMPRequest request = this.factory.createInfoRequest();
+
+ Assert.assertSame(MCMPRequestType.INFO, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertNull(request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+ }
+
+ @Test
+ public void testCreateDumpRequest()
+ {
+ MCMPRequest request = this.factory.createDumpRequest();
+
+ Assert.assertSame(MCMPRequestType.DUMP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertNull(request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+ }
+
+ @Test
+ public void testCreateDisableRequestEngine()
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("route");
+
+ EasyMock.replay(engine);
+
+ MCMPRequest request = this.factory.createDisableRequest(engine);
+
+ EasyMock.verify(engine);
+
+ Assert.assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("route", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+ }
+
+ @Test
+ public void testCreateEnableRequestEngine()
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("route");
+
+ EasyMock.replay(engine);
+
+ MCMPRequest request = this.factory.createEnableRequest(engine);
+
+ EasyMock.verify(engine);
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("route", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+ }
+
+ @Test
+ public void testCreateRemoveRequestEngine()
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("route");
+
+ EasyMock.replay(engine);
+
+ MCMPRequest request = this.factory.createRemoveRequest(engine);
+
+ EasyMock.verify(engine);
+
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("route", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+ }
+
+ @Test
+ public void testCreateRequest()
+ {
+ MCMPRequest request = this.factory.createRequest(MCMPRequestType.REMOVE_APP, "route", new HashSet<String>(Arrays.asList("alias1", "alias2")), "path");
+
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("route", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals("alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("path", parameters.get("Context"));
+ }
+}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.modcluster.mcmp;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.Service;
+import org.easymock.EasyMock;
+import org.jboss.modcluster.ModClusterServiceTestCase;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.mcmp.impl.ResetRequestSourceImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ResetRequestSourceTestCase
+{
+ private static final ModClusterServiceTestCase.LifecycleServer server = ModClusterServiceTestCase.server;
+
+ private final NodeConfiguration nodeConfig = EasyMock.createStrictMock(NodeConfiguration.class);
+ private final BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
+ private final MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
+
+ private final ResetRequestSource source = new ResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory);
+
+ @Test
+ public void testGetResetRequests() throws Exception
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Context context = EasyMock.createStrictMock(Context.class);
+ MCMPRequest configRequest = EasyMock.createStrictMock(MCMPRequest.class);
+ MCMPRequest contextRequest = EasyMock.createStrictMock(MCMPRequest.class);
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ EasyMock.expect(this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig)).andReturn(configRequest);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { host });
+ EasyMock.expect(host.getName()).andReturn("host").times(2);
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(host.findChildren()).andReturn(new Container[] { context });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.isStarted()).andReturn(true);
+
+ EasyMock.expect(this.requestFactory.createEnableRequest(context)).andReturn(contextRequest);
+
+ EasyMock.replay(server, this.requestFactory, service, engine, host, context, this.nodeConfig, this.balancerConfig);
+
+ Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
+
+ List<MCMPRequest> requests = this.source.getResetRequests(emptyResponseMap);
+
+ EasyMock.verify(server, this.requestFactory, service, engine, host, context, this.nodeConfig, this.balancerConfig);
+
+ Assert.assertEquals(2, requests.size());
+
+ Assert.assertSame(configRequest, requests.get(0));
+ Assert.assertSame(contextRequest, requests.get(1));
+
+ EasyMock.reset(server);
+ }
+}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/test/MockProxy.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/test/MockProxy.java 2009-01-22 17:05:07 UTC (rev 2202)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/test/MockProxy.java 2009-01-22 22:34:01 UTC (rev 2203)
@@ -42,6 +42,7 @@
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPRequestType;
import org.jboss.modcluster.mcmp.MCMPServerState;
+import org.jboss.modcluster.mcmp.impl.DefaultMCMPRequest;
/**
* Mock httpd proxy that queues all received messages
@@ -138,7 +139,7 @@
}
}
- this.requests.add(new MCMPRequest(type, wildcard, jvmRoute, parameters));
+ this.requests.add(new DefaultMCMPRequest(type, wildcard, jvmRoute, parameters));
if (this.state == MCMPServerState.State.OK)
{
15 years, 11 months
JBoss Native SVN: r2202 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-22 12:05:07 -0500 (Thu, 22 Jan 2009)
New Revision: 2202
Modified:
trunk/build/unix/buildbin.mod_cluster.windows.sh
Log:
Try to create a make.bat to allow easy rebuild in the sources sources.
Modified: trunk/build/unix/buildbin.mod_cluster.windows.sh
===================================================================
--- trunk/build/unix/buildbin.mod_cluster.windows.sh 2009-01-22 16:19:46 UTC (rev 2201)
+++ trunk/build/unix/buildbin.mod_cluster.windows.sh 2009-01-22 17:05:07 UTC (rev 2202)
@@ -68,6 +68,8 @@
(cd $native_sources
echo "Running nmake at `pwd`"
+ echo "nmake -f NMAKEmakefile PREFIX=${win_output_loc} ${add_conf} install"
+ echo "nmake -f NMAKEmakefile PREFIX=${win_output_loc} ${add_conf} install" > make.bat
nmake -f NMAKEmakefile PREFIX=${win_output_loc} ${add_conf} install || exit 1
) || exit 1
15 years, 11 months
JBoss Native SVN: r2201 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-22 11:19:46 -0500 (Thu, 22 Jan 2009)
New Revision: 2201
Modified:
trunk/build/unix/buildbin.rhel-httpd.windows.sh
Log:
Try to create a make.bat to allow easy rebuild in the sources sources.
Modified: trunk/build/unix/buildbin.rhel-httpd.windows.sh
===================================================================
--- trunk/build/unix/buildbin.rhel-httpd.windows.sh 2009-01-22 11:34:18 UTC (rev 2200)
+++ trunk/build/unix/buildbin.rhel-httpd.windows.sh 2009-01-22 16:19:46 UTC (rev 2201)
@@ -68,6 +68,8 @@
(cd $native_sources
echo "Running nmake at `pwd`"
+ echo "nmake -f NMAKEmakefile PREFIX=${win_output_loc} ${add_conf} install"
+ echo "nmake -f NMAKEmakefile PREFIX=${win_output_loc} ${add_conf} install" > make.bat
nmake -f NMAKEmakefile PREFIX=${win_output_loc} ${add_conf} install
)
15 years, 11 months
JBoss Native SVN: r2200 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-22 06:34:18 -0500 (Thu, 22 Jan 2009)
New Revision: 2200
Modified:
trunk/build/unix/build.sh
Log:
Comment out the buildroot stuff (for the moment).
Modified: trunk/build/unix/build.sh
===================================================================
--- trunk/build/unix/build.sh 2009-01-22 11:01:27 UTC (rev 2199)
+++ trunk/build/unix/build.sh 2009-01-22 11:34:18 UTC (rev 2200)
@@ -1178,13 +1178,14 @@
if $run_test; then
# create a chrootable environment for testing:
- if [ ! -d ${TMPROOTBASE}/${package_output_dir} ]; then
- override ${build_top}/util/buildroot ${TMPROOTBASE}/${package_output_dir}
- if [ $? -ne 0 ]; then
- echo "buildroot ${TMPROOTBASE}/${package_output_dir} failed"
- exit 1
- fi
- fi
+ # Need sudo right... Hard to get so commented out for the moment.
+#JFC if [ ! -d ${TMPROOTBASE}/${package_output_dir} ]; then
+#JFC override ${build_top}/util/buildroot ${TMPROOTBASE}/${package_output_dir}
+#JFC if [ $? -ne 0 ]; then
+#JFC echo "buildroot ${TMPROOTBASE}/${package_output_dir} failed"
+#JFC exit 1
+#JFC fi
+#JFC fi
# run a test
override ${build_top}/buildtest.${PACKAGE}.sh ${TMPROOTBASE} ${package_output_dir} ${build_cache_dir} ${IPLOCAL} ${has_ssl}
15 years, 11 months
JBoss Native SVN: r2199 - trunk/build/windows.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-22 06:01:27 -0500 (Thu, 22 Jan 2009)
New Revision: 2199
Modified:
trunk/build/windows/build.bat
Log:
Oops...
Modified: trunk/build/windows/build.bat
===================================================================
--- trunk/build/windows/build.bat 2009-01-22 10:45:50 UTC (rev 2198)
+++ trunk/build/windows/build.bat 2009-01-22 11:01:27 UTC (rev 2199)
@@ -201,7 +201,6 @@
set INIT=%LOCAL_DIR%
echo set INIT=%LOCAL_DIR% >> %ENV_BAT%
pushd %BUILD_HOME%\unix
-PAUSE
bash build.sh %1 %2 %3 %4 %5
@if ERRORLEVEL 1 (
echo build.sh failed
15 years, 11 months