JBoss Native SVN: r1911 - trunk/mod_cluster/src/test/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-26 18:23:13 -0400 (Fri, 26 Sep 2008)
New Revision: 1911
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
Log:
Minor refactoring. Unit tests work again.
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2008-09-26 22:20:57 UTC (rev 1910)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2008-09-26 22:23:13 UTC (rev 1911)
@@ -59,7 +59,7 @@
{
private final NodeConfiguration nodeConfig = EasyMock.createStrictMock(NodeConfiguration.class);
private final BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
- private final MCMPHandlerConfiguration mcmpHandlerConfig = EasyMock.createStrictMock(MCMPHandlerConfiguration.class);
+ private final MCMPHandlerConfiguration mcmpConfig = EasyMock.createStrictMock(MCMPHandlerConfiguration.class);
private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
private final LoadBalanceFactorProvider provider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
private final AdvertiseListenerFactory listenerFactory = EasyMock.createStrictMock(AdvertiseListenerFactory.class);
@@ -73,7 +73,7 @@
@Override
protected void setUp() throws Exception
{
- this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpHandlerConfig, this.mcmpHandler, this.provider, this.listenerFactory);
+ this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.provider, this.listenerFactory);
}
public void testInit() throws IOException
@@ -84,73 +84,73 @@
AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
// Test advertise = false
- EasyMock.expect(this.mcmpHandlerConfig.getProxyList()).andReturn(localHostName);
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
- EasyMock.expect(this.mcmpHandlerConfig.getAdvertise()).andReturn(Boolean.FALSE);
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.FALSE);
- EasyMock.replay(this.mcmpHandler, this.mcmpHandlerConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.mcmpConfig, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.mcmpHandlerConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.mcmpHandlerConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.mcmpConfig, listener);
+ EasyMock.reset(this.mcmpHandler, this.mcmpConfig, listener);
// Test advertise = true
- EasyMock.expect(this.mcmpHandlerConfig.getProxyList()).andReturn(localHostName);
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
- EasyMock.expect(this.mcmpHandlerConfig.getAdvertise()).andReturn(Boolean.TRUE);
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpHandlerConfig)).andReturn(listener);
+ EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(listener);
listener.start();
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
// Test advertise = null, proxies configured
- EasyMock.expect(this.mcmpHandlerConfig.getProxyList()).andReturn(localHostName);
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
- EasyMock.expect(this.mcmpHandlerConfig.getAdvertise()).andReturn(null);
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
- EasyMock.replay(this.mcmpHandler, this.mcmpHandlerConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.mcmpConfig, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.mcmpHandlerConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.mcmpHandlerConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.mcmpConfig, listener);
+ EasyMock.reset(this.mcmpHandler, this.mcmpConfig, listener);
// Test advertise = null, no proxies configured
- EasyMock.expect(this.mcmpHandlerConfig.getProxyList()).andReturn(null);
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(null);
List<AddressPort> emptyList = Collections.emptyList();
this.mcmpHandler.init(emptyList);
- EasyMock.expect(this.mcmpHandlerConfig.getAdvertise()).andReturn(null);
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
- EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpHandlerConfig)).andReturn(listener);
+ EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(listener);
listener.start();
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
}
public void testShutdown() throws IOException
@@ -173,22 +173,22 @@
AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
- EasyMock.expect(this.mcmpHandlerConfig.getProxyList()).andReturn(localHostName);
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
- EasyMock.expect(this.mcmpHandlerConfig.getAdvertise()).andReturn(Boolean.TRUE);
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpHandlerConfig)).andReturn(listener);
+ EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(listener);
listener.start();
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpHandlerConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
// Now test shutdown()
listener.destroy();
@@ -502,150 +502,6 @@
EasyMock.expect(engine.getJvmRoute()).andReturn(null);
}
- public void testConfig() throws Exception
- {
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Service service = EasyMock.createStrictMock(Service.class);
-
- Capture<MCMPRequest> capturedRequest = recordConfig(engine, service);
-
- EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, engine, service);
-
- this.handler.config(engine);
-
- EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, engine, service);
-
- MCMPRequest request = capturedRequest.getValue();
-
- assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- assertFalse(request.isWildcard());
-
- Map<String, String> parameters = request.getParameters();
-
- assertEquals(17, parameters.size());
- assertEquals("host1", parameters.get("JVMRoute"));
- assertEquals("127.0.0.1", parameters.get("Host"));
- assertEquals("0", parameters.get("Port"));
- assertEquals("ajp", parameters.get("Type"));
- assertEquals("domain", parameters.get("Domain"));
- assertEquals("On", parameters.get("flushpackets"));
- assertEquals("1", parameters.get("flushwait"));
- assertEquals("2", parameters.get("ping"));
- assertEquals("3", parameters.get("smax"));
- assertEquals("4", parameters.get("ttl"));
- assertEquals("5", parameters.get("Timeout"));
- assertEquals("S", parameters.get("Balancer"));
- assertEquals("No", parameters.get("StickySession"));
- assertEquals("Yes", parameters.get("StickySessionRemove"));
- assertEquals("No", parameters.get("StickySessionForce"));
- assertEquals("6", parameters.get("WaitWorker"));
- assertEquals("7", parameters.get("Maxattempts"));
-
- EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, engine, service);
- }
-
- private Capture<MCMPRequest> recordConfig(Engine engine, Service service) throws Exception
- {
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
- Connector connector = new Connector("AJP/1.3");
-
- // 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.getService()).andReturn(service);
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
-
- 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));
-
- return capturedRequest;
- }
-
- public void testRemoveAll() throws IOException
- {
- Engine engine = EasyMock.createStrictMock(Engine.class);
-
- // Test not initialized
- try
- {
- this.handler.removeAll(engine);
-
- fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- testInit();
-
- // Test initialized - no jvm route
- // Expect log message
- EasyMock.expect(engine.getName()).andReturn("engine");
-
- EasyMock.expect(engine.getJvmRoute()).andReturn(null);
-
- EasyMock.replay(engine);
-
- this.handler.removeAll(engine);
-
- EasyMock.verify(engine);
- EasyMock.reset(engine);
-
-
- // Test initialized - jvm route exists
- Capture<MCMPRequest> capturedRequest = this.recordRemoveAll(engine);
-
- EasyMock.replay(this.mcmpHandler, engine);
-
- this.handler.removeAll(engine);
-
- EasyMock.verify(this.mcmpHandler, engine);
-
- MCMPRequest request = capturedRequest.getValue();
-
- assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- assertTrue(request.isWildcard());
- assertEquals(Collections.singletonMap("JVMRoute", "host1"), request.getParameters());
-
- EasyMock.reset(this.mcmpHandler, engine);
- }
-
- private Capture<MCMPRequest> recordRemoveAll(Engine engine)
- {
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(engine.getName()).andReturn("engine");
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
-
- this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- return capturedRequest;
- }
-
public void testStatus() throws IOException
{
Engine engine = EasyMock.createStrictMock(Engine.class);
@@ -653,7 +509,7 @@
// Test not initialized
try
{
- this.handler.removeAll(engine);
+ this.handler.status(engine);
fail();
}
@@ -716,35 +572,84 @@
testInit();
// Test initialized
- Service service1 = EasyMock.createStrictMock(Service.class);
- Service service2 = EasyMock.createStrictMock(Service.class);
- Engine engine1 = EasyMock.createStrictMock(Engine.class);
- Engine engine2 = EasyMock.createStrictMock(Engine.class);
- Container container1 = EasyMock.createStrictMock(Container.class);
- Container container2 = EasyMock.createStrictMock(Container.class);
- Context context1 = EasyMock.createStrictMock(Context.class);
- Context context2 = EasyMock.createStrictMock(Context.class);
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ Context context = EasyMock.createStrictMock(Context.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ Connector connector = new Connector("AJP/1.3");
- EasyMock.expect(server.findServices()).andReturn(new Service[] { service1, service2 });
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
- EasyMock.expect(service1.getContainer()).andReturn(engine1);
- this.recordConfig(engine1, service1);
- EasyMock.expect(engine1.findChildren()).andReturn(new Container[] { container1 });
- EasyMock.expect(container1.findChildren()).andReturn(new Container[] { context1 });
- this.recordAddContext(context1, container1);
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.expect(service2.getContainer()).andReturn(engine2);
- this.recordConfig(engine2, service2);
- EasyMock.expect(engine2.findChildren()).andReturn(new Container[] { container2 });
- EasyMock.expect(container2.findChildren()).andReturn(new Container[] { context2 });
- this.recordAddContext(context2, container2);
+ 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.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+ EasyMock.expect(engine.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ 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));
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
+ this.recordAddContext(context, container);
+
+ EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+
this.handler.startServer(server);
- EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
- EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+ EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(17, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("127.0.0.1", parameters.get("Host"));
+ assertEquals("0", parameters.get("Port"));
+ assertEquals("ajp", parameters.get("Type"));
+ assertEquals("domain", parameters.get("Domain"));
+ assertEquals("On", parameters.get("flushpackets"));
+ assertEquals("1", parameters.get("flushwait"));
+ assertEquals("2", parameters.get("ping"));
+ assertEquals("3", parameters.get("smax"));
+ assertEquals("4", parameters.get("ttl"));
+ assertEquals("5", parameters.get("Timeout"));
+ assertEquals("S", parameters.get("Balancer"));
+ assertEquals("No", parameters.get("StickySession"));
+ assertEquals("Yes", parameters.get("StickySessionRemove"));
+ assertEquals("No", parameters.get("StickySessionForce"));
+ assertEquals("6", parameters.get("WaitWorker"));
+ assertEquals("7", parameters.get("Maxattempts"));
+
+ EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
}
public void testStopServer() throws IOException
@@ -766,34 +671,38 @@
testInit();
// Test initialized
- Service service1 = EasyMock.createStrictMock(Service.class);
- Service service2 = EasyMock.createStrictMock(Service.class);
- Engine engine1 = EasyMock.createStrictMock(Engine.class);
- Engine engine2 = EasyMock.createStrictMock(Engine.class);
- Container container1 = EasyMock.createStrictMock(Container.class);
- Container container2 = EasyMock.createStrictMock(Container.class);
- Context context1 = EasyMock.createStrictMock(Context.class);
- Context context2 = EasyMock.createStrictMock(Context.class);
-
- EasyMock.expect(server.findServices()).andReturn(new Service[] { service1, service2 });
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ Context context = EasyMock.createStrictMock(Context.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(service1.getContainer()).andReturn(engine1);
- this.recordRemoveAll(engine1);
- EasyMock.expect(engine1.findChildren()).andReturn(new Container[] { container1 });
- EasyMock.expect(container1.findChildren()).andReturn(new Container[] { context1 });
- this.recordRemoveContext(context1, container1, engine1);
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.expect(service2.getContainer()).andReturn(engine2);
- this.recordRemoveAll(engine2);
- EasyMock.expect(engine2.findChildren()).andReturn(new Container[] { container2 });
- EasyMock.expect(container2.findChildren()).andReturn(new Container[] { context2 });
- this.recordRemoveContext(context2, container2, engine2);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
- EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
+ this.recordRemoveContext(context, container, engine);
+
+ EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+
this.handler.stopServer(server);
- EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
- EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+ EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ assertTrue(request.isWildcard());
+ assertEquals(Collections.singletonMap("JVMRoute", "host1"), request.getParameters());
+
+ EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
}
}
\ No newline at end of file
16 years, 3 months
JBoss Native SVN: r1910 - in trunk/mod_cluster/src: test/java/org/jboss/modcluster and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-26 18:20:57 -0400 (Fri, 26 Sep 2008)
New Revision: 1910
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
Log:
Minor refactoring. Unit tests work again.
Fixed infinite loop if new discovery events exist.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-26 09:19:02 UTC (rev 1909)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-26 22:20:57 UTC (rev 1910)
@@ -61,10 +61,10 @@
private final StringManager sm = StringManager.getManager(Constants.Package);
private final NodeConfiguration nodeConfig;
private final BalancerConfiguration balancerConfig;
- private final MCMPHandlerConfiguration mcmpHandlerConfig;
+ private final MCMPHandlerConfiguration mcmpConfig;
private final MCMPHandler mcmpHandler;
+ private final AdvertiseListenerFactory listenerFactory;
private final LoadBalanceFactorProvider loadBalanceFactorProvider;
- private final AdvertiseListenerFactory listenerFactory;
private volatile boolean init;
@@ -73,18 +73,18 @@
// ----------------------------------------------------------- Constructors
public DefaultJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpHandlerConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider)
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider)
{
- this(nodeConfig, balancerConfig, mcmpHandlerConfig, mcmpHandler, loadBalanceFactorProvider, new AdvertiseListenerFactoryImpl());
+ this(nodeConfig, balancerConfig, mcmpConfig, mcmpHandler, loadBalanceFactorProvider, new AdvertiseListenerFactoryImpl());
}
protected DefaultJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpHandlerConfig, MCMPHandler mcmpHandler,
- LoadBalanceFactorProvider loadBalanceFactorProvider, AdvertiseListenerFactory listenerFactory)
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider,
+ AdvertiseListenerFactory listenerFactory)
{
this.nodeConfig = nodeConfig;
this.balancerConfig = balancerConfig;
- this.mcmpHandlerConfig = mcmpHandlerConfig;
+ this.mcmpConfig = mcmpConfig;
this.mcmpHandler = mcmpHandler;
this.loadBalanceFactorProvider = loadBalanceFactorProvider;
this.listenerFactory = listenerFactory;
@@ -94,14 +94,14 @@
public synchronized void init()
{
- List<AddressPort> initialProxies = MCMPUtils.parseProxies(this.mcmpHandlerConfig.getProxyList());
+ List<AddressPort> initialProxies = MCMPUtils.parseProxies(this.mcmpConfig.getProxyList());
this.mcmpHandler.init(initialProxies);
- Boolean advertise = this.mcmpHandlerConfig.getAdvertise();
+ Boolean advertise = this.mcmpConfig.getAdvertise();
if (Boolean.TRUE.equals(advertise) || (advertise == null && initialProxies.isEmpty()))
{
- this.advertiseListener = this.listenerFactory.createListener(this.mcmpHandler, this.mcmpHandlerConfig);
+ this.advertiseListener = this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig);
try
{
@@ -190,29 +190,38 @@
}
}
}
-
+
protected void config(Engine engine)
{
+ this.config(engine, this.mcmpHandler);
+ }
+
+ protected void config(Engine engine, MCMPHandler mcmpHandler)
+ {
log.debug(this.sm.getString("modcluster.engine.config", engine.getName()));
// If needed, create automagical JVM route (address + port + engineName)
try
{
- Utils.establishJvmRouteAndConnectorAddress(engine, this.mcmpHandler);
+ Utils.establishJvmRouteAndConnectorAddress(engine, mcmpHandler);
+
+ this.jvmRouteEstablished(engine);
+
+ MCMPRequest request = MCMPUtils.createConfigRequest(engine, this.nodeConfig, this.balancerConfig);
+ this.mcmpHandler.sendRequest(request);
}
catch (Exception e)
{
- e.printStackTrace();
- this.mcmpHandler.markProxiesInError();
+ mcmpHandler.markProxiesInError();
+
log.info(this.sm.getString("modcluster.error.addressJvmRoute"), e);
- return;
}
-
- MCMPRequest request = MCMPUtils.createConfigRequest(engine, this.nodeConfig, this.balancerConfig);
-
- // Send CONFIG request
- this.mcmpHandler.sendRequest(request);
}
+
+ protected void jvmRouteEstablished(Engine engine)
+ {
+ // Do nothing
+ }
public void addContext(Context context)
{
@@ -266,8 +275,6 @@
protected void removeAll(Engine engine)
{
- this.checkInit();
-
log.debug(this.sm.getString("modcluster.engine.stop", engine.getName()));
// JVMRoute can be null here if nothing was ever initialized
@@ -288,11 +295,16 @@
this.mcmpHandler.status();
// Send STATUS request
- int lbf = this.loadBalanceFactorProvider.getLoadBalanceFactor();
+ int lbf = this.getLoadBalanceFactor();
MCMPRequest request = MCMPUtils.createStatusRequest(engine, lbf);
this.mcmpHandler.sendRequest(request);
}
+ protected int getLoadBalanceFactor()
+ {
+ return this.loadBalanceFactorProvider.getLoadBalanceFactor();
+ }
+
// ---------------------------------------------------------------- Private
private void checkInit()
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-26 09:19:02 UTC (rev 1909)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-26 22:20:57 UTC (rev 1910)
@@ -94,13 +94,13 @@
final HASingletonAwareResetRequestSource resetRequestSource;
final Map<ClusterNode, MCMPServerDiscoveryEvent> proxyChangeDigest =
new HashMap<ClusterNode, MCMPServerDiscoveryEvent>();
+ final ModClusterServiceDRMEntry drmEntry;
/**
* The string manager for this package.
*/
final StringManager sm = StringManager.getManager(Constants.Package);
- final LoadBalanceFactorProvider loadManager;
private final RpcHandler rpcHandler;
private final JBossWebEventHandler eventHandlerDelegate;
private final String domain;
@@ -109,7 +109,6 @@
volatile int latestLoad;
volatile int statusCount = 0;
volatile int processStatusFrequency = 1;
- ModClusterServiceDRMEntry drmEntry;
/**
* Create a new ClusterCoordinator.
@@ -150,9 +149,7 @@
this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this, this);
this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource);
this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this, this);
- this.loadManager = loadFactorProvider;
- this.eventHandlerDelegate = new ClusteredJBossWebEventHandler(config, loadFactorProvider);
-// this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config, config, this.clusteredHandler, loadFactorProvider);
+ this.eventHandlerDelegate = new ClusteredJBossWebEventHandler(config, config, config, this.clusteredHandler, loadFactorProvider);
this.domain = config.getDomain();
this.masterPerDomain = config.isMasterPerDomain();
@@ -180,34 +177,30 @@
protected ModClusterService(HAPartition partition,
NodeConfiguration nodeConfig,
BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpHandlerConfig,
+ MCMPHandlerConfiguration mcmpConfig,
MCMPHandler localHandler,
HASingletonAwareResetRequestSource resetRequestSource,
ClusteredMCMPHandler clusteredHandler,
- LoadBalanceFactorProvider loadManager,
- JBossWebEventHandler eventHandler,
+ LoadBalanceFactorProvider loadFactorProvider,
HASingletonElectionPolicy electionPolicy)
{
super(new HAServiceEventFactory());
assert partition != null : this.sm.getString("modcluster.error.iae.null", "partition");
assert localHandler != null : this.sm.getString("modcluster.error.iae.null", "localHandler");
- assert loadManager != null : this.sm.getString("modcluster.error.iae.null", "loadManager");
assert resetRequestSource != null : this.sm.getString("modcluster.error.iae.null", "resetRequestSource");
assert nodeConfig != null : this.sm.getString("modcluster.error.iae.null", "nodeConfig");
assert balancerConfig != null : this.sm.getString("modcluster.error.iae.null", "balancerConfig");
assert clusteredHandler != null : this.sm.getString("modcluster.error.iae.null", "clusteredHandler");
- assert eventHandler != null : this.sm.getString("modcluster.error.iae.null", "eventHandler");
this.setHAPartition(partition);
this.localHandler = localHandler;
this.resetRequestSource = resetRequestSource;
this.clusteredHandler = clusteredHandler;
- this.loadManager = loadManager;
- this.eventHandlerDelegate = eventHandler;
+ this.eventHandlerDelegate = new ClusteredJBossWebEventHandler(nodeConfig, balancerConfig, mcmpConfig, this.clusteredHandler, loadFactorProvider);
this.domain = nodeConfig.getDomain();
- this.masterPerDomain = mcmpHandlerConfig.isMasterPerDomain();
+ this.masterPerDomain = mcmpConfig.isMasterPerDomain();
this.setElectionPolicy(electionPolicy);
@@ -431,194 +424,6 @@
return narrowed;
}
- @SuppressWarnings("unchecked")
- void updateClusterStatus()
- {
- Set<MCMPServerState> masterList = null;
- Map<ClusterNode, MCMPServerDiscoveryEvent> latestEvents = null;
- Map<ClusterNode, ModClusterServiceDRMEntry> nonresponsive = new HashMap<ClusterNode, ModClusterServiceDRMEntry>();
- Map<String, Integer> loadBalanceFactors = new HashMap<String, Integer>();
- Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses = new HashMap<ClusterNode, PeerMCMPDiscoveryStatus>();
- List<MCMPRequest> resetRequests = new ArrayList<MCMPRequest>();
- HAPartition partition = this.getHAPartition();
- DistributedReplicantManager drm = partition.getDistributedReplicantManager();
- boolean resync = false;
-
- do
- {
- this.localHandler.status();
-
- synchronized (this.proxyChangeDigest)
- {
- masterList = this.localHandler.getProxyStates();
- latestEvents = new HashMap<ClusterNode, MCMPServerDiscoveryEvent>(this.proxyChangeDigest);
- }
-
- List<ModClusterServiceDRMEntry> replicants = drm.lookupReplicants(this.getHAServiceKey());
- nonresponsive.clear();
-
- for (ModClusterServiceDRMEntry replicant: replicants)
- {
- nonresponsive.put(replicant.getPeer(), replicant);
- }
- nonresponsive.remove(partition.getClusterNode());
-
- // FIXME -- what about our own dropped discovery events if we just became master?
- List responses = this.getClusterCoordinatorState(masterList);
-
- // Gather up all the reset requests in one list
- // FIXME -- what about our own dropped requests if we just became master?
- resetRequests.clear();
-
- // Gather all the load balance factors
- loadBalanceFactors.clear();
-
- // Add our own lbf - it is not returned via getclusterCoordinatorState(...)
- for (String jvmRoute: this.drmEntry.getJvmRoutes())
- {
- loadBalanceFactors.put(jvmRoute, this.latestLoad);
- }
-
- // Gather the info on who knows about what proxies
- statuses.clear();
-
- for (Object response: responses)
- {
- if (response instanceof ModClusterServiceStateGroupRpcResponse)
- {
- ModClusterServiceStateGroupRpcResponse mcssgrr = (ModClusterServiceStateGroupRpcResponse) response;
- ClusterNode cn = mcssgrr.getSender();
-
- // Check for discovery events we haven't processed
- MCMPServerDiscoveryEvent latestEvent = latestEvents.get(cn);
-
- for (MCMPServerDiscoveryEvent toCheck: mcssgrr.getUnacknowledgedEvents())
- {
- if (latestEvent != null && latestEvent.getEventIndex() <= toCheck.getEventIndex())
- {
- continue; // already processed it
- }
-
- AddressPort ap = toCheck.getMCMPServer();
- if (toCheck.isAddition())
- {
- this.localHandler.addProxy(ap.getAddress(), ap.getPort());
- }
- else
- {
- this.localHandler.removeProxy(ap.getAddress(), ap.getPort());
- }
- resync = true;
- }
-
- if (!resync) // don't bother if we are going to start over
- {
- statuses.put(cn, new PeerMCMPDiscoveryStatus(cn, mcssgrr.getStates(), latestEvent));
-
- List<MCMPRequest> toAdd = mcssgrr.getResetRequests();
- if (toAdd != null)
- {
- resetRequests.addAll(toAdd);
- }
-
- ModClusterServiceDRMEntry removed = nonresponsive.remove(cn);
- if (removed != null)
- {
- Integer lbf = Integer.valueOf(mcssgrr.getLoadBalanceFactor());
- for (String jvmRoute: removed.getJvmRoutes())
- {
- loadBalanceFactors.put(jvmRoute, lbf);
- }
- }
- }
- }
- else if (response instanceof ThrowableGroupRpcResponse)
- {
- ThrowableGroupRpcResponse tgrr = (ThrowableGroupRpcResponse) response;
- ClusterNode cn = tgrr.getSender();
-
- this.log.warn(this.sm.getString("modcluster.error.rpc.known", "getClusterCoordinatorState", cn), tgrr.getValue());
-
- // Don't remove from nonresponsive list and we'll pass back an error
- // status (null server list) to this peer
- }
- else if (response instanceof Throwable)
- {
- this.log.warn(this.sm.getString("modcluster.error.rpc.unknown", "getClusterCoordinatorState"), (Throwable) response);
- }
- else
- {
- this.log.error(this.sm.getString("modcluster.error.rpc.unexpected", response, "getClusterCoordinatorState"));
- }
- }
- }
- // We picked up previously unknown discovery events; start over
- while (resync);
-
- // Add error-state objects for non-responsive peers
- Integer lbf = Integer.valueOf(0);
- for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry: nonresponsive.entrySet())
- {
- ClusterNode cn = entry.getKey();
- statuses.put(entry.getKey(), new PeerMCMPDiscoveryStatus(cn, null, latestEvents.get(cn)));
-
- for (String jvmRoute: entry.getValue().getJvmRoutes())
- {
- loadBalanceFactors.put(jvmRoute, lbf);
- }
- }
- // FIXME handle crashed members, gone from DRM
-
- // Advise the proxies of any reset requests
- this.localHandler.sendRequests(resetRequests);
-
- // Pass along the LBF values
- List<MCMPRequest> statusRequests = new ArrayList<MCMPRequest>();
- for (Map.Entry<String, Integer> entry: loadBalanceFactors.entrySet())
- {
- statusRequests.add(MCMPUtils.createStatusRequest(entry.getKey(), entry.getValue().intValue()));
- }
- this.localHandler.sendRequests(statusRequests);
-
- // Advise the members the process is done and that they should update DRM
- this.notifyClusterStatusComplete(masterList, statuses);
- }
-
- private void notifyClusterStatusComplete(Set<MCMPServerState> masterList, Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
- {
- HAPartition partition = this.getHAPartition();
-
- // Determine who should update DRM first -- us or the rest of the nodes
- Set<ModClusterServiceDRMEntry> allStatuses = new HashSet<ModClusterServiceDRMEntry>(statuses.values());
- ModClusterServiceDRMEntry ourCurrentStatus = (ModClusterServiceDRMEntry) partition.getDistributedReplicantManager().lookupLocalReplicant(this.getHAServiceKey());
- allStatuses.add(ourCurrentStatus);
-
- ClusterNode node = partition.getClusterNode();
-
- boolean othersFirst = this.narrowCandidateList(allStatuses).contains(node);
- ModClusterServiceDRMEntry ourNewStatus = new ModClusterServiceDRMEntry(node, masterList);
- boolean updated = !ourNewStatus.equals(ourCurrentStatus);
-
- if (othersFirst)
- {
- this.clusterStatusComplete(statuses);
-
- if (updated)
- {
- this.updateLocalDRM(ourNewStatus);
- }
- }
- else
- {
- if (updated)
- {
- this.updateLocalDRM(ourNewStatus);
- }
-
- this.clusterStatusComplete(statuses);
- }
- }
-
/**
* @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#clusterStatusComplete(java.util.Map)
*/
@@ -865,26 +670,25 @@
private class ClusteredJBossWebEventHandler extends DefaultJBossWebEventHandler
{
+ private final ModClusterService coord = ModClusterService.this;
+
/**
* Create a new ClusteredJBossWebEventHandler.
*
- * @param nodeConfig
- * @param balancerConfig
- * @param mcmpHandlerConfig
- * @param mcmpHandler
- * @param loadBalanceFactorProvider
+ * @param config
+ * @param loadFactorProvider
*/
- public ClusteredJBossWebEventHandler(ModClusterConfig config, LoadBalanceFactorProvider loadBalanceFactorProvider)
+ public ClusteredJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler clusteredHandler, LoadBalanceFactorProvider loadFactorProvider)
{
- // FIXME ClusteredJBossWebEventHandler constructor
- super(config, config, config, ModClusterService.this.clusteredHandler, loadBalanceFactorProvider);
+ super(nodeConfig, balancerConfig, mcmpConfig, clusteredHandler, loadFactorProvider);
}
@Override
public void startServer(Server server)
{
// Pass on ref to our server
- ModClusterService.this.resetRequestSource.setJbossWebServer(server);
+ this.coord.resetRequestSource.setJbossWebServer(server);
super.startServer(server);
}
@@ -892,51 +696,231 @@
@Override
protected void config(Engine engine)
{
- // If needed, create automagical JVM route (address + port + engineName)
- try
- {
- Utils.establishJvmRouteAndConnectorAddress(engine, ModClusterService.this.clusteredHandler);
- }
- catch (Exception e) {
- ModClusterService.this.clusteredHandler.markProxiesInError();
- log.info(ModClusterService.this.sm.getString("modcluster.error.addressJvmRoute"), e);
- return;
- }
-
- ModClusterService.this.drmEntry.addJvmRoute(engine.getJvmRoute());
- ModClusterService.this.updateLocalDRM(ModClusterService.this.drmEntry);
-
- super.config(engine);
+ this.config(engine, this.coord.clusteredHandler);
}
@Override
+ protected void jvmRouteEstablished(Engine engine)
+ {
+ this.coord.drmEntry.addJvmRoute(engine.getJvmRoute());
+ this.coord.updateLocalDRM(this.coord.drmEntry);
+ }
+
+ @Override
protected void removeAll(Engine engine)
{
super.removeAll(engine);
- ModClusterService.this.drmEntry.removeJvmRoute(engine.getJvmRoute());
- ModClusterService.this.updateLocalDRM(ModClusterService.this.drmEntry);
+ this.coord.drmEntry.removeJvmRoute(engine.getJvmRoute());
+ this.coord.updateLocalDRM(this.coord.drmEntry);
}
@Override
public void status(Engine engine)
{
- log.info(ModClusterService.this.sm.getString("modcluster.engine.status", engine.getName()));
+ log.info(this.coord.sm.getString("modcluster.engine.status", engine.getName()));
- ModClusterService.this.latestLoad = ModClusterService.this.loadManager.getLoadBalanceFactor();
+ this.coord.latestLoad = this.getLoadBalanceFactor();
- if (ModClusterService.this.isMasterNode())
+ if (this.coord.isMasterNode())
{
- ModClusterService.this.statusCount = (ModClusterService.this.statusCount + 1) % ModClusterService.this.processStatusFrequency;
+ this.coord.statusCount = (this.coord.statusCount + 1) % this.coord.processStatusFrequency;
- if (ModClusterService.this.statusCount == 0)
+ if (this.coord.statusCount == 0)
{
- ModClusterService.this.updateClusterStatus();
+ this.updateClusterStatus();
}
}
+ }
+
+ @SuppressWarnings("unchecked")
+ void updateClusterStatus()
+ {
+ Set<MCMPServerState> masterList = null;
+ Map<ClusterNode, MCMPServerDiscoveryEvent> latestEvents = null;
+ Map<ClusterNode, ModClusterServiceDRMEntry> nonresponsive = new HashMap<ClusterNode, ModClusterServiceDRMEntry>();
+ Map<String, Integer> loadBalanceFactors = new HashMap<String, Integer>();
+ Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses = new HashMap<ClusterNode, PeerMCMPDiscoveryStatus>();
+ List<MCMPRequest> resetRequests = new ArrayList<MCMPRequest>();
+ HAPartition partition = this.coord.getHAPartition();
+ DistributedReplicantManager drm = partition.getDistributedReplicantManager();
+ boolean resync = false;
+
+ do
+ {
+ resync = false;
+
+ this.coord.localHandler.status();
+
+ synchronized (this.coord.proxyChangeDigest)
+ {
+ masterList = this.coord.localHandler.getProxyStates();
+ latestEvents = new HashMap<ClusterNode, MCMPServerDiscoveryEvent>(this.coord.proxyChangeDigest);
+ }
+
+ List<ModClusterServiceDRMEntry> replicants = drm.lookupReplicants(this.coord.getHAServiceKey());
+ nonresponsive.clear();
+
+ for (ModClusterServiceDRMEntry replicant: replicants)
+ {
+ nonresponsive.put(replicant.getPeer(), replicant);
+ }
+ nonresponsive.remove(partition.getClusterNode());
+
+ // FIXME -- what about our own dropped discovery events if we just became master?
+ List responses = this.coord.getClusterCoordinatorState(masterList);
+
+ // Gather up all the reset requests in one list
+ // FIXME -- what about our own dropped requests if we just became master?
+ resetRequests.clear();
+
+ // Gather all the load balance factors
+ loadBalanceFactors.clear();
+
+ // Add our own lbf - it is not returned via getclusterCoordinatorState(...)
+ for (String jvmRoute: this.coord.drmEntry.getJvmRoutes())
+ {
+ loadBalanceFactors.put(jvmRoute, this.coord.latestLoad);
+ }
+
+ // Gather the info on who knows about what proxies
+ statuses.clear();
+
+ for (Object response: responses)
+ {
+ if (response instanceof ModClusterServiceStateGroupRpcResponse)
+ {
+ ModClusterServiceStateGroupRpcResponse mcssgrr = (ModClusterServiceStateGroupRpcResponse) response;
+ ClusterNode cn = mcssgrr.getSender();
+
+ // Check for discovery events we haven't processed
+ MCMPServerDiscoveryEvent latestEvent = latestEvents.get(cn);
+
+ for (MCMPServerDiscoveryEvent toCheck: mcssgrr.getUnacknowledgedEvents())
+ {
+ if (latestEvent != null && latestEvent.getEventIndex() <= toCheck.getEventIndex())
+ {
+ continue; // already processed it
+ }
+
+ AddressPort ap = toCheck.getMCMPServer();
+ if (toCheck.isAddition())
+ {
+ this.coord.localHandler.addProxy(ap.getAddress(), ap.getPort());
+ }
+ else
+ {
+ this.coord.localHandler.removeProxy(ap.getAddress(), ap.getPort());
+ }
+ resync = true;
+ }
+
+ if (!resync) // don't bother if we are going to start over
+ {
+ statuses.put(cn, new PeerMCMPDiscoveryStatus(cn, mcssgrr.getStates(), latestEvent));
+
+ List<MCMPRequest> toAdd = mcssgrr.getResetRequests();
+ if (toAdd != null)
+ {
+ resetRequests.addAll(toAdd);
+ }
+
+ ModClusterServiceDRMEntry removed = nonresponsive.remove(cn);
+ if (removed != null)
+ {
+ Integer lbf = Integer.valueOf(mcssgrr.getLoadBalanceFactor());
+ for (String jvmRoute: removed.getJvmRoutes())
+ {
+ loadBalanceFactors.put(jvmRoute, lbf);
+ }
+ }
+ }
+ }
+ else if (response instanceof ThrowableGroupRpcResponse)
+ {
+ ThrowableGroupRpcResponse tgrr = (ThrowableGroupRpcResponse) response;
+ ClusterNode cn = tgrr.getSender();
+
+ log.warn(this.coord.sm.getString("modcluster.error.rpc.known", "getClusterCoordinatorState", cn), tgrr.getValue());
+
+ // Don't remove from nonresponsive list and we'll pass back an error
+ // status (null server list) to this peer
+ }
+ else if (response instanceof Throwable)
+ {
+ log.warn(this.coord.sm.getString("modcluster.error.rpc.unknown", "getClusterCoordinatorState"), (Throwable) response);
+ }
+ else
+ {
+ log.error(this.coord.sm.getString("modcluster.error.rpc.unexpected", response, "getClusterCoordinatorState"));
+ }
+ }
+ }
+ // We picked up previously unknown discovery events; start over
+ while (resync);
+
+ // Add error-state objects for non-responsive peers
+ Integer lbf = Integer.valueOf(0);
+ for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry: nonresponsive.entrySet())
+ {
+ ClusterNode cn = entry.getKey();
+ statuses.put(entry.getKey(), new PeerMCMPDiscoveryStatus(cn, null, latestEvents.get(cn)));
+
+ for (String jvmRoute: entry.getValue().getJvmRoutes())
+ {
+ loadBalanceFactors.put(jvmRoute, lbf);
+ }
+ }
+ // FIXME handle crashed members, gone from DRM
+
+ // Advise the proxies of any reset requests
+ this.coord.localHandler.sendRequests(resetRequests);
+
+ // Pass along the LBF values
+ List<MCMPRequest> statusRequests = new ArrayList<MCMPRequest>();
+ for (Map.Entry<String, Integer> entry: loadBalanceFactors.entrySet())
+ {
+ statusRequests.add(MCMPUtils.createStatusRequest(entry.getKey(), entry.getValue().intValue()));
+ }
+ this.coord.localHandler.sendRequests(statusRequests);
+
+ // Advise the members the process is done and that they should update DRM
+ this.notifyClusterStatusComplete(masterList, statuses);
+ }
+
+ private void notifyClusterStatusComplete(Set<MCMPServerState> masterList, Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
+ {
+ HAPartition partition = this.coord.getHAPartition();
+
+ // Determine who should update DRM first -- us or the rest of the nodes
+ Set<ModClusterServiceDRMEntry> allStatuses = new HashSet<ModClusterServiceDRMEntry>(statuses.values());
+ DistributedReplicantManager drm = partition.getDistributedReplicantManager();
+ ModClusterServiceDRMEntry ourCurrentStatus = (ModClusterServiceDRMEntry) drm.lookupLocalReplicant(this.coord.getHAServiceKey());
+ allStatuses.add(ourCurrentStatus);
+
+ ClusterNode node = partition.getClusterNode();
+
+ boolean othersFirst = this.coord.narrowCandidateList(allStatuses).contains(node);
+ ModClusterServiceDRMEntry ourNewStatus = new ModClusterServiceDRMEntry(node, masterList);
+ boolean updated = !ourNewStatus.equals(ourCurrentStatus);
+
+ if (othersFirst)
+ {
+ this.coord.clusterStatusComplete(statuses);
+
+ if (updated)
+ {
+ this.coord.updateLocalDRM(ourNewStatus);
+ }
+ }
else
{
- log.info("We are not master");
+ if (updated)
+ {
+ this.coord.updateLocalDRM(ourNewStatus);
+ }
+
+ this.coord.clusterStatusComplete(statuses);
}
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2008-09-26 09:19:02 UTC (rev 1909)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2008-09-26 22:20:57 UTC (rev 1910)
@@ -22,10 +22,10 @@
package org.jboss.modcluster;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -35,8 +35,10 @@
import junit.framework.TestCase;
+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;
@@ -46,6 +48,7 @@
import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
+import org.jboss.modcluster.advertise.AdvertiseListener;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -71,12 +74,11 @@
private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
private NodeConfiguration nodeConfig = EasyMock.createMock(NodeConfiguration.class);
private BalancerConfiguration balancerConfig = EasyMock.createMock(BalancerConfiguration.class);
- private MCMPHandlerConfiguration mcmpHandlerConfig = EasyMock.createMock(MCMPHandlerConfiguration.class);
+ private MCMPHandlerConfiguration mcmpConfig = EasyMock.createMock(MCMPHandlerConfiguration.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 JBossWebEventHandler eventHandler = EasyMock.createStrictMock(JBossWebEventHandler.class);
private HASingletonElectionPolicy electionPolicy = EasyMock.createStrictMock(HASingletonElectionPolicy.class);
private ClusterNode node = EasyMock.createStrictMock(ClusterNode.class);
@@ -93,23 +95,23 @@
@Override
protected void setUp() throws Exception
{
- EasyMock.expect(this.mcmpHandlerConfig.isMasterPerDomain()).andReturn(MASTER_PER_DOMAIN);
+ EasyMock.expect(this.mcmpConfig.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.mcmpHandlerConfig, this.nodeConfig, this.partition);
+ EasyMock.replay(this.mcmpConfig, this.nodeConfig, this.partition);
- this.modClusterService = new ModClusterService(this.partition, this.nodeConfig, this.balancerConfig, this.mcmpHandlerConfig, this.mcmpHandler, this.resetRequestSource, this.clusteredMCMPHandler, this.lbfProvider, this.eventHandler, this.electionPolicy);
+ this.modClusterService = new ModClusterService(this.partition, this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.resetRequestSource, this.clusteredMCMPHandler, this.lbfProvider, this.electionPolicy);
this.modClusterService.setServiceHAName(SERVICE_HA_NAME);
- EasyMock.verify(this.mcmpHandlerConfig, this.nodeConfig, this.partition);
- EasyMock.reset(this.mcmpHandlerConfig, this.nodeConfig, this.partition);
+ EasyMock.verify(this.mcmpConfig, this.nodeConfig, this.partition);
+ EasyMock.reset(this.mcmpConfig, this.nodeConfig, this.partition);
}
public void testAddProxy()
{
- String host = "172.0.0.1";
+ String host = "127.0.0.1";
int port = 0;
this.clusteredMCMPHandler.addProxy(host, port);
@@ -124,7 +126,7 @@
public void testRemoveProxy()
{
- String host = "172.0.0.1";
+ String host = "127.0.0.1";
int port = 0;
this.clusteredMCMPHandler.removeProxy(host, port);
@@ -176,187 +178,536 @@
EasyMock.reset(this.clusteredMCMPHandler);
}
- public void testInit()
+ public void testInit() throws UnknownHostException
{
- this.eventHandler.init();
+ InetAddress localAddress = InetAddress.getLocalHost();
+ String localHostName = localAddress.getHostName();
- EasyMock.replay(this.eventHandler);
+ 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.modClusterService.init();
- EasyMock.verify(this.eventHandler);
- EasyMock.reset(this.eventHandler);
- }
-
- public void testStartServer()
- {
- Server server = EasyMock.createMock(Server.class);
+ EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+ EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+
- this.resetRequestSource.setJbossWebServer(server);
- this.eventHandler.startServer(server);
+ // Test advertise = null, proxies configured
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
- EasyMock.replay(this.resetRequestSource, this.eventHandler);
+ this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
- this.modClusterService.startServer(server);
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
- EasyMock.verify(this.resetRequestSource, this.eventHandler);
- EasyMock.reset(this.resetRequestSource, this.eventHandler);
+ EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+
+ this.modClusterService.init();
+
+ EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+ EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
}
- public void testStopServer()
+ public void testStartServer() throws Exception
{
Server server = EasyMock.createStrictMock(Server.class);
- this.eventHandler.stopServer(server);
+ this.resetRequestSource.setJbossWebServer(server);
- EasyMock.replay(this.eventHandler);
+ EasyMock.replay(this.resetRequestSource);
- this.modClusterService.stopServer(server);
+ // Test not initialized
+ try
+ {
+ this.modClusterService.startServer(server);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(this.resetRequestSource);
+ EasyMock.reset(this.resetRequestSource);
- EasyMock.verify(this.eventHandler);
- EasyMock.reset(this.eventHandler);
- }
-
- public void testConfig() throws Exception
- {
- ModClusterServiceDRMEntry drmEntry = this.verifyConfig(EasyMock.createStrictMock(Engine.class), "host1");
+ testInit();
- assertEquals(Collections.singleton("host1"), drmEntry.getJvmRoutes());
- assertNull(drmEntry.getMCMPServerStates());
- assertSame(this.node, drmEntry.getPeer());
- }
-
- private ModClusterServiceDRMEntry verifyConfig(Engine engine, String host) throws Exception
- {
+ // 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<ModClusterServiceDRMEntry> capturedDRMEntry = new Capture<ModClusterServiceDRMEntry>();
+ 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.clusteredMCMPHandler.getProxyStates()).andReturn(states);
- EasyMock.expect(engine.getJvmRoute()).andReturn(host);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("route");
EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- drm.add(EasyMock.eq(SERVICE_HA_NAME + ":" + DOMAIN), EasyMock.capture(capturedDRMEntry));
- this.eventHandler.config(engine);
+ drm.add("myservice:domain", this.modClusterService.drmEntry);
- EasyMock.replay(engine, service, drm, this.clusteredMCMPHandler, this.partition, this.eventHandler);
+ EasyMock.expect(engine.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- this.modClusterService.config(engine);
+ 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.verify(engine, service, drm, this.clusteredMCMPHandler, this.partition, this.eventHandler);
- EasyMock.reset(engine, service, drm, this.clusteredMCMPHandler, this.partition, this.eventHandler);
+ 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);
- return capturedDRMEntry.getValue();
+ 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.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ this.modClusterService.startServer(server);
+
+ EasyMock.verify(this.partition, this.resetRequestSource, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(17, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("127.0.0.1", parameters.get("Host"));
+ assertEquals("0", parameters.get("Port"));
+ assertEquals("ajp", parameters.get("Type"));
+ assertEquals("domain", parameters.get("Domain"));
+ assertEquals("On", parameters.get("flushpackets"));
+ assertEquals("1", parameters.get("flushwait"));
+ assertEquals("2", parameters.get("ping"));
+ assertEquals("3", parameters.get("smax"));
+ assertEquals("4", parameters.get("ttl"));
+ assertEquals("5", parameters.get("Timeout"));
+ assertEquals("S", parameters.get("Balancer"));
+ assertEquals("No", parameters.get("StickySession"));
+ assertEquals("Yes", parameters.get("StickySessionRemove"));
+ assertEquals("No", parameters.get("StickySessionForce"));
+ assertEquals("6", parameters.get("WaitWorker"));
+ assertEquals("7", parameters.get("Maxattempts"));
+
+ Set<String> routes = this.modClusterService.drmEntry.getJvmRoutes();
+ assertEquals(1, routes.size());
+ assertEquals("route", routes.iterator().next());
+
+ EasyMock.reset(this.partition, this.resetRequestSource, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
}
- public void testRemoveAll() throws Exception
+ private void recordAddContext(Context context, Container container)
{
- Engine engine = EasyMock.createStrictMock(Engine.class);
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
- // First config
- ModClusterServiceDRMEntry drmEntry = this.verifyConfig(engine, "host1");
+ EasyMock.expect(context.isStarted()).andReturn(false);
+ }
+
+ public void testStopServer() throws Exception
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
- assertEquals(Collections.singleton("host1"), drmEntry.getJvmRoutes());
- assertNull(drmEntry.getMCMPServerStates());
- assertSame(this.node, drmEntry.getPeer());
+ // Test not initialized
+ try
+ {
+ this.modClusterService.stopServer(server);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
- Capture<ModClusterServiceDRMEntry> capturedDRMEntry = new Capture<ModClusterServiceDRMEntry>();
+ testInit();
+
+ this.modClusterService.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>();
- this.eventHandler.removeAll(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ 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(EasyMock.eq(SERVICE_HA_NAME + ":" + DOMAIN), EasyMock.capture(capturedDRMEntry));
+ drm.add("myservice:domain", this.modClusterService.drmEntry);
- EasyMock.replay(drm, this.eventHandler, engine, this.partition);
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
+ this.recordRemoveContext(context, container, engine);
- this.modClusterService.removeAll(engine);
+ EasyMock.replay(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
- EasyMock.verify(drm, this.eventHandler, engine, this.partition);
+ this.modClusterService.stopServer(server);
- drmEntry = capturedDRMEntry.getValue();
+ EasyMock.verify(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ MCMPRequest request = capturedRequest.getValue();
- assertEquals(Collections.emptySet(), drmEntry.getJvmRoutes());
- assertNull(drmEntry.getMCMPServerStates());
- assertSame(this.node, drmEntry.getPeer());
+ assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ assertTrue(request.isWildcard());
+ assertEquals(Collections.singletonMap("JVMRoute", "host1"), request.getParameters());
- EasyMock.reset(drm, this.eventHandler, engine, this.partition);
+ assertTrue(this.modClusterService.drmEntry.getJvmRoutes().isEmpty());
+
+ EasyMock.reset(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
}
- public void testAddContext()
+ private void recordRemoveContext(Context context, Container container, Engine engine)
{
- Context context = EasyMock.createMock(Context.class);
+ // 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);
+ }
+
+ public void testAddContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
- this.eventHandler.addContext(context);
+ // Test not initialized
+ try
+ {
+ this.modClusterService.addContext(context);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
- EasyMock.replay(this.eventHandler);
+ testInit();
+
+ // Test context not started
+ Container container = EasyMock.createStrictMock(Container.class);
+ recordAddContext(context, container);
+
+ EasyMock.replay(context, container);
+
this.modClusterService.addContext(context);
- EasyMock.verify(this.eventHandler);
- EasyMock.reset(this.eventHandler);
+ EasyMock.verify(context, container);
+ EasyMock.reset(context, container);
+
+ // Test context started
+ 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(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ EasyMock.expect(context.isStarted()).andReturn(true);
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, container, engine, host);
+
+ this.modClusterService.addContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, container, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(3, parameters.size());
+
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, container, engine, host);
}
- public void testStartContext()
+ public void testStartContext() throws UnknownHostException
{
- Context context = EasyMock.createMock(Context.class);
+ Context context = EasyMock.createStrictMock(Context.class);
- this.eventHandler.startContext(context);
+ // Test not initialized
+ try
+ {
+ this.modClusterService.startContext(context);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
- EasyMock.replay(this.eventHandler);
+ testInit();
+
+ // Test initialized
+ Container container = EasyMock.createStrictMock(Container.class);
+ 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(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, container, engine, host);
+
this.modClusterService.startContext(context);
- EasyMock.verify(this.eventHandler);
- EasyMock.reset(this.eventHandler);
+ EasyMock.verify(this.clusteredMCMPHandler, context, container, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(3, parameters.size());
+
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, container, engine, host);
}
- public void testStopContext()
+ public void testStopContext() throws UnknownHostException
{
- Context context = EasyMock.createMock(Context.class);
+ Context context = EasyMock.createStrictMock(Context.class);
- this.eventHandler.stopContext(context);
+ // Test not initialized
+ try
+ {
+ this.modClusterService.stopContext(context);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
- EasyMock.replay(this.eventHandler);
+ testInit();
+
+ // Test initialized
+ Container container = EasyMock.createStrictMock(Container.class);
+ 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(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, container, engine, host);
+
this.modClusterService.stopContext(context);
- EasyMock.verify(this.eventHandler);
- EasyMock.reset(this.eventHandler);
+ EasyMock.verify(this.clusteredMCMPHandler, context, container, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(3, parameters.size());
+
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, container, engine, host);
}
- public void testRemoveContext()
+ public void testRemoveContext() throws UnknownHostException
{
- Context context = EasyMock.createMock(Context.class);
+ Context context = EasyMock.createStrictMock(Context.class);
- this.eventHandler.removeContext(context);
+ // Test not initialized
+ try
+ {
+ this.modClusterService.removeContext(context);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
- EasyMock.replay(this.eventHandler);
+ testInit();
+
+ // Test initialized - no jvm route
+ Container container = EasyMock.createStrictMock(Container.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ this.recordRemoveContext(context, container, engine);
+
+ EasyMock.replay(context, container, engine);
+
this.modClusterService.removeContext(context);
- EasyMock.verify(this.eventHandler);
- EasyMock.reset(this.eventHandler);
+ EasyMock.verify(context, container, engine);
+ EasyMock.reset(context, container, engine);
+
+
+ // Test initialized - jvm route exists
+ 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(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("host1");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, container, engine, host);
+
+ this.modClusterService.removeContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, container, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(3, parameters.size());
+
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, container, engine, host);
}
public void testStatus() throws Exception
{
- Engine engine = EasyMock.createMock(Engine.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
// Test non-master status
+ EasyMock.expect(engine.getName()).andReturn("engine");
EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
- EasyMock.replay(this.lbfProvider);
+ EasyMock.replay(this.lbfProvider, engine);
this.modClusterService.status(engine);
- EasyMock.verify(this.lbfProvider);
- EasyMock.reset(this.lbfProvider);
+ EasyMock.verify(this.lbfProvider, engine);
+ EasyMock.reset(this.lbfProvider, engine);
// Make master
@@ -413,8 +764,8 @@
// Test master status
MCMPServerState localState = EasyMock.createMock(MCMPServerState.class);
ModClusterServiceDRMEntry drmEntry = new ModClusterServiceDRMEntry(this.node, null);
- InetAddress address1 = InetAddress.getByName("172.0.0.1");
- InetAddress address2 = InetAddress.getByName("172.0.1.1");
+ 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);
@@ -427,6 +778,7 @@
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();
@@ -452,7 +804,6 @@
EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
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)));
@@ -481,11 +832,11 @@
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.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2);
+ EasyMock.replay(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
this.modClusterService.status(engine);
- EasyMock.verify(this.lbfProvider, this.mcmpHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2);
+ EasyMock.verify(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
List<MCMPRequest> requests = capturedRequests.getValue();
@@ -526,19 +877,20 @@
assertTrue(status1.getJvmRoutes().isEmpty());
assertNull(status1.getLatestDiscoveryEvent());
- EasyMock.reset(this.lbfProvider, this.mcmpHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2);
+ 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.modClusterService.setProcessStatusFrequency(2);
+ EasyMock.expect(engine.getName()).andReturn("engine");
EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
- EasyMock.replay(this.lbfProvider);
+ EasyMock.replay(this.lbfProvider, engine);
this.modClusterService.status(engine);
- EasyMock.verify(this.lbfProvider);
- EasyMock.reset(this.lbfProvider);
+ EasyMock.verify(this.lbfProvider, engine);
+ EasyMock.reset(this.lbfProvider, engine);
}
}
16 years, 3 months
JBoss Native SVN: r1909 - trunk/mod_cluster/native/mod_proxy_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-09-26 05:19:02 -0400 (Fri, 26 Sep 2008)
New Revision: 1909
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Oops I am counting wrong.
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-09-26 01:38:03 UTC (rev 1908)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-09-26 09:19:02 UTC (rev 1909)
@@ -707,7 +707,7 @@
/* check for /context[/] in the URL */
len = strlen(context->context);
if (strncmp(r->uri, context->context, len) == 0) {
- if (r->uri[len] == '\0' || r->uri[len-1] == '/') {
+ if (r->uri[len] == '\0' || r->uri[len] == '/') {
/* Check status */
switch (context->status)
{
16 years, 3 months
JBoss Native SVN: r1908 - trunk/mod_cluster/src/main/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-25 21:38:03 -0400 (Thu, 25 Sep 2008)
New Revision: 1908
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
Log:
Removed debug log
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-26 01:23:03 UTC (rev 1907)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-26 01:38:03 UTC (rev 1908)
@@ -567,7 +567,6 @@
loadBalanceFactors.put(jvmRoute, lbf);
}
}
- this.log.info(loadBalanceFactors);
// FIXME handle crashed members, gone from DRM
// Advise the proxies of any reset requests
16 years, 3 months
JBoss Native SVN: r1907 - trunk/mod_cluster/src/main/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-25 21:23:03 -0400 (Thu, 25 Sep 2008)
New Revision: 1907
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
Log:
Refactored ModClusterService to clean up the conflicting strategies of extending DefaultJBossWebEventHandler and delegating to it.
I'll clean this implementation up later.
JBossWebEventHandler.config(Engine) and removeAll(Engine) are obsolete.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-25 16:53:57 UTC (rev 1906)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-26 01:23:03 UTC (rev 1907)
@@ -191,7 +191,7 @@
}
}
- public void config(Engine engine)
+ protected void config(Engine engine)
{
log.debug(this.sm.getString("modcluster.engine.config", engine.getName()));
@@ -264,7 +264,7 @@
}
}
- public void removeAll(Engine engine)
+ protected void removeAll(Engine engine)
{
this.checkInit();
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandler.java 2008-09-25 16:53:57 UTC (rev 1906)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandler.java 2008-09-26 01:23:03 UTC (rev 1907)
@@ -43,12 +43,8 @@
void removeContext(Context context);
- void config(Engine engine);
-
- void removeAll(Engine engine);
-
void status(Engine engine);
-
+
void startServer(Server server);
void stopServer(Server server);
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-25 16:53:57 UTC (rev 1906)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-26 01:23:03 UTC (rev 1907)
@@ -100,16 +100,16 @@
*/
final StringManager sm = StringManager.getManager(Constants.Package);
- private final LoadBalanceFactorProvider loadManager;
+ final LoadBalanceFactorProvider loadManager;
private final RpcHandler rpcHandler;
private final JBossWebEventHandler eventHandlerDelegate;
private final String domain;
private final boolean masterPerDomain;
volatile int latestLoad;
- private volatile int statusCount = 0;
- private volatile int processStatusFrequency = 1;
- private ModClusterServiceDRMEntry drmEntry;
+ volatile int statusCount = 0;
+ volatile int processStatusFrequency = 1;
+ ModClusterServiceDRMEntry drmEntry;
/**
* Create a new ClusterCoordinator.
@@ -149,10 +149,10 @@
this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this, this);
this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource);
-// this.localHandler.init();
this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this, this);
this.loadManager = loadFactorProvider;
- this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config, config, this.clusteredHandler, loadFactorProvider);
+ this.eventHandlerDelegate = new ClusteredJBossWebEventHandler(config, loadFactorProvider);
+// this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config, config, this.clusteredHandler, loadFactorProvider);
this.domain = config.getDomain();
this.masterPerDomain = config.isMasterPerDomain();
@@ -259,100 +259,48 @@
public void init()
{
- // Use the standard logic
this.eventHandlerDelegate.init();
}
public void shutdown()
{
- // Use the standard logic
this.eventHandlerDelegate.shutdown();
}
-
public void startServer(Server server)
{
- // Pass on ref to our server
- this.resetRequestSource.setJbossWebServer(server);
-
- // Use the standard logic
this.eventHandlerDelegate.startServer(server);
}
public void stopServer(Server server)
{
- // Use the standard logic
this.eventHandlerDelegate.stopServer(server);
}
- public void config(Engine engine)
- {
- // If needed, create automagical JVM route (address + port + engineName)
- try
- {
- Utils.establishJvmRouteAndConnectorAddress(engine, this.clusteredHandler);
- }
- catch (Exception e) {
- this.clusteredHandler.markProxiesInError();
- this.log.info(this.sm.getString("modcluster.error.addressJvmRoute"), e);
- return;
- }
-
- this.drmEntry.addJvmRoute(engine.getJvmRoute());
- this.updateLocalDRM(this.drmEntry);
-
- // Use the standard logic
- this.eventHandlerDelegate.config(engine);
- }
-
- public void removeAll(Engine engine)
- {
- // Use the standard logic
- this.eventHandlerDelegate.removeAll(engine);
-
- this.drmEntry.removeJvmRoute(engine.getJvmRoute());
- this.updateLocalDRM(this.drmEntry);
- }
-
public void addContext(Context context)
{
- // Use the standard logic
this.eventHandlerDelegate.addContext(context);
}
public void startContext(Context context)
{
- // Use the standard logic
this.eventHandlerDelegate.startContext(context);
}
public void stopContext(Context context)
{
- // Use the standard logic
this.eventHandlerDelegate.stopContext(context);
}
public void removeContext(Context context)
{
- // Use the standard logic
this.eventHandlerDelegate.removeContext(context);
}
public void status(Engine engine)
{
- this.latestLoad = this.loadManager.getLoadBalanceFactor();
-
- if (this.isMasterNode())
- {
- this.statusCount = (this.statusCount + 1) % this.processStatusFrequency;
-
- if (this.statusCount == 0)
- {
- this.updateClusterStatus();
- }
- }
+ this.eventHandlerDelegate.status(engine);
}
-
// ------------------------------------------------------------- Properties
@@ -370,7 +318,6 @@
{
this.processStatusFrequency = processStatusFrequency;
}
-
// ------------------------------------------------------- Public Overrides
@@ -485,115 +432,129 @@
}
@SuppressWarnings("unchecked")
- private void updateClusterStatus()
+ void updateClusterStatus()
{
- this.localHandler.status();
Set<MCMPServerState> masterList = null;
Map<ClusterNode, MCMPServerDiscoveryEvent> latestEvents = null;
- synchronized (this.proxyChangeDigest)
- {
- masterList = this.localHandler.getProxyStates();
- latestEvents = new HashMap<ClusterNode, MCMPServerDiscoveryEvent>(this.proxyChangeDigest);
- }
- HAPartition partition = this.getHAPartition();
- List<ModClusterServiceDRMEntry> replicants = partition.getDistributedReplicantManager().lookupReplicants(this.getHAServiceKey());
Map<ClusterNode, ModClusterServiceDRMEntry> nonresponsive = new HashMap<ClusterNode, ModClusterServiceDRMEntry>();
- for (ModClusterServiceDRMEntry replicant: replicants)
- {
- nonresponsive.put(replicant.getPeer(), replicant);
- }
- nonresponsive.remove(partition.getClusterNode());
-
- // FIXME -- what about our own dropped discovery events if we just became master?
- List responses = this.getClusterCoordinatorState(masterList);
-
- // Gather up all the reset requests in one list
- // FIXME -- what about our own dropped requests if we just became master?
- List<MCMPRequest> resetRequests = new ArrayList<MCMPRequest>();
-
- // Gather all the load balance factors
Map<String, Integer> loadBalanceFactors = new HashMap<String, Integer>();
-
- // Gather the info on who knows about what proxies
Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses = new HashMap<ClusterNode, PeerMCMPDiscoveryStatus>();
+ List<MCMPRequest> resetRequests = new ArrayList<MCMPRequest>();
+ HAPartition partition = this.getHAPartition();
+ DistributedReplicantManager drm = partition.getDistributedReplicantManager();
+ boolean resync = false;
- boolean resync = false;
- for (Object response: responses)
+ do
{
- if (response instanceof ModClusterServiceStateGroupRpcResponse)
+ this.localHandler.status();
+
+ synchronized (this.proxyChangeDigest)
{
- ModClusterServiceStateGroupRpcResponse mcssgrr = (ModClusterServiceStateGroupRpcResponse) response;
- ClusterNode cn = mcssgrr.getSender();
-
- // Check for discovery events we haven't processed
- MCMPServerDiscoveryEvent latestEvent = latestEvents.get(cn);
- for (MCMPServerDiscoveryEvent toCheck: mcssgrr.getUnacknowledgedEvents())
+ masterList = this.localHandler.getProxyStates();
+ latestEvents = new HashMap<ClusterNode, MCMPServerDiscoveryEvent>(this.proxyChangeDigest);
+ }
+
+ List<ModClusterServiceDRMEntry> replicants = drm.lookupReplicants(this.getHAServiceKey());
+ nonresponsive.clear();
+
+ for (ModClusterServiceDRMEntry replicant: replicants)
+ {
+ nonresponsive.put(replicant.getPeer(), replicant);
+ }
+ nonresponsive.remove(partition.getClusterNode());
+
+ // FIXME -- what about our own dropped discovery events if we just became master?
+ List responses = this.getClusterCoordinatorState(masterList);
+
+ // Gather up all the reset requests in one list
+ // FIXME -- what about our own dropped requests if we just became master?
+ resetRequests.clear();
+
+ // Gather all the load balance factors
+ loadBalanceFactors.clear();
+
+ // Add our own lbf - it is not returned via getclusterCoordinatorState(...)
+ for (String jvmRoute: this.drmEntry.getJvmRoutes())
+ {
+ loadBalanceFactors.put(jvmRoute, this.latestLoad);
+ }
+
+ // Gather the info on who knows about what proxies
+ statuses.clear();
+
+ for (Object response: responses)
+ {
+ if (response instanceof ModClusterServiceStateGroupRpcResponse)
{
- if (latestEvent != null && latestEvent.getEventIndex() <= toCheck.getEventIndex())
+ ModClusterServiceStateGroupRpcResponse mcssgrr = (ModClusterServiceStateGroupRpcResponse) response;
+ ClusterNode cn = mcssgrr.getSender();
+
+ // Check for discovery events we haven't processed
+ MCMPServerDiscoveryEvent latestEvent = latestEvents.get(cn);
+
+ for (MCMPServerDiscoveryEvent toCheck: mcssgrr.getUnacknowledgedEvents())
{
- continue; // already processed it
- }
-
- AddressPort ap = toCheck.getMCMPServer();
- if (toCheck.isAddition())
- {
- this.localHandler.addProxy(ap.getAddress(), ap.getPort());
- }
- else
- {
- this.localHandler.removeProxy(ap.getAddress(), ap.getPort());
- }
- resync = true;
- }
-
- if (!resync) // don't bother if we are going to start over
- {
- statuses.put(cn, new PeerMCMPDiscoveryStatus(cn, mcssgrr.getStates(), latestEvent));
+ if (latestEvent != null && latestEvent.getEventIndex() <= toCheck.getEventIndex())
+ {
+ continue; // already processed it
+ }
- List<MCMPRequest> toAdd = mcssgrr.getResetRequests();
- if (toAdd != null)
- {
- resetRequests.addAll(toAdd);
+ AddressPort ap = toCheck.getMCMPServer();
+ if (toCheck.isAddition())
+ {
+ this.localHandler.addProxy(ap.getAddress(), ap.getPort());
+ }
+ else
+ {
+ this.localHandler.removeProxy(ap.getAddress(), ap.getPort());
+ }
+ resync = true;
}
- ModClusterServiceDRMEntry removed = nonresponsive.remove(cn);
- if (removed != null)
+ if (!resync) // don't bother if we are going to start over
{
- Integer lbf = Integer.valueOf(mcssgrr.getLoadBalanceFactor());
- for (String jvmRoute: removed.getJvmRoutes())
+ statuses.put(cn, new PeerMCMPDiscoveryStatus(cn, mcssgrr.getStates(), latestEvent));
+
+ List<MCMPRequest> toAdd = mcssgrr.getResetRequests();
+ if (toAdd != null)
{
- loadBalanceFactors.put(jvmRoute, lbf);
+ resetRequests.addAll(toAdd);
}
+
+ ModClusterServiceDRMEntry removed = nonresponsive.remove(cn);
+ if (removed != null)
+ {
+ Integer lbf = Integer.valueOf(mcssgrr.getLoadBalanceFactor());
+ for (String jvmRoute: removed.getJvmRoutes())
+ {
+ loadBalanceFactors.put(jvmRoute, lbf);
+ }
+ }
}
}
+ else if (response instanceof ThrowableGroupRpcResponse)
+ {
+ ThrowableGroupRpcResponse tgrr = (ThrowableGroupRpcResponse) response;
+ ClusterNode cn = tgrr.getSender();
+
+ this.log.warn(this.sm.getString("modcluster.error.rpc.known", "getClusterCoordinatorState", cn), tgrr.getValue());
+
+ // Don't remove from nonresponsive list and we'll pass back an error
+ // status (null server list) to this peer
+ }
+ else if (response instanceof Throwable)
+ {
+ this.log.warn(this.sm.getString("modcluster.error.rpc.unknown", "getClusterCoordinatorState"), (Throwable) response);
+ }
+ else
+ {
+ this.log.error(this.sm.getString("modcluster.error.rpc.unexpected", response, "getClusterCoordinatorState"));
+ }
}
- else if (response instanceof ThrowableGroupRpcResponse)
- {
- ThrowableGroupRpcResponse tgrr = (ThrowableGroupRpcResponse) response;
- ClusterNode cn = tgrr.getSender();
-
- this.log.warn(this.sm.getString("modcluster.error.rpc.known", "getClusterCoordinatorState", cn), tgrr.getValue());
-
- // Don't remove from nonresponsive list and we'll pass back an error
- // status (null server list) to this peer
- }
- else if (response instanceof Throwable)
- {
- this.log.warn(this.sm.getString("modcluster.error.rpc.unknown", "getClusterCoordinatorState"), (Throwable) response);
- }
- else
- {
- this.log.error(this.sm.getString("modcluster.error.rpc.unexpected", response, "getClusterCoordinatorState"));
- }
}
+ // We picked up previously unknown discovery events; start over
+ while (resync);
- if (resync)
- {
- // We picked up previously unknown discovery events; start over
- this.updateClusterStatus();
- return;
- }
-
// Add error-state objects for non-responsive peers
Integer lbf = Integer.valueOf(0);
for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry: nonresponsive.entrySet())
@@ -606,7 +567,7 @@
loadBalanceFactors.put(jvmRoute, lbf);
}
}
-
+ this.log.info(loadBalanceFactors);
// FIXME handle crashed members, gone from DRM
// Advise the proxies of any reset requests
@@ -689,7 +650,7 @@
}
}
- private void updateLocalDRM(ModClusterServiceDRMEntry ourNewStatus)
+ void updateLocalDRM(ModClusterServiceDRMEntry ourNewStatus)
{
try
{
@@ -902,4 +863,82 @@
return new ResetRequestGroupRpcResponse(node, requests);
}
}
+
+ private class ClusteredJBossWebEventHandler extends DefaultJBossWebEventHandler
+ {
+ /**
+ * Create a new ClusteredJBossWebEventHandler.
+ *
+ * @param nodeConfig
+ * @param balancerConfig
+ * @param mcmpHandlerConfig
+ * @param mcmpHandler
+ * @param loadBalanceFactorProvider
+ */
+ public ClusteredJBossWebEventHandler(ModClusterConfig config, LoadBalanceFactorProvider loadBalanceFactorProvider)
+ {
+ // FIXME ClusteredJBossWebEventHandler constructor
+ super(config, config, config, ModClusterService.this.clusteredHandler, loadBalanceFactorProvider);
+ }
+
+ @Override
+ public void startServer(Server server)
+ {
+ // Pass on ref to our server
+ ModClusterService.this.resetRequestSource.setJbossWebServer(server);
+
+ super.startServer(server);
+ }
+
+ @Override
+ protected void config(Engine engine)
+ {
+ // If needed, create automagical JVM route (address + port + engineName)
+ try
+ {
+ Utils.establishJvmRouteAndConnectorAddress(engine, ModClusterService.this.clusteredHandler);
+ }
+ catch (Exception e) {
+ ModClusterService.this.clusteredHandler.markProxiesInError();
+ log.info(ModClusterService.this.sm.getString("modcluster.error.addressJvmRoute"), e);
+ return;
+ }
+
+ ModClusterService.this.drmEntry.addJvmRoute(engine.getJvmRoute());
+ ModClusterService.this.updateLocalDRM(ModClusterService.this.drmEntry);
+
+ super.config(engine);
+ }
+
+ @Override
+ protected void removeAll(Engine engine)
+ {
+ super.removeAll(engine);
+
+ ModClusterService.this.drmEntry.removeJvmRoute(engine.getJvmRoute());
+ ModClusterService.this.updateLocalDRM(ModClusterService.this.drmEntry);
+ }
+
+ @Override
+ public void status(Engine engine)
+ {
+ log.info(ModClusterService.this.sm.getString("modcluster.engine.status", engine.getName()));
+
+ ModClusterService.this.latestLoad = ModClusterService.this.loadManager.getLoadBalanceFactor();
+
+ if (ModClusterService.this.isMasterNode())
+ {
+ ModClusterService.this.statusCount = (ModClusterService.this.statusCount + 1) % ModClusterService.this.processStatusFrequency;
+
+ if (ModClusterService.this.statusCount == 0)
+ {
+ ModClusterService.this.updateClusterStatus();
+ }
+ }
+ else
+ {
+ log.info("We are not master");
+ }
+ }
+ }
}
16 years, 3 months
JBoss Native SVN: r1906 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-25 12:53:57 -0400 (Thu, 25 Sep 2008)
New Revision: 1906
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Rollback last few desperate debugging measures.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 16:09:59 UTC (rev 1905)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 16:53:57 UTC (rev 1906)
@@ -785,7 +785,7 @@
else
{
proxy.setState(Proxy.State.ERROR);
- log.error(this.sm.getString("modcluster.error.other", new Object[] { command, proxy, errorType, message, responseStatus }));
+ log.error(this.sm.getString("modcluster.error.other", command, proxy, errorType, message));
}
}
catch (IOException e)
@@ -947,8 +947,6 @@
{
this.socket = this.socketFactory.createSocket(this.address, this.port);
this.socket.setSoTimeout(this.socketTimeout);
- this.reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
- this.writer = new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream()));
}
return this.socket;
}
@@ -956,18 +954,24 @@
/**
* Convenience method that returns a reader to the proxy.
*/
- BufferedReader getConnectionReader() throws IOException
+ synchronized BufferedReader getConnectionReader() throws IOException
{
- this.getConnection();
+ if (this.reader == null)
+ {
+ this.reader = new BufferedReader(new InputStreamReader(this.getConnection().getInputStream()));
+ }
return this.reader;
}
/**
* Convenience method that returns a writer to the proxy.
*/
- BufferedWriter getConnectionWriter() throws IOException
+ synchronized BufferedWriter getConnectionWriter() throws IOException
{
- this.getConnection();
+ if (this.writer == null)
+ {
+ this.writer = new BufferedWriter(new OutputStreamWriter(this.getConnection().getOutputStream()));
+ }
return this.writer;
}
16 years, 3 months
JBoss Native SVN: r1905 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-25 12:09:59 -0400 (Thu, 25 Sep 2008)
New Revision: 1905
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
oops - last commit caused NullPointerException
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 15:35:33 UTC (rev 1904)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 16:09:59 UTC (rev 1905)
@@ -956,16 +956,18 @@
/**
* Convenience method that returns a reader to the proxy.
*/
- BufferedReader getConnectionReader()
+ BufferedReader getConnectionReader() throws IOException
{
+ this.getConnection();
return this.reader;
}
/**
* Convenience method that returns a writer to the proxy.
*/
- BufferedWriter getConnectionWriter()
+ BufferedWriter getConnectionWriter() throws IOException
{
+ this.getConnection();
return this.writer;
}
16 years, 3 months
JBoss Native SVN: r1904 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-25 11:35:33 -0400 (Thu, 25 Sep 2008)
New Revision: 1904
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Create socket and i/o streams atomically
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 15:12:06 UTC (rev 1903)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 15:35:33 UTC (rev 1904)
@@ -947,6 +947,8 @@
{
this.socket = this.socketFactory.createSocket(this.address, this.port);
this.socket.setSoTimeout(this.socketTimeout);
+ this.reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
+ this.writer = new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream()));
}
return this.socket;
}
@@ -954,24 +956,16 @@
/**
* Convenience method that returns a reader to the proxy.
*/
- synchronized BufferedReader getConnectionReader() throws IOException
+ BufferedReader getConnectionReader()
{
- if (this.reader == null)
- {
- this.reader = new BufferedReader(new InputStreamReader(this.getConnection().getInputStream()));
- }
return this.reader;
}
/**
* Convenience method that returns a writer to the proxy.
*/
- synchronized BufferedWriter getConnectionWriter() throws IOException
+ BufferedWriter getConnectionWriter()
{
- if (this.writer == null)
- {
- this.writer = new BufferedWriter(new OutputStreamWriter(this.getConnection().getOutputStream()));
- }
return this.writer;
}
16 years, 3 months
JBoss Native SVN: r1903 - in trunk/mod_cluster/src/main/java/org/jboss/modcluster: mcmp/impl and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-25 11:12:06 -0400 (Thu, 25 Sep 2008)
New Revision: 1903
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/LocalStrings.properties
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Use response status instead
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/LocalStrings.properties
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/LocalStrings.properties 2008-09-25 15:09:40 UTC (rev 1902)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/LocalStrings.properties 2008-09-25 15:12:06 UTC (rev 1903)
@@ -23,7 +23,7 @@
modcluster.error.noproxy=No proxy list or URL configured, advertise disabled and no localhost available; connect connect to mod_cluster
modcluster.error.nonPositiveAttribute=Invalid {0} specified [{1}] - must be a positive number.
modcluster.error.nullAttribute=Value for attribute {0} cannot be null
-modcluster.error.other=Error {4} [{2}: {3}] sending command {0} to proxy {1}, configuration will be reset
+modcluster.error.other=Error [{2}: {3}: {4}] sending command {0} to proxy {1}, configuration will be reset
modcluster.error.iae.null=[{0}] is null
modcluster.error.iae.invalid="Invalid value [{0}] for [{1}]
modcluster.error.parse=Error parsing response header for command {0}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 15:09:40 UTC (rev 1902)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 15:12:06 UTC (rev 1903)
@@ -785,7 +785,7 @@
else
{
proxy.setState(Proxy.State.ERROR);
- log.error(this.sm.getString("modcluster.error.other", new Object[] { command, proxy, errorType, message, Integer.valueOf(status) }));
+ log.error(this.sm.getString("modcluster.error.other", new Object[] { command, proxy, errorType, message, responseStatus }));
}
}
catch (IOException e)
16 years, 3 months
JBoss Native SVN: r1902 - in trunk/mod_cluster/src/main/java/org/jboss/modcluster: mcmp/impl and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-25 11:09:40 -0400 (Thu, 25 Sep 2008)
New Revision: 1902
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/LocalStrings.properties
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Add status to modcluster.error.other message
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/LocalStrings.properties
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/LocalStrings.properties 2008-09-25 06:43:12 UTC (rev 1901)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/LocalStrings.properties 2008-09-25 15:09:40 UTC (rev 1902)
@@ -23,7 +23,7 @@
modcluster.error.noproxy=No proxy list or URL configured, advertise disabled and no localhost available; connect connect to mod_cluster
modcluster.error.nonPositiveAttribute=Invalid {0} specified [{1}] - must be a positive number.
modcluster.error.nullAttribute=Value for attribute {0} cannot be null
-modcluster.error.other=Error [{2}: {3}] sending command {0} to proxy {1}, configuration will be reset
+modcluster.error.other=Error {4} [{2}: {3}] sending command {0} to proxy {1}, configuration will be reset
modcluster.error.iae.null=[{0}] is null
modcluster.error.iae.invalid="Invalid value [{0}] for [{1}]
modcluster.error.parse=Error parsing response header for command {0}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 06:43:12 UTC (rev 1901)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-09-25 15:09:40 UTC (rev 1902)
@@ -785,7 +785,7 @@
else
{
proxy.setState(Proxy.State.ERROR);
- log.error(this.sm.getString("modcluster.error.other", command, proxy, errorType, message));
+ log.error(this.sm.getString("modcluster.error.other", new Object[] { command, proxy, errorType, message, Integer.valueOf(status) }));
}
}
catch (IOException e)
16 years, 3 months