Author: jfrederic.clere(a)jboss.com
Date: 2008-10-17 12:35:49 -0400 (Fri, 17 Oct 2008)
New Revision: 1963
Added:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyRemove.java
Modified:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/MyCount.java
Log:
Add a test for StickyRemove (on cookie).
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-10-17 14:35:30 UTC
(rev 1962)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-10-17 16:35:49 UTC
(rev 1963)
@@ -53,6 +53,7 @@
private String node = null;
public int httpResponseCode = 0;
+ public String requestedSessionId = null;
/*
*
* Usage:
@@ -238,6 +239,13 @@
}
System.out.println("No cookies");
}
+ Header head =
bm.getResponseHeader("getRequestedSessionId");
+ if (head != null) {
+ HeaderElement[] heade = head.getElements();
+ requestedSessionId = heade[0].getValue();
+ } else {
+ requestedSessionId = null;
+ }
} else {
System.out.println("Not 200");
success = false;
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/MyCount.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/MyCount.java 2008-10-17 14:35:30 UTC
(rev 1962)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/MyCount.java 2008-10-17 16:35:49 UTC
(rev 1963)
@@ -55,7 +55,6 @@
out.println("<body>");
out.println("<h3>" + title + "</h3>");
-
HttpSession session = request.getSession(false);
Integer ii = new Integer(0);
if (session == null) {
@@ -128,6 +127,10 @@
out.println("</body>");
out.println("</html>");
+
+ /* Use headers */
+ response.setHeader("RequestedSessionId",
request.getRequestedSessionId());
+
}
public void doPost(HttpServletRequest request,
Added: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyRemove.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyRemove.java
(rev 0)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyRemove.java 2008-10-17
16:35:49 UTC (rev 1963)
@@ -0,0 +1,159 @@
+/*
+ * 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 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;
+
+public class TestStickyRemove extends TestCase {
+
+ StandardServer server = null;
+
+ /* Test failover */
+ public void testStickyRemove() {
+
+ boolean clienterror = false;
+ server = Maintest.getServer();
+ JBossWeb service = null;
+ JBossWeb service2 = null;
+ Connector connector = null;
+ Connector connector2 = null;
+ LifecycleListener cluster = null;
+ try {
+ // server = (StandardServer) ServerFactory.getServer();
+
+ service = new JBossWeb("node3", "localhost");
+ connector = service.addConnector(8009);
+ server.addService(service);
+
+ service2 = new JBossWeb("node4", "localhost");
+ connector2 = service2.addConnector(8889);
+ server.addService(service2);
+
+ cluster = Maintest.createClusterListener("232.0.0.2", 23364, false,
null, true, true, false);
+ server.addLifecycleListener(cluster);
+ Maintest.listServices();
+
+ } catch(IOException ex) {
+ ex.printStackTrace();
+ fail("can't start service");
+ }
+
+ // 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();
+ }
+
+ // Start the client and wait for it.
+ Client client = new Client();
+
+ // Wait for it.
+ try {
+ if (client.runit("http://localhost:7779/ROOT/MyCount", 10, false,
true) != 0)
+ clienterror = true;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ clienterror = true;
+ }
+
+ // Stop the connector that has received the request...
+ String node = client.getnode();
+ if ("node4".equals(node)) {
+ connector = connector2;
+ node = "node3";
+ } else {
+ node = "node4";
+ }
+ if (connector != null) {
+ try {
+ connector.stop();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ fail("can't stop connector");
+ }
+ }
+
+ if (clienterror)
+ fail("Client error");
+
+ // Run a test on it. (it waits until httpd as received the nodes information).
+ client.setnode(node);
+ try {
+ client.setdelay(30000);
+ client.start();
+ client.join();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ if (client.getresultok())
+ System.out.println("Test DONE");
+ else {
+ System.out.println("Test FAILED");
+ clienterror = true;
+ }
+
+ // Stop the server or services.
+ try {
+ wait.stopit();
+ wait.join();
+ server.removeService(service);
+ server.removeService(service2);
+ server.removeLifecycleListener(cluster);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+
+ // Wait until httpd as received the stop messages.
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+
+ // Test client result.
+ if (clienterror)
+ fail("Client test failed");
+ if (client.requestedSessionId != null)
+ fail("Client client received a sessionid");
+ }
+}
Show replies by date