[jboss-cvs] JBossAS SVN: r106184 - in branches/Branch_No_Multicast/testsuite: src/main/org/jboss/test/cluster and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 18 17:58:09 EDT 2010
Author: pferraro
Date: 2010-06-18 17:58:08 -0400 (Fri, 18 Jun 2010)
New Revision: 106184
Added:
branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/
branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/HAModClusterServiceTestCase.java
branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/MockProxy.java
branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/ModClusterServiceTestCase.java
Modified:
branches/Branch_No_Multicast/testsuite/imports/config/tests-clustering.xml
Log:
Add test targets for mod_cluster-ec2 profile.
Modified: branches/Branch_No_Multicast/testsuite/imports/config/tests-clustering.xml
===================================================================
--- branches/Branch_No_Multicast/testsuite/imports/config/tests-clustering.xml 2010-06-18 21:35:57 UTC (rev 106183)
+++ branches/Branch_No_Multicast/testsuite/imports/config/tests-clustering.xml 2010-06-18 21:58:08 UTC (rev 106184)
@@ -64,7 +64,10 @@
</patternset>
<patternset id="cluster.ustxsticky.includes">
<include name="org/jboss/test/cluster/defaultcfg/ejb2/ustxsticky/test/UserTransactionStickyUnitTestCase.class"/>
- </patternset>
+ </patternset>
+ <patternset id="cluster.mod_cluster.includes">
+ <include name="org/jboss/test/cluster/mod_cluster/ModClusterServiceTestCase.class"/>
+ </patternset>
<patternset id="cluster.excludes">
<exclude name="org/jboss/test/cluster/**/*TestCase.class"/>
</patternset>
@@ -464,41 +467,81 @@
</target>
- <target name="tests-clustering-cluster-ec2">
-
- <!-- Create tests-configs content for cluster-tcp-0/1 from the cluster-udp content -->
- <mkdir dir="${build.resources}/test-configs/cluster-tcp-0"/>
- <copy todir="${build.resources}/test-configs/cluster-tcp-0">
- <fileset dir="${build.resources}/test-configs/cluster-udp-0" />
- </copy>
- <mkdir dir="${build.resources}/test-configs/cluster-tcp-1"/>
- <copy todir="${build.resources}/test-configs/cluster-tcp-1">
- <fileset dir="${build.resources}/test-configs/cluster-udp-1" />
- </copy>
+ <target name="tests-clustering-cluster-ec2">
+
+ <!-- Create tests-configs content for cluster-tcp-0/1 from the cluster-udp content -->
+ <mkdir dir="${build.resources}/test-configs/cluster-tcp-0"/>
+ <copy todir="${build.resources}/test-configs/cluster-tcp-0">
+ <fileset dir="${build.resources}/test-configs/cluster-udp-0" />
+ </copy>
+ <mkdir dir="${build.resources}/test-configs/cluster-tcp-1"/>
+ <copy todir="${build.resources}/test-configs/cluster-tcp-1">
+ <fileset dir="${build.resources}/test-configs/cluster-udp-1" />
+ </copy>
+
+ <antcall target="tests-clustering">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+ <antcall target="run-clustered-ustxsticky-tests">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+ <antcall target="run-clustered-profileservice-tests">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+ <antcall target="run-tomcat-sso-clustered-tests">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+
+ </target>
+
+ <target name="tests-mod_cluster-ec2">
+
+ <!-- Create tests-configs content for cluster-tcp-0/1 from the cluster-udp content -->
+ <mkdir dir="${build.resources}/test-configs/cluster-tcp-0"/>
+ <copy todir="${build.resources}/test-configs/cluster-tcp-0">
+ <fileset dir="${build.resources}/test-configs/cluster-udp-0" />
+ </copy>
+ <mkdir dir="${build.resources}/test-configs/cluster-tcp-1"/>
+ <copy todir="${build.resources}/test-configs/cluster-tcp-1">
+ <fileset dir="${build.resources}/test-configs/cluster-udp-1" />
+ </copy>
+
+ <antcall target="tests-clustering">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="mod_cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+ <antcall target="tests-mod_cluster">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="mod_cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+ <antcall target="run-clustered-ustxsticky-tests">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="mod_cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+ <antcall target="run-clustered-profileservice-tests">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="mod_cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+ <antcall target="run-tomcat-sso-clustered-tests">
+ <param name="jboss.default.jgroups.stack" value="tcp"/>
+ <param name="baseconf" value="mod_cluster-ec2"/>
+ <param name="cluster.excludes.refid" value="ec2.excludes"/>
+ </antcall>
+
+ </target>
- <antcall target="tests-clustering">
- <param name="jboss.default.jgroups.stack" value="tcp"/>
- <param name="baseconf" value="cluster-ec2"/>
- <param name="cluster.excludes.refid" value="ec2.excludes"/>
- </antcall>
- <antcall target="run-clustered-ustxsticky-tests">
- <param name="jboss.default.jgroups.stack" value="tcp"/>
- <param name="baseconf" value="cluster-ec2"/>
- <param name="cluster.excludes.refid" value="ec2.excludes"/>
- </antcall>
- <antcall target="run-clustered-profileservice-tests">
- <param name="jboss.default.jgroups.stack" value="tcp"/>
- <param name="baseconf" value="cluster-ec2"/>
- <param name="cluster.excludes.refid" value="ec2.excludes"/>
- </antcall>
- <antcall target="run-tomcat-sso-clustered-tests">
- <param name="jboss.default.jgroups.stack" value="tcp"/>
- <param name="baseconf" value="cluster-ec2"/>
- <param name="cluster.excludes.refid" value="ec2.excludes"/>
- </antcall>
-
- </target>
-
<!--
This target gets around the fact that we cannot easily create a set of related
cluster configs using a single test-configs subdirectory. Rather than pollute the
@@ -907,4 +950,27 @@
</target>
+ <target name="tests-mod_cluster">
+
+ <mkdir dir="${build.reports}"/>
+ <mkdir dir="${build.testlog}"/>
+
+ <create-cluster-node-from-baseconf conf="mod_cluster-ec2-0" baseconf="${baseconf}"/>
+ <create-cluster-node-from-baseconf conf="mod_cluster-ec2-1" baseconf="${baseconf}"/>
+
+ <server:start name="mod_cluster-ec2-0"/>
+ <server:start name="mod_cluster-ec2-1"/>
+
+ <antcall target="tests-clustering-unit">
+ <param name="cluster.includes.refid" value="cluster.mod_cluster.includes"/>
+ <param name="jboss-junit-configuration" value="Default-${jboss.default.jgroups.stack}"/>
+ <param name="jbosstest.cluster.node0.config" value="mod_cluster-ec2-0"/>
+ <param name="jbosstest.cluster.node1.config" value="mod_cluster-ec2-1"/>
+ </antcall>
+
+ <server:stop name="mod_cluster-ec2-0"/>
+ <server:stop name="mod_cluster-ec2-1"/>
+
+ </target>
+
</project>
Added: branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/HAModClusterServiceTestCase.java
===================================================================
--- branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/HAModClusterServiceTestCase.java (rev 0)
+++ branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/HAModClusterServiceTestCase.java 2010-06-18 21:58:08 UTC (rev 106184)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.mod_cluster;
+
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import junit.framework.Assert;
+
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class HAModClusterServiceTestCase extends JBossClusteredTestCase
+{
+ private static final String ENGINE = "jboss.web";
+ private static final int PORT = 8009;
+
+ private MockProxy proxy = new MockProxy(2);
+
+ /**
+ * Create a new ModClusterServiceTestCase.
+ *
+ * @param name
+ */
+ public HAModClusterServiceTestCase(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ this.proxy.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ this.proxy.stop();
+
+ super.tearDown();
+ }
+
+ public void testInfo() throws Exception
+ {
+ MBeanServerConnection[] servers = this.getAdaptors();
+
+ ObjectName name = ObjectName.getInstance("jboss.web:service=ModCluster");
+
+ servers[0].invoke(name, "addProxy", new Object[] { "127.0.0.1", this.proxy.getPort() }, new String[] { String.class.getName(), Integer.TYPE.getName() });
+
+ // Wait the duration of at least 1 status interval
+ Thread.sleep(20000);
+
+ // Proxy should have received:
+ // 1. INFO - to establish proxy connectivity
+ // 2. CONFIG - to configure proxy
+ // 3. STATUS - periodic status
+
+ List<Map.Entry<String, Map<String, String>>> requests = new LinkedList<Map.Entry<String, Map<String, String>>>();
+
+ int count = this.proxy.getRequests().drainTo(requests);
+
+ Assert.assertEquals(requests.toString(), 2, count);
+
+ for (Map.Entry<String, Map<String, String>> infoRequest: requests)
+ {
+ String command = infoRequest.getKey();
+ Map<String, String> parameters = infoRequest.getValue();
+
+ Assert.assertTrue(command, command.startsWith("INFO"));
+ Assert.assertFalse(command.contains("*"));
+ Assert.assertTrue(parameters.isEmpty());
+ }
+
+ String[] hosts = this.getServers();
+ ByteBuffer buffer = ByteBuffer.allocate(InetAddress.getLocalHost().getAddress().length + (Integer.SIZE / Byte.SIZE) + ENGINE.getBytes().length);
+
+ for (int i = 0; i < hosts.length; ++i)
+ {
+ String host = InetAddress.getByName(hosts[i]).getHostAddress();
+
+ requests.clear();
+
+ buffer.clear();
+ buffer.put(InetAddress.getByName(hosts[i]).getAddress());
+ buffer.putInt(PORT);
+ buffer.put(ENGINE.getBytes());
+
+ String jvmRoute = UUID.nameUUIDFromBytes(buffer.array()).toString();
+
+ count = this.proxy.getRequests(jvmRoute).drainTo(requests);
+
+ Assert.assertTrue(requests.toString(), count >= 2);
+
+ Map.Entry<String, Map<String, String>> configRequest = requests.get(0);
+ String command = configRequest.getKey();
+ Map<String, String> parameters = configRequest.getValue();
+
+ Assert.assertTrue(command, command.startsWith("CONFIG"));
+ Assert.assertFalse(command.contains("*"));
+ Assert.assertEquals(parameters.toString(), 6, parameters.size());
+ Assert.assertEquals(String.valueOf(PORT), parameters.get("Port"));
+ Assert.assertEquals(host, parameters.get("Host"));
+ Assert.assertEquals("ajp", parameters.get("Type"));
+ Assert.assertEquals(jvmRoute, parameters.get("JVMRoute"));
+ Assert.assertEquals("No", parameters.get("StickySessionForce"));
+ Assert.assertEquals("1", parameters.get("Maxattempts"));
+
+ for (Map.Entry<String, Map<String, String>> statusRequest: requests.subList(1, requests.size()))
+ {
+ command = statusRequest.getKey();
+ parameters = statusRequest.getValue();
+
+ Assert.assertTrue(command, command.startsWith("STATUS"));
+ Assert.assertFalse(command.contains("*"));
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals(jvmRoute, parameters.get("JVMRoute"));
+ String value = parameters.get("Load");
+ Assert.assertNotNull(value);
+ int load = Integer.parseInt(value);
+ Assert.assertTrue(0 <= load);
+ Assert.assertTrue(load <= 100);
+ }
+ }
+ }
+}
Added: branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/MockProxy.java
===================================================================
--- branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/MockProxy.java (rev 0)
+++ branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/MockProxy.java 2010-06-18 21:58:08 UTC (rev 106184)
@@ -0,0 +1,266 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.mod_cluster;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Mock httpd proxy that queues all received messages
+ * @author Paul Ferraro
+ */
+ at SuppressWarnings("boxing")
+public class MockProxy implements Runnable
+{
+ private final BlockingQueue<Map.Entry<String, Map<String, String>>> requests = new LinkedBlockingQueue<Map.Entry<String, Map<String, String>>>();
+ private final ConcurrentMap<String, BlockingQueue<Map.Entry<String, Map<String, String>>>> requestMap = new ConcurrentHashMap<String, BlockingQueue<Map.Entry<String, Map<String, String>>>>();
+
+ private ServerSocket server;
+ private final List<Thread> workers;
+ private final int threads;
+
+ private volatile boolean healthy = true;
+
+ public MockProxy(int threads)
+ {
+ this.workers = new ArrayList<Thread>(threads);
+ this.threads = threads;
+ }
+
+ public void run()
+ {
+ try
+ {
+ while (!Thread.currentThread().isInterrupted())
+ {
+ try
+ {
+ Socket socket = this.server.accept();
+ socket.setSoTimeout(15000);
+
+ try
+ {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
+
+ String line = reader.readLine();
+
+ while ((line != null) && !Thread.currentThread().isInterrupted())
+ {
+ if (line.length() == 0)
+ {
+ line = reader.readLine();
+ continue;
+ }
+
+ String command = line;
+ System.out.println("Received command: " + command);
+ line = reader.readLine();
+
+ while ((line != null) && (line.length() > 0))
+ {
+ // Ignore headers
+ line = reader.readLine();
+ }
+
+ if (line != null)
+ {
+ line = reader.readLine();
+ System.out.println("Received body: " + line);
+ }
+
+ Map<String, String> parameters = new HashMap<String, String>();
+
+ if (line != null)
+ {
+ if (line.length() > 0)
+ {
+ for (String parameter: line.split("&"))
+ {
+ String[] parts = parameter.split("=");
+
+ String name = parts[0];
+ String value = URLDecoder.decode(parts[1], "UTF-8");
+
+ parameters.put(name, value);
+ }
+ System.out.println("Parsed body: " + line);
+ }
+
+ if (this.healthy)
+ {
+ writer.write("HTTP/1.0 200 OK");
+ }
+ else
+ {
+ writer.write("HTTP/1.0 500 ERROR");
+ }
+
+ writer.newLine();
+ writer.newLine();
+ writer.flush();
+ }
+
+ Map.Entry<String, Map<String, String>> request = Collections.singletonMap(command, parameters).entrySet().iterator().next();
+
+ System.out.println("Received: " + request);
+ String jvmRoute = parameters.get("JVMRoute");
+
+ if (jvmRoute == null)
+ {
+ this.requests.add(request);
+ }
+ else
+ {
+ this.getRequests(jvmRoute).add(request);
+ }
+ Thread.yield();
+ if (line != null)
+ {
+ line = reader.readLine();
+ }
+ }
+ }
+ finally
+ {
+ if (socket.isConnected())
+ {
+ try
+ {
+ socket.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+ }
+ catch (SocketException e)
+ {
+ System.out.println("Socket accept interrupted");
+ }
+ catch (SocketTimeoutException e)
+ {
+ System.out.println("Socket accept timeout");
+ }
+ }
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ public void setHealty(boolean healthy)
+ {
+ this.healthy = healthy;
+ }
+
+ public BlockingQueue<Map.Entry<String, Map<String, String>>> getRequests()
+ {
+ return this.requests;
+ }
+
+ public BlockingQueue<Map.Entry<String, Map<String, String>>> getRequests(String jvmRoute)
+ {
+ BlockingQueue<Map.Entry<String, Map<String, String>>> newQueue = new LinkedBlockingQueue<Map.Entry<String, Map<String, String>>>();
+ BlockingQueue<Map.Entry<String, Map<String, String>>> queue = this.requestMap.putIfAbsent(jvmRoute, newQueue);
+ return (queue != null) ? queue : newQueue;
+ }
+
+ public int getPort()
+ {
+ return this.server.getLocalPort();
+ }
+
+ public void start() throws Exception
+ {
+ this.server = new ServerSocket(0, 200, null);
+ this.server.setSoTimeout(15000);
+
+ for (int i = 0; i < this.threads; ++i)
+ {
+ Thread thread = new Thread(this);
+
+ this.workers.add(thread);
+
+ thread.start();
+ }
+ }
+
+ public void stop()
+ {
+ for (Thread worker: this.workers)
+ {
+ if (worker != null)
+ {
+ worker.interrupt();
+ }
+ }
+
+ if (this.server != null)
+ {
+ try
+ {
+ this.server.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ for (Thread worker: this.workers)
+ {
+ try
+ {
+ worker.join();
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ this.workers.clear();
+ this.requestMap.clear();
+ this.requests.clear();
+ }
+}
\ No newline at end of file
Added: branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/ModClusterServiceTestCase.java
===================================================================
--- branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/ModClusterServiceTestCase.java (rev 0)
+++ branches/Branch_No_Multicast/testsuite/src/main/org/jboss/test/cluster/mod_cluster/ModClusterServiceTestCase.java 2010-06-18 21:58:08 UTC (rev 106184)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.mod_cluster;
+
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import junit.framework.Assert;
+
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * A ModClusterServiceTestCase.
+ *
+ * @author Paul Ferraro
+ */
+public class ModClusterServiceTestCase extends JBossClusteredTestCase
+{
+ private static final String ENGINE = "jboss.web";
+ private static final int PORT = 8009;
+
+ private MockProxy proxy = new MockProxy(2);
+
+ /**
+ * Create a new ModClusterServiceTestCase.
+ *
+ * @param name
+ */
+ public ModClusterServiceTestCase(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ this.proxy.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ this.proxy.stop();
+
+ super.tearDown();
+ }
+
+ public void testInfo() throws Exception
+ {
+ MBeanServerConnection[] servers = this.getAdaptors();
+
+ ObjectName name = ObjectName.getInstance("jboss.web:service=ModCluster");
+
+ String[] hosts = this.getServers();
+ ByteBuffer buffer = ByteBuffer.allocate(InetAddress.getLocalHost().getAddress().length + (Integer.SIZE / Byte.SIZE) + ENGINE.getBytes().length);
+
+ for (int i = 0; i < hosts.length; ++i)
+ {
+ String host = InetAddress.getByName(hosts[i]).getHostAddress();
+
+ servers[i].invoke(name, "addProxy", new Object[] { "127.0.0.1", this.proxy.getPort() }, new String[] { String.class.getName(), Integer.TYPE.getName() });
+
+ // Wait the duration of at least 1 status interval
+ Thread.sleep(20000);
+
+ // Proxy should have received:
+ // 1. INFO - to establish proxy connectivity
+ // 2. CONFIG - to configure proxy
+ // 3. STATUS - periodic status
+
+ List<Map.Entry<String, Map<String, String>>> requests = new LinkedList<Map.Entry<String, Map<String, String>>>();
+
+ int count = this.proxy.getRequests().drainTo(requests);
+
+ Assert.assertEquals(1, count);
+
+ for (Map.Entry<String, Map<String, String>> infoRequest: requests)
+ {
+ String command = infoRequest.getKey();
+ Map<String, String> parameters = infoRequest.getValue();
+
+ Assert.assertTrue(command, command.startsWith("INFO"));
+ Assert.assertFalse(command.contains("*"));
+ Assert.assertTrue(parameters.isEmpty());
+ }
+
+ requests.clear();
+
+ buffer.clear();
+ buffer.put(InetAddress.getByName(hosts[i]).getAddress());
+ buffer.putInt(PORT);
+ buffer.put(ENGINE.getBytes());
+
+ String jvmRoute = UUID.nameUUIDFromBytes(buffer.array()).toString();
+
+ count = this.proxy.getRequests(jvmRoute).drainTo(requests);
+
+ Assert.assertTrue(Integer.toString(count), count >= 2);
+
+ Map.Entry<String, Map<String, String>> configRequest = requests.get(0);
+ String command = configRequest.getKey();
+ Map<String, String> parameters = configRequest.getValue();
+
+ Assert.assertTrue(command, command.startsWith("CONFIG"));
+ Assert.assertFalse(command.contains("*"));
+ Assert.assertEquals(parameters.toString(), 6, parameters.size());
+ Assert.assertEquals(String.valueOf(PORT), parameters.get("Port"));
+ Assert.assertEquals(host, parameters.get("Host"));
+ Assert.assertEquals("ajp", parameters.get("Type"));
+ Assert.assertEquals(jvmRoute, parameters.get("JVMRoute"));
+ Assert.assertEquals("No", parameters.get("StickySessionForce"));
+ Assert.assertEquals("1", parameters.get("Maxattempts"));
+
+ for (Map.Entry<String, Map<String, String>> statusRequest: requests.subList(1, requests.size()))
+ {
+ command = statusRequest.getKey();
+ parameters = statusRequest.getValue();
+
+ Assert.assertTrue(command, command.startsWith("STATUS"));
+ Assert.assertFalse(command.contains("*"));
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals(jvmRoute, parameters.get("JVMRoute"));
+ String value = parameters.get("Load");
+ Assert.assertNotNull(value);
+ int load = Integer.parseInt(value);
+ Assert.assertTrue(0 <= load);
+ Assert.assertTrue(load <= 100);
+ }
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list