Author: jfrederic.clere(a)jboss.com
Date: 2008-07-09 10:36:11 -0400 (Wed, 09 Jul 2008)
New Revision: 1742
Added:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/ServerThread.java
Modified:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestBase.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestFailover.java
Log:
Use ServerThread for both tests and arrange client.
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-07-08 07:35:38 UTC
(rev 1741)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-07-09 14:36:11 UTC
(rev 1742)
@@ -38,7 +38,7 @@
private int nbtest = 10;
private int delay = 1000;
private boolean checkcookie = true;
- private boolean success = false;
+ private boolean success = true;
/*
*
* Usage:
@@ -133,10 +133,12 @@
}
} else {
System.out.println("Not 200");
+ success = false;
}
// System.out.println("response:\n" +
pm.getResponseBodyAsString(len));
} catch(HttpException e) {
e.printStackTrace();
+ success = false;
}
System.out.println("DONE: " + httpResponseCode);
pm.releaseConnection();
@@ -149,13 +151,18 @@
for (int i = 0; i < nbtest; i++) {
try {
- if (runit() != 0) return;
+ if (runit() != 0) {
+ success = false;
+ return;
+ }
sleep((int)(Math.random() * 1000));
} catch (InterruptedException e) {
- } catch (Exception e) {}
+ success = false;
+ } catch (Exception e) {
+ success = false;
+ }
}
System.out.println("DONE!");
- success = true;
}
public boolean getresultok() {
return success;
Added: trunk/mod_cluster/test/java/org/jboss/mod_cluster/ServerThread.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/ServerThread.java
(rev 0)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/ServerThread.java 2008-07-09
14:36:11 UTC (rev 1742)
@@ -0,0 +1,67 @@
+/*
+ * 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 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 ServerThread extends Thread {
+ int delay;
+ boolean ok = true;
+ StandardServer server = null;
+
+ public ServerThread(int delay, StandardServer server) {
+ this.delay = delay;
+ this.server = server;
+ }
+ public void run() {
+ try {
+ server.start();
+ while (ok) {
+ Thread.sleep(delay);
+ }
+ // sleep(delay);
+ server.stop();
+ } catch (InterruptedException e) {
+ } catch (LifecycleException ex) {
+ ex.printStackTrace();
+ }
+ }
+ public void stopit() {
+ ok = false;
+ }
+}
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestBase.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestBase.java 2008-07-08 07:35:38
UTC (rev 1741)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestBase.java 2008-07-09 14:36:11
UTC (rev 1742)
@@ -46,6 +46,7 @@
/* Test */
public void testBase() {
+ boolean clienterror = false;
StandardServer server = Maintest.getServer();
JBossWeb service = null;
JBossWeb service2 = null;
@@ -71,14 +72,15 @@
// Debug Stuff
Maintest.listServices();
- server.start();
-
} catch(IOException ex) {
ex.printStackTrace();
- } catch (LifecycleException 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(20000);
@@ -96,23 +98,29 @@
client.join();
} catch (Exception ex) {
ex.printStackTrace();
+ clienterror = true;
}
if (client.getresultok())
System.out.println("Test DONE");
- else
+ else {
System.out.println("Test FAILED");
+ clienterror = true;
+ }
- // Stop the server or services.
+ // Stop the jboss and remove the services.
try {
- /// service.stop();
- /// service2.stop();
- server.stop();
+ wait.stopit();
+ wait.join();
+
server.removeService(service);
server.removeService(service2);
server.removeLifecycleListener(cluster);
- } catch (LifecycleException ex) {
+ } catch (InterruptedException ex) {
ex.printStackTrace();
+ fail("can't stop service");
}
+ if (clienterror)
+ fail("Client error");
// Wait until httpd as received the stop messages.
System.gc();
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestFailover.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestFailover.java 2008-07-08
07:35:38 UTC (rev 1741)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestFailover.java 2008-07-09
14:36:11 UTC (rev 1742)
@@ -73,8 +73,8 @@
fail("can't start service");
}
- // start a thread.
- ServerThread wait = new ServerThread(3000);
+ // start the server thread.
+ ServerThread wait = new ServerThread(3000, server);
wait.start();
// Wait until httpd as received the nodes information.
@@ -130,7 +130,7 @@
}
// Start a server thread.
- wait = new ServerThread(3000);
+ wait = new ServerThread(3000, server);
wait.start();
// Run a test on it. (it waits until httpd as received the nodes information).
@@ -169,27 +169,4 @@
if (clienterror)
fail("Client test failed");
}
- public class ServerThread extends Thread {
- int delay;
- boolean ok = true;
- public ServerThread(int delay) {
- this.delay = delay;
- }
- public void run() {
- try {
- server.start();
- while (ok) {
- Thread.sleep(delay);
- }
- // sleep(delay);
- server.stop();
- } catch (InterruptedException e) {
- } catch (LifecycleException ex) {
- ex.printStackTrace();
- }
- }
- public void stopit() {
- ok = false;
- }
- }
}
Show replies by date