Author: jfrederic.clere(a)jboss.com
Date: 2008-07-11 07:49:22 -0400 (Fri, 11 Jul 2008)
New Revision: 1746
Added:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/NodeInfo.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestAddDel.java
Modified:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java
Log:
Add a test that adds and removes 10 nodes.
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java 2008-07-11 09:59:44
UTC (rev 1745)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java 2008-07-11 11:49:22
UTC (rev 1746)
@@ -49,6 +49,8 @@
public static Test suite() {
TestSuite suite = new TestSuite();
server = (StandardServer) ServerFactory.getServer();
+ suite.addTest(new TestSuite(TestAddDel.class));
+ System.gc();
suite.addTest(new TestSuite(TestBase.class));
System.gc();
suite.addTest(new TestSuite(TestFailover.class));
Added: trunk/mod_cluster/test/java/org/jboss/mod_cluster/NodeInfo.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/NodeInfo.java
(rev 0)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/NodeInfo.java 2008-07-11 11:49:22
UTC (rev 1746)
@@ -0,0 +1,81 @@
+/*
+ * mod_cluster
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision$
+ */
+
+package org.jboss.mod_cluster;
+
+import java.util.ArrayList;
+
+public class NodeInfo {
+ String JVMRoute;
+ int status;
+ int lbfactor;
+ int elected;
+ int removed;
+
+ /**
+ * Check that nodes in nodeinfos corresponds to nodes in nodenames
+ */
+ static public boolean check(ArrayList nodes, String [] nodenames)
+ {
+ boolean [] in = new boolean[nodenames.length];
+
+ if (nodes == null || nodenames == null)
+ return false;
+
+ NodeInfo [] nodeinfos = new NodeInfo[nodes.size()];
+ for (int i=0; i<nodeinfos.length; i++) {
+ nodeinfos[i] = (NodeInfo) nodes.get(i);
+ }
+
+ for (int i=0; i<nodenames.length; i++)
+ in[i] = false;
+
+ for (int i=0; i<nodenames.length; i++) {
+ boolean hasit = false;
+ for (int j=0; j<nodeinfos.length; j++) {
+ if (nodeinfos[j].JVMRoute.equals(nodenames[i])) {
+ if (in[i])
+ return false; // twice.
+ if (nodeinfos[j].removed == 0) {
+ in[i] = true;
+ hasit = true;
+ }
+ }
+ }
+ if (!hasit)
+ return false; // not found.
+ }
+ int i = 0;
+ for (int j=0; j<nodeinfos.length; j++) {
+ if (nodeinfos[j].removed == 0)
+ i++;
+ }
+ if (i != nodenames.length)
+ return false; // Too many route entries in httpd.
+ return true;
+ }
+}
Added: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestAddDel.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestAddDel.java
(rev 0)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestAddDel.java 2008-07-11 11:49:22
UTC (rev 1746)
@@ -0,0 +1,168 @@
+/*
+ * mod_cluster
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision$
+ */
+
+package org.jboss.mod_cluster;
+
+import java.io.IOException;
+
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+import org.apache.catalina.Engine;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardServer;
+
+import org.jboss.web.cluster.ClusterListener;
+
+public class TestAddDel extends TestCase {
+
+ /* Test */
+ public void testAddDel() {
+
+ boolean clienterror = false;
+ int numbnodes = 10;
+ String [] nodenames = new String [numbnodes];
+ JBossWeb [] service = new JBossWeb[numbnodes];
+ ClusterListener cluster = null;
+
+ StandardServer server = Maintest.getServer();
+ for (int i=0; i<numbnodes; i++) {
+ try {
+ // server = (StandardServer) ServerFactory.getServer();
+ String name = "node" + i;
+ nodenames[i] = name;
+ service[i] = new JBossWeb(name, "localhost");
+ service[i].addConnector(8009 + i);
+ server.addService(service[i]);
+
+ } catch(IOException ex) {
+ ex.printStackTrace();
+ fail("can't start service");
+ }
+ }
+
+ cluster = new ClusterListener();
+ cluster.setAdvertiseGroupAddress("232.0.0.2");
+ cluster.setAdvertisePort(23364);
+ cluster.setSsl(false);
+ // SSL ?
+ server.addLifecycleListener((LifecycleListener) cluster);
+
+ // Debug Stuff
+ Maintest.listServices();
+
+ // start the server thread.
+ ServerThread wait = new ServerThread(3000, server);
+ wait.start();
+
+ // Wait until httpd as received the nodes information.
+ try {
+ Thread.sleep(30000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+
+ // Read the result via INFO.
+ String result = cluster.getProxyInfo();
+ ArrayList nodes = new ArrayList();
+ if (result != null) {
+ System.out.println(result);
+ String [] records = result.split("\n");
+ int l = 0;
+ for (int i=0; i<records.length; i++) {
+ // System.out.println("records[" + i + "]: " +
records[i]);
+ NodeInfo nodeinfo = null;
+ String [] results = records[i].split(",");
+ for (int j=0; j<results.length; j++, l++) {
+ // System.out.println("results[" + j + "]: " +
results[j]);
+ String [] data = results[j].split(": ");
+ // System.out.println("data[" + 0 + "]: " +
data[0] + "*");
+ if ("node".equals(data[0]) && nodeinfo == null) {
+ nodeinfo = new NodeInfo();
+ continue;
+ }
+ if ("JVMRoute".equals(data[0])) {
+ nodeinfo.JVMRoute = data[1];
+ }
+ else if ("status".equals(data[0])) {
+ nodeinfo.status = Integer.valueOf(data[1]).intValue();
+ }
+ else if ("lbfactor".equals(data[0])) {
+ nodeinfo.lbfactor = Integer.valueOf(data[1]).intValue();
+ }
+ else if ("elected".equals(data[0])) {
+ nodeinfo.elected = Integer.valueOf(data[1]).intValue();
+ }
+ else if ("removed".equals(data[0])) {
+ nodeinfo.removed = Integer.valueOf(data[1]).intValue();
+ }
+ }
+ if (nodeinfo != null) {
+ // System.out.println("Adding: " + nodeinfo);
+ nodes.add(nodeinfo);
+ }
+ }
+ } else
+ clienterror = true;
+
+ // Check the nodes.
+ if (!clienterror) {
+ if (!NodeInfo.check(nodes, nodenames))
+ clienterror = true;
+ }
+
+ // Stop the jboss and remove the services.
+ try {
+ wait.stopit();
+ wait.join();
+
+ for (int i=0; i<numbnodes; i++) {
+ server.removeService(service[i]);
+ }
+ server.removeLifecycleListener(cluster);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ fail("can't stop service");
+ }
+ // Wait until httpd as received the stop messages.
+ System.gc();
+ try {
+ Thread.sleep(20000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+
+ if (clienterror)
+ fail("Client error");
+
+ }
+}
Show replies by date