PageRenderTime 66ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/mod_cluster-1.2.1.Final/test/java/src/test/java/org/jboss/mod_cluster/TestPing.java

#
Java | 183 lines | 126 code | 20 blank | 37 comment | 35 complexity | 9a389374e6597082e5e7a74c172cb5cb MD5 | raw file
Possible License(s): LGPL-3.0
  1. /*
  2. * mod_cluster
  3. *
  4. * Copyright(c) 2009 Red Hat Middleware, LLC,
  5. * and individual contributors as indicated by the @authors tag.
  6. * See the copyright.txt in the distribution for a
  7. * full listing of individual contributors.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library in the file COPYING.LIB;
  21. * if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  23. *
  24. * @author Jean-Frederic Clere
  25. * @version $Revision$
  26. */
  27. package org.jboss.mod_cluster;
  28. import java.io.IOException;
  29. import java.net.ServerSocket;
  30. import junit.framework.TestCase;
  31. import org.apache.catalina.Engine;
  32. import org.apache.catalina.Service;
  33. import org.jboss.modcluster.ModClusterService;
  34. import org.apache.catalina.LifecycleException;
  35. import org.apache.catalina.connector.Connector;
  36. import org.apache.catalina.core.StandardServer;
  37. public class TestPing extends TestCase {
  38. /* Test that the sessions are really sticky */
  39. public void testPing() {
  40. boolean clienterror = false;
  41. StandardServer server = Maintest.getServer();
  42. JBossWeb service = null;
  43. JBossWeb service2 = null;
  44. ModClusterService cluster = null;
  45. System.out.println("Testping Started");
  46. try {
  47. service = new JBossWeb("node1", "localhost");
  48. service.addConnector(8011);
  49. server.addService(service);
  50. service2 = new JBossWeb("node2", "localhost");
  51. service2.addConnector(8010);
  52. server.addService(service2);
  53. cluster = Maintest.createClusterListener("224.0.1.105", 23364, false, null, true, false, true, "secret");
  54. } catch(Exception ex) {
  55. ex.printStackTrace();
  56. fail("can't start service");
  57. }
  58. // start the server thread.
  59. ServerThread wait = new ServerThread(3000, server);
  60. wait.start();
  61. // Wait until httpd as received the nodes information.
  62. int tries = Maintest.WaitForHttpd(cluster, 60);
  63. if (tries == -1) {
  64. fail("can't find PING-RSP in proxy response");
  65. }
  66. if (tries == 60) {
  67. fail("can't find proxy");
  68. }
  69. // PING the 2 nodes...
  70. String [] nodes = new String[2];
  71. nodes[0] = "node1";
  72. nodes[1] = "node2";
  73. int countinfo = 0;
  74. while (countinfo < 20) {
  75. int i;
  76. for (i=0; i< nodes.length; i++) {
  77. String result = Maintest.doProxyPing(cluster, nodes[i]);
  78. if (result == null)
  79. fail("Maintest.doProxyPing failed");
  80. if (!Maintest.checkProxyPing(result))
  81. break;
  82. }
  83. if (i == nodes.length)
  84. break;
  85. try {
  86. Thread.sleep(3000);
  87. } catch (InterruptedException ex) {
  88. ex.printStackTrace();
  89. }
  90. countinfo++;
  91. }
  92. if (countinfo == 20)
  93. fail("can't find node(s) PING-RSP in proxy response");
  94. // Try a not existing node.
  95. String result = Maintest.doProxyPing(cluster, "NONE");
  96. if (result == null)
  97. fail("Maintest.doProxyPing failed");
  98. if (Maintest.checkProxyPing(result))
  99. fail("doProxyPing on not existing node should have failed");
  100. // Get the connection back.
  101. tries = Maintest.WaitForHttpd(cluster, 20);
  102. if (tries == -1) {
  103. fail("can't find PING-RSP in proxy response");
  104. }
  105. if (tries == 20) {
  106. fail("can't find proxy");
  107. }
  108. // Ping using url
  109. result = Maintest.doProxyPing(cluster, "ajp", "localhost", 8011);
  110. if (result == null)
  111. fail("Maintest.doProxyPing failed");
  112. if (!Maintest.checkProxyPing(result))
  113. fail("doProxyPing on " + "ajp://localhost:8011" + " have failed");
  114. // Try a not existing node.
  115. result = Maintest.doProxyPing(cluster, "ajp", "localhost", 8012);
  116. if (result == null)
  117. fail("Maintest.doProxyPing failed");
  118. if (Maintest.checkProxyPing(result))
  119. fail("doProxyPing on " + "ajp://localhost:8012" + " should have failed");
  120. // Try a timeout node.
  121. try {
  122. ServerSocket sock = new ServerSocket(8012);
  123. } catch (Exception ex) {
  124. fail("can't create ServerSocket on 8012");
  125. }
  126. tries = Maintest.WaitForHttpd(cluster, 20);
  127. if (tries == -1) {
  128. fail("can't find PING-RSP in proxy response");
  129. }
  130. if (tries == 20) {
  131. fail("can't find proxy");
  132. }
  133. result = Maintest.doProxyPing(cluster, "ajp", "localhost", 8012);
  134. if (result == null)
  135. fail("Maintest.doProxyPing failed");
  136. if (Maintest.checkProxyPing(result))
  137. fail("doProxyPing on " + "ajp://localhost:8012" + " should have failed");
  138. // Stop the jboss and remove the services.
  139. try {
  140. wait.stopit();
  141. wait.join();
  142. server.removeService(service);
  143. server.removeService(service2);
  144. } catch (InterruptedException ex) {
  145. ex.printStackTrace();
  146. fail("can't stop service");
  147. }
  148. // Wait until httpd as received the stop messages.
  149. countinfo = 0;
  150. nodes = null;
  151. while ((!Maintest.checkProxyInfo(cluster, nodes)) && countinfo < 20) {
  152. try {
  153. Thread.sleep(3000);
  154. } catch (InterruptedException ex) {
  155. ex.printStackTrace();
  156. }
  157. countinfo++;
  158. }
  159. Maintest.StopClusterListener();
  160. System.gc();
  161. System.out.println("TestPing Done");
  162. }
  163. }