Author: jfrederic.clere(a)jboss.com
Date: 2008-09-12 08:26:32 -0400 (Fri, 12 Sep 2008)
New Revision: 1815
Added:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/ClientBasicAuthen.java
Modified:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java
Log:
Arrange JBWEB_117 test. Special chunked stuff...
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-09-11 17:39:06 UTC
(rev 1814)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-09-12 12:26:32 UTC
(rev 1815)
@@ -127,9 +127,17 @@
HttpMethodBase bm = null;
if (fd != null) {
pm = new PostMethod(URL);
- pm.setRequestBody(fd);
+ // InputStreamRequestEntity buf = new InputStreamRequestEntity(fd);
+ // XXX: Ugly hack to test...
+ byte [] buffet = new byte[6144];
+ for (int i=0; i<buffet.length;i++)
+ buffet[i] = 'a';
+ ByteArrayRequestEntity buf = new ByteArrayRequestEntity(buffet);
+ pm.setRequestEntity(buf);
+ // pm.setRequestBody(fd);
pm.setHttp11(true);
- pm.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
+ pm.setContentChunked(true);
+ // pm.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
bm = pm;
} else if (post != null) {
pm = new PostMethod(URL);
Added: trunk/mod_cluster/test/java/org/jboss/mod_cluster/ClientBasicAuthen.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/ClientBasicAuthen.java
(rev 0)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/ClientBasicAuthen.java 2008-09-12
12:26:32 UTC (rev 1815)
@@ -0,0 +1,155 @@
+/*
+ * 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.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.ByteArrayInputStream;
+
+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;
+
+import org.apache.catalina.core.AprLifecycleListener;
+
+public class ClientBasicAuthen {
+
+ /* Tests for Basic Authentication needs (JBWEB-117.war) */
+ public static String test(boolean nat, File fd) {
+ InputStream in = null;
+ if (fd != null)
+ try {
+ in = new FileInputStream(fd);
+ } catch(IOException ex) {
+ ex.printStackTrace();
+ return("can't start service");
+ }
+ return test(nat, in);
+ }
+ public static String test(boolean nat, InputStream fd) {
+
+ boolean clienterror = false;
+ StandardServer server = Maintest.getServer();
+ JBossWeb service = null;
+ ClusterListener cluster = null;
+ try {
+ // server = (StandardServer) ServerFactory.getServer();
+
+ service = new JBossWeb("node1", "localhost", nat);
+ if (nat)
+ service.addConnector(8009,
"org.apache.coyote.ajp.AjpAprProtocol");
+ else
+ service.addConnector(8009, "ajp");
+
+ service.addWAR("JBWEB-117.war", "node1");
+ server.addService(service);
+
+ cluster = new ClusterListener();
+ cluster.setAdvertiseGroupAddress("232.0.0.2");
+ cluster.setAdvertisePort(23364);
+ cluster.setSsl(false);
+ // SSL ?
+ server.addLifecycleListener((LifecycleListener) cluster);
+
+ // Add AprLifecycleListener.
+ if (nat) {
+ AprLifecycleListener listener = new AprLifecycleListener();
+ server.addLifecycleListener((LifecycleListener) listener);
+ }
+
+ // Debug Stuff
+ Maintest.listServices();
+
+ } catch(IOException ex) {
+ ex.printStackTrace();
+ return("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(40000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+
+ // Start the client and wait for it.
+ Client client = new Client();
+
+ // Wait for it.
+ String data = "a";
+ for (int i=0; i<517; i++)
+ data = data.concat("a");
+ int ret = 0;
+ try {
+ ret = client.runit("http://localhost:7779/JBWEB-117/JBWEB_117", 1,
true, data, "manager" , "manager", fd);
+ client.start();
+ client.join();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ clienterror = true;
+ }
+
+ // Stop the jboss and remove the services.
+ try {
+ wait.stopit();
+ wait.join();
+
+ server.removeService(service);
+ server.removeLifecycleListener(cluster);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ return("can't stop service");
+ }
+ if (clienterror)
+ return("Client error");
+
+ if (ret != 401)
+ return("Should get 401 code");
+
+ // Wait until httpd as received the stop messages.
+ System.gc();
+ try {
+ Thread.sleep(20000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+}
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java 2008-09-11
17:39:06 UTC (rev 1814)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java 2008-09-12
12:26:32 UTC (rev 1815)
@@ -51,109 +51,8 @@
/* Test for JBWEB-117 */
public void testJBWEB_117() {
- testJBWEB_117(false, (File) null);
+ String result = ClientBasicAuthen.test(false, (File) null);
+ if (result != null)
+ fail(result);
}
- public void testJBWEB_117(boolean nat, File fd) {
- InputStream in = null;
- if (fd != null)
- try {
- in = new FileInputStream(fd);
- } catch(IOException ex) {
- ex.printStackTrace();
- fail("can't start service");
- }
- testJBWEB_117(nat, in);
- }
- public void testJBWEB_117(boolean nat, InputStream fd) {
-
- boolean clienterror = false;
- StandardServer server = Maintest.getServer();
- JBossWeb service = null;
- ClusterListener cluster = null;
- try {
- // server = (StandardServer) ServerFactory.getServer();
-
- service = new JBossWeb("node1", "localhost", nat);
- if (nat)
- service.addConnector(8009,
"org.apache.coyote.ajp.AjpAprProtocol");
- else
- service.addConnector(8009, "ajp");
-
- service.addWAR("JBWEB-117.war", "node1");
- server.addService(service);
-
- cluster = new ClusterListener();
- cluster.setAdvertiseGroupAddress("232.0.0.2");
- cluster.setAdvertisePort(23364);
- cluster.setSsl(false);
- // SSL ?
- server.addLifecycleListener((LifecycleListener) cluster);
-
- // Add AprLifecycleListener.
- if (nat) {
- AprLifecycleListener listener = new AprLifecycleListener();
- server.addLifecycleListener((LifecycleListener) listener);
- }
-
- // Debug Stuff
- 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(40000);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
-
- // Start the client and wait for it.
- Client client = new Client();
-
- // Wait for it.
- String data = "a";
- for (int i=0; i<517; i++)
- data = data.concat("a");
- int ret = 0;
- try {
- ret = client.runit("http://localhost:7779/JBWEB-117/JBWEB_117", 1,
true, data, "manager" , "manager", fd);
- client.start();
- client.join();
- } catch (Exception ex) {
- ex.printStackTrace();
- clienterror = true;
- }
-
- // Stop the jboss and remove the services.
- try {
- wait.stopit();
- wait.join();
-
- server.removeService(service);
- server.removeLifecycleListener(cluster);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- fail("can't stop service");
- }
- if (clienterror)
- fail("Client error");
-
- if (ret != 401)
- fail("Should get 401 code");
-
- // Wait until httpd as received the stop messages.
- System.gc();
- try {
- Thread.sleep(20000);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- }
}
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java 2008-09-11
17:39:06 UTC (rev 1814)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java 2008-09-12
12:26:32 UTC (rev 1815)
@@ -46,7 +46,7 @@
import org.apache.catalina.core.AprLifecycleListener;
-public class Test_Chunk_JBWEB_117 extends TestJBWEB_117 {
+public class Test_Chunk_JBWEB_117 extends TestCase {
/* Test for JBWEB-117 */
public void test_Chunk_JBWEB_117() {
@@ -54,6 +54,8 @@
for (int i=0; i<buf.length;i++)
buf[i] = 'a';
ByteArrayInputStream fd = new ByteArrayInputStream(buf);
- super.testJBWEB_117(false, fd);
+ String result = ClientBasicAuthen.test(false, fd);
+ if (result != null)
+ fail(result);
}
}