[jboss-cvs] JBossAS SVN: r64214 - in trunk/testsuite/src/main/org/jboss/test/cluster: testutil and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 23 22:37:01 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-07-23 22:37:00 -0400 (Mon, 23 Jul 2007)
New Revision: 64214

Added:
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/DBSetup.java
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockHAPartition.java
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/PromiscuousTrafficTester.java
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/WebTestBase.java
Log:
[JBAS-4552] Move cluster tests into cluster package
[JBAS-4553] Reorg cluster tests to prevent unnecessary repetition

Copied: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/DBSetup.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/DBSetup.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/DBSetup.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/DBSetup.java	2007-07-24 02:37:00 UTC (rev 64214)
@@ -0,0 +1,148 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This 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.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software 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 software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.cluster.testutil;
+
+import java.sql.DriverManager;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.io.File;
+import java.io.IOException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+/** A TestSetup that starts hypersonic before the testcase with a tcp
+ * listening port at 1701.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revison:$
+ */
+public class DBSetup extends TestSetup
+{
+   public DBSetup(Test test)
+   {
+      super(test);
+   }
+
+   protected void setUp() throws Exception
+   {
+         File hypersoniDir = new File("output/hypersonic");
+         if (!hypersoniDir.exists())
+         {
+            hypersoniDir.mkdirs();
+         }
+
+         if (!hypersoniDir.isDirectory())
+         {
+            throw new IOException("Failed to create directory: " + hypersoniDir);
+         }
+      
+         File dbPath = new File(hypersoniDir, "cif-db");
+
+         // Start DB in new thread, or else it will block us
+         DBThread serverThread = new DBThread(dbPath);
+         serverThread.start();
+         
+         int elapsed = 0;
+         while (!serverThread.isStarted() && elapsed < 15000)
+         {
+            try 
+            {
+               Thread.sleep(100);
+               elapsed += 100;
+            }
+            catch (InterruptedException ie)
+            {
+               System.out.println("Interrupted while waiting for Hypersonic");
+            }
+         }
+         
+         if (!serverThread.isStarted())
+            System.out.println("Hypersonic failed to start in a timely fashion");
+   }
+
+   protected void tearDown() throws Exception
+   {
+      Class.forName("org.hsqldb.jdbcDriver");
+      String dbURL = "jdbc:hsqldb:hsql://localhost:1701";
+      Connection conn = DriverManager.getConnection(dbURL, "sa", "");
+      Statement statement = conn.createStatement();      
+      statement.executeQuery("SHUTDOWN COMPACT");
+      
+   }
+
+   public static void main(String[] args) throws Exception
+   {
+      DBSetup setup = new DBSetup(null);
+      setup.setUp();
+      Thread.sleep(120*1000);
+      setup.tearDown();
+   }
+   
+   class DBThread extends Thread
+   {
+      boolean started;
+      File dbPath;
+      
+      DBThread(File dbPath)
+      {
+         super("hypersonic");
+         this.dbPath = dbPath;
+      }
+      
+      boolean isStarted()
+      {
+         return started;
+      }
+      
+      public void run()
+      {
+         try
+         {
+            // Create startup arguments
+            String[] args = {
+                  "-database",
+                  dbPath.toString(),
+                  "-port",
+                  String.valueOf(1701),
+                  "-silent",
+                  "false",
+                  "-trace",
+                  "false",
+                  "-no_system_exit",
+                  "true",
+             };
+            System.out.println("Starting hsqldb");
+            org.hsqldb.Server.main(args);
+            System.out.println("Done");
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace();
+         }
+         finally
+         {
+            started = true;
+         }
+      }
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockHAPartition.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockHAPartition.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockHAPartition.java	2007-07-24 02:37:00 UTC (rev 64214)
@@ -0,0 +1,231 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This 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.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.cluster.testutil;
+
+import java.util.ArrayList;
+import java.util.Vector;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
+import org.jboss.ha.framework.interfaces.DistributedState;
+import org.jboss.ha.framework.interfaces.HAPartition;
+
+/**
+ * Mock implementation of HAPartition intended to support unit testing
+ * of DistributedReplicantManagerImpl without the need for an underlying
+ * JChannel.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Id$
+ */
+public class MockHAPartition implements HAPartition
+{   
+   public static final String PARTITION_NAME = "MockPartition";
+   
+   private DistributedReplicantManager drm;
+   private Vector currentNodes;
+   private ClusterNode localAddress;
+   private ArrayList remoteReplicants;
+   
+   public MockHAPartition(ClusterNode localAddress)
+   {
+      this.localAddress = localAddress;
+   }
+   
+   public MockHAPartition()
+   {
+      
+   }
+   
+   // ------------------------------------------------------------  HAPartition
+   
+   public String getNodeName()
+   {
+      return localAddress.getName();
+   }
+
+   public String getPartitionName()
+   {
+      return PARTITION_NAME;
+   }
+
+   public DistributedReplicantManager getDistributedReplicantManager()
+   {
+      return drm;
+   }
+
+   public DistributedState getDistributedStateService()
+   {
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void registerRPCHandler(String serviceName, Object handler)
+   {
+      if (handler instanceof DistributedReplicantManager)
+         drm = (DistributedReplicantManager) handler;
+      else
+         throw new UnsupportedOperationException("not implemented");
+   }
+   
+   public void registerRPCHandler(String serviceName, Object handler, ClassLoader classloader)
+   {
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void unregisterRPCHandler(String serviceName, Object subscriber)
+   {
+      if (subscriber == drm)
+         drm = null;
+      else    
+         throw new UnsupportedOperationException("not implemented");
+   }
+
+   public ArrayList callMethodOnCluster(String serviceName, String methodName, Object[] args, Class[] types,
+         boolean excludeSelf) throws Exception
+   {
+      if (excludeSelf)
+      {
+         if ("_add".equals(methodName)) 
+         {
+            // no-op -- there is no cluster
+            return null;
+         }
+         else if ("lookupLocalReplicants".equals(methodName) && args.length == 0)
+         {
+            return remoteReplicants;
+         }
+      }
+      // TODO Implement lookupLocalReplicants for DRM SERVICE_NAME
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public ArrayList callMethodOnCluster(String serviceName, String methodName, Object[] args, boolean excludeSelf)
+         throws Exception
+   {
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void callAsynchMethodOnCluster(String serviceName, String methodName, Object[] args, Class[] types,
+         boolean excludeSelf) throws Exception
+   {
+      if (excludeSelf && "_remove".equals(methodName))
+      {
+         // no-op -- there is no cluster
+         return;
+      }
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void callAsynchMethodOnCluster(String serviceName, String methodName, Object[] args, boolean excludeSelf)
+         throws Exception
+   {
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public ArrayList callMethodOnCoordinatorNode(String serviceName, String methodName, Object[] args, Class[] types,
+         boolean excludeSelf) throws Exception
+   {
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void subscribeToStateTransferEvents(String serviceName, HAPartitionStateTransfer subscriber)
+   {
+      // no-op. at this point the test fixture directly passes state
+      // to the target DRM
+   }
+
+   public void unsubscribeFromStateTransferEvents(String serviceName, HAPartitionStateTransfer subscriber)
+   {
+      // no-op. at this point the test fixture directly passes state
+      // to the target DRM
+   }
+
+   public void registerMembershipListener(HAMembershipListener listener)
+   {
+      // no-op. at this point the test fixture directly passes membership
+      // changes to the target DRM
+   }
+
+   public void unregisterMembershipListener(HAMembershipListener listener)
+   {
+      // no-op. at this point the test fixture directly passes membership
+      // changes to the target DRM
+   }
+   
+   public boolean getAllowSynchronousMembershipNotifications()
+   {
+      return false;
+   }
+   
+   public void setAllowSynchronousMembershipNotifications(boolean allowSync)
+   {
+      // no-op      
+   }
+
+   public long getCurrentViewId()
+   {
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public Vector getCurrentView()
+   {
+      Vector result = new Vector();
+      for (int i = 0; i < currentNodes.size(); i++)
+         result.add(((ClusterNode) currentNodes.elementAt(i)).getName());
+         
+      return result;
+   }
+
+   public ClusterNode[] getClusterNodes()
+   {
+      ClusterNode[] result = new ClusterNode[currentNodes.size()];
+      return (ClusterNode[]) currentNodes.toArray(result);
+   }
+
+   public ClusterNode getClusterNode()
+   {
+      return localAddress;
+   }
+   
+   // ---------------------------------------------------------  Public Methods
+   
+   public void setCurrentViewClusterNodes(Vector nodes)
+   {
+      this.currentNodes = nodes;
+   }
+   
+   public void setRemoteReplicants(ArrayList remoteReplicants)
+   {
+      this.remoteReplicants = remoteReplicants;
+   }
+   
+   public void setLocalAddress(ClusterNode localAddress)
+   {
+      this.localAddress = localAddress;
+   }
+
+}


Property changes on: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockHAPartition.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Copied: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/PromiscuousTrafficTester.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/PromiscuousTrafficTester.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/PromiscuousTrafficTester.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/PromiscuousTrafficTester.java	2007-07-24 02:37:00 UTC (rev 64214)
@@ -0,0 +1,280 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.cluster.testutil;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.UnknownHostException;
+
+/**
+ * Tests for the existence of the problem described at
+ * http://wiki.jboss.org/wiki/Wiki.jsp?page=PromiscuousTraffic
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class PromiscuousTrafficTester
+{
+   private InetAddress goodMulticast;
+   private InetAddress badMulticast;
+   private InetAddress senderAddress;
+   private InetAddress receiverAddress;
+   private int mcastPort = 64000;
+   private int ttl = 0;
+   
+   private MulticastSocket sender;
+   private MulticastReceiver goodReceiver;
+   private MulticastReceiver badReceiver;
+   
+   private PromiscuousTrafficTester(String[] args) throws Exception
+   {
+      // Set defaults
+      goodMulticast = InetAddress.getByName("229.10.11.12");
+      badMulticast = InetAddress.getByName("229.10.11.13");
+      senderAddress = InetAddress.getLocalHost();
+      receiverAddress = InetAddress.getLocalHost();
+      
+      // Check what was passed in
+      parseArgs(args);
+      
+      try
+      {
+         setUpSockets();
+      }
+      catch (Exception e)
+      {
+         closeSockets();
+         throw e;
+      }
+   }
+   
+   private void test() throws Exception
+   {
+      try
+      {
+         byte[] data = "Hello".getBytes();
+         DatagramPacket datagram = new DatagramPacket(data, 0, data.length, goodMulticast, mcastPort);
+         
+         System.out.println("Sending 'Hello' on " + goodMulticast + ":" + mcastPort);
+         sender.send(datagram);
+         
+         Thread.sleep(1000);
+         
+         if ("Hello".equals(goodReceiver.getValue()) == false)
+            throw new IllegalStateException("Did not receive 'Hello' as expected; got " + goodReceiver.getValue());
+         
+         if (badReceiver.getValue() != null)
+         {
+            System.out.println("Bad news. Detected the Promiscuous Traffic " +
+                    "problem. Received " + badReceiver.getValue() + 
+                    " on undesired address " + badMulticast); 
+         }
+         else
+         {
+            System.out.println("Good news. Did not detect the Promiscuous Traffic problem.");
+         }
+      }
+      finally
+      {
+         closeSockets();
+      }
+   }
+   
+   private void parseArgs(String[] args) throws UnknownHostException
+   {
+      if (args == null || args.length == 0)
+         return;
+      
+      senderAddress = InetAddress.getByName(args[0]);      
+      
+      if (args.length > 1)
+         receiverAddress = InetAddress.getByName(args[1]);
+      else
+         receiverAddress = senderAddress;
+      
+      if (args.length > 2)
+         goodMulticast = InetAddress.getByName(args[2]);
+      
+      if (args.length > 3)
+         badMulticast = InetAddress.getByName(args[3]);
+      
+      if (args.length > 4)
+         mcastPort = Integer.parseInt(args[4]);
+      
+      if (args.length > 5)
+         ttl = Integer.parseInt(args[5]);
+   }
+   
+   private void setUpSockets() throws IOException
+   {
+      sender = new MulticastSocket();
+      sender.setInterface(senderAddress);
+      sender.setTimeToLive(ttl);
+      
+      goodReceiver = new MulticastReceiver(goodMulticast);
+      goodReceiver.startListener();
+      
+      badReceiver = new MulticastReceiver(badMulticast);
+      badReceiver.startListener();
+      
+      // Sleep a bit to let the listeners start
+      try
+      {
+         Thread.sleep(250);
+      }
+      catch (InterruptedException e)
+      {
+         e.printStackTrace();
+      }
+   }
+   
+   private void closeSockets()
+   {
+      if (goodReceiver != null)
+         goodReceiver.stopListener();
+      
+      if (badReceiver != null)
+         badReceiver.stopListener();
+      
+      if (sender != null)
+         sender.close();
+   }
+   
+   /**
+    * Create and run the PromiscuousTrafficTester.
+    * 
+    * @param args 0 or more of the following; not all need be present, but none
+    *             can be skipped if subsequent values are desired:
+    *             [0] Interface sender should bind to (machine name)
+    *             [1] Interface receivers should bind to (same as sender interface)
+    *             [2] Multicast address on which packets will be sent (229.10.11.12)
+    *             [3] Multicast address on which receipt of packet means (229.10.11.13)
+    *                 promiscuous traffic problem is present
+    *             [4] Multicast port (64000)
+    *             [5] TTL of multicast packet (0)
+    */
+   public static void main(String[] args)
+   {
+      try
+      {
+         PromiscuousTrafficTester tester = new PromiscuousTrafficTester(args);
+         tester.test();
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+   }
+   
+   private class MulticastReceiver implements Runnable
+   {
+      private InetAddress group;
+      private MulticastSocket socket;
+      private String value;
+      private Exception exception;
+      private Thread thread;
+      private boolean stopping;
+      
+      MulticastReceiver(InetAddress mcastAddr) throws IOException
+      {
+         group = mcastAddr;
+         socket = new MulticastSocket(mcastPort);
+         socket.setInterface(receiverAddress);
+         socket.joinGroup(mcastAddr);
+      }
+
+      
+      public void run()
+      {
+         try
+         {
+            System.out.println("Listening on address " + group);
+            
+            byte[] buf = new byte[256];
+            DatagramPacket packet = new DatagramPacket(buf, buf.length);
+            socket.receive(packet);
+            
+            value = new String(packet.getData()).trim();
+            
+            System.out.println(group + ":" + mcastPort + " -- Received " + value);
+         }
+         catch (Exception e)
+         {
+            if (!stopping)
+            {
+               this.exception = e;
+               e.printStackTrace(System.out);
+            }
+         }
+      }
+
+
+      public Exception getException()
+      {
+         return exception;
+      }
+
+      public String getValue()
+      {
+         return value;
+      }
+      
+      public void startListener()
+      {
+         thread = new Thread(this);
+         thread.start();
+      }
+      
+      public void stopListener()
+      {
+         stopping = true;
+         
+         if (thread.isAlive())
+         {
+            try
+            {
+               thread.join(50);
+            }
+            catch (InterruptedException e)
+            {               
+            }
+         
+            if (thread.isAlive())
+               thread.interrupt();
+         }
+         
+         try
+         {
+            socket.leaveGroup(group);
+         }
+         catch (IOException e)
+         {
+         }
+         
+         socket.close();
+      }
+      
+   }
+}

Copied: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/SessionTestUtil.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java	2007-07-24 02:37:00 UTC (rev 64214)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This 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.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.test.cluster.testutil;
+
+import java.util.Set;
+
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.test.cluster.web.CacheHelper;
+
+/**
+ * Utilities for session testing.
+ * 
+ * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class SessionTestUtil
+{  
+   private static final String[] TYPES = { String.class.getName() };
+   
+   public static Object getSessionVersion(RMIAdaptor adaptor, String sessionFqn) throws Exception
+   {
+      return adaptor.invoke(CacheHelper.OBJECT_NAME, 
+                            "getSessionVersion", 
+                            new Object[] { sessionFqn }, 
+                            TYPES);
+   }
+
+   public static Object getBuddySessionVersion(RMIAdaptor adaptor, String sessionFqn) throws Exception
+   {
+
+      return adaptor.invoke(CacheHelper.OBJECT_NAME, 
+                            "getBuddySessionVersion", 
+                            new Object[] { sessionFqn }, 
+                            TYPES);
+   }
+   
+   public static Set getSessionIds(RMIAdaptor adaptor, String warFqn) throws Exception
+   {
+      return (Set) adaptor.invoke(CacheHelper.OBJECT_NAME, 
+                           "getSessionIds", 
+                           new Object[] { warFqn }, 
+                           TYPES);
+   }
+   
+   public static void leaveHelperOnServer(RMIAdaptor adaptor) throws Exception
+   {
+      adaptor.invoke(CacheHelper.OBJECT_NAME, 
+            "setLeaveInstalledAfterShutdown", 
+            new Object[0], new String[0]);
+   }
+   
+   public static void uninstallHelper(RMIAdaptor adaptor) throws Exception
+   {
+      adaptor.invoke(CacheHelper.OBJECT_NAME, 
+            "uninstall", 
+            new Object[0], new String[0]);
+   }
+
+   private SessionTestUtil() {}
+}

Added: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/WebTestBase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/WebTestBase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/WebTestBase.java	2007-07-24 02:37:00 UTC (rev 64214)
@@ -0,0 +1,263 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This 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.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software 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 software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.cluster.testutil;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import org.apache.commons.httpclient.Cookie;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * Base class to test HttpSessionReplication.
+ *
+ * @author Ben Wang
+ * @version $Revision: 1.0
+ */
+public abstract class WebTestBase
+      extends JBossClusteredTestCase
+{
+   /** 
+    * Standard number of ms to pause between http requests
+    * to give session time to replicate
+    */
+   public static final long DEFAULT_SLEEP = 300;
+   
+   protected String[] servers_ = null;
+   protected String baseURL0_;
+   protected String baseURL1_;
+
+   public WebTestBase(String name)
+   {
+      super(name);
+   }
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      servers_ = super.getServers();
+      assertEquals("Server size " , servers_.length, 2);
+
+      String[] httpURLs  = super.getHttpURLs();
+      assertEquals("Url size " , httpURLs.length, 2);
+      baseURL0_ = httpURLs[0];
+      baseURL1_ = baseURL0_;
+      if( servers_.length > 1 )
+      {
+        baseURL1_ = httpURLs[1];
+      }
+   }
+
+   /**
+    * Sleep for specified time
+    *
+    * @param msecs
+    */
+   protected void sleepThread(long msecs)
+   {
+      try {
+         Thread.sleep(msecs);
+      } catch (InterruptedException e) {
+         e.printStackTrace();
+      }
+   }
+
+
+   /**
+    * Makes a http call to the jsp that retrieves the attribute stored on the
+    * session. When the attribute values mathes with the one retrieved earlier,
+    * we have HttpSessionReplication.
+    * Makes use of commons-httpclient library of Apache
+    *
+    * @param client
+    * @param url
+    * @return session attribute
+    */
+   protected String makeGet(HttpClient client, String url)
+      throws IOException
+   {
+      getLog().debug("makeGet(): trying to get from url " +url);
+
+      GetMethod method = new GetMethod(url);
+      int responseCode = 0;
+      try
+      {
+         responseCode = client.executeMethod(method);
+      } catch (IOException e)
+      {
+         e.printStackTrace();
+         fail("HttpClient executeMethod fails." +e.toString());
+      }
+      assertTrue("Get OK with url: " +url + " responseCode: " +responseCode
+        , responseCode == HttpURLConnection.HTTP_OK);
+
+      // Read the response body.
+      byte[] responseBody = method.getResponseBody();
+
+      // Release the connection.
+//      method.releaseConnection();
+
+      // Deal with the response.
+      // Use caution: ensure correct character encoding and is not binary data
+      return new String(responseBody);
+   }
+
+   /**
+    * Makes a http call to the jsp that retrieves the attribute stored on the
+    * session. When the attribute values mathes with the one retrieved earlier,
+    * we have HttpSessionReplication.
+    * Makes use of commons-httpclient library of Apache
+    *
+    * @param client
+    * @param url
+    * @return session attribute
+    */
+   protected String makeGetFailed(HttpClient client, String url)
+      throws IOException
+   {
+      getLog().debug("makeGetFailed(): trying to get from url " +url);
+
+      GetMethod method = new GetMethod(url);
+      int responseCode = 0;
+      try
+      {
+         responseCode = client.executeMethod(method);
+      } catch (IOException e)
+      {
+         e.printStackTrace();
+      }
+      assertTrue("Should not be OK code with url: " +url + " responseCode: " +responseCode
+        , responseCode != HttpURLConnection.HTTP_OK);
+
+      // Read the response body.
+      byte[] responseBody = method.getResponseBody();
+
+      // Release the connection.
+//      method.releaseConnection();
+
+      // Deal with the response.
+      // Use caution: ensure correct character encoding and is not binary data
+      return new String(responseBody);
+   }
+
+
+   /**
+    * Makes a http call to the jsp that retrieves the attribute stored on the
+    * session. When the attribute values mathes with the one retrieved earlier,
+    * we have HttpSessionReplication.
+    * Makes use of commons-httpclient library of Apache
+    *
+    * @param client
+    * @param url
+    * @return session attribute
+    */
+   protected String makeGetWithState(HttpClient client, String url)
+      throws IOException
+   {
+      getLog().debug("makeGetWithState(): trying to get from url " +url);
+      GetMethod method = new GetMethod(url);
+      int responseCode = 0;
+      try
+      {
+         HttpState state = client.getState();
+         responseCode = client.executeMethod(method.getHostConfiguration(),
+            method, state);
+      } catch (IOException e)
+      {
+         e.printStackTrace();
+         fail("HttpClient executeMethod fails." +e.toString());
+      }
+      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
+
+      // Read the response body.
+      byte[] responseBody = method.getResponseBody();
+      /* Validate that the attribute was actually seen. An absence of the
+         header is treated as true since there are pages used that done't
+         add it.
+      */
+      Header hdr = method.getResponseHeader("X-SawTestHttpAttribute");
+      Boolean sawAttr = hdr != null ? Boolean.valueOf(hdr.getValue()) : Boolean.TRUE;
+      String attr = null;
+      if( sawAttr.booleanValue() )
+         attr = new String(responseBody);
+      // Release the connection.
+//      method.releaseConnection();
+
+      // Deal with the response.
+      // Use caution: ensure correct character encoding and is not binary data
+      return attr;
+   }
+
+   protected void setCookieDomainToThisServer(HttpClient client, String server)
+   {
+      // Get the session cookie
+      Cookie sessionID = getSessionCookie(client, server);
+      // Reset the domain so that the cookie will be sent to server1
+      sessionID.setDomain(server);
+      client.getState().addCookie(sessionID);
+   }
+   
+   protected String getSessionID(HttpClient client, String server)
+   {
+      Cookie sessionID = getSessionCookie(client, server);
+      return sessionID.getValue();
+   }
+   
+   protected Cookie getSessionCookie(HttpClient client, String server)
+   {
+      // Get the state for the JSESSIONID
+      HttpState state = client.getState();
+      // Get the JSESSIONID so we can reset the host
+      Cookie[] cookies = state.getCookies();
+      Cookie sessionID = null;
+      for(int c = 0; c < cookies.length; c ++)
+      {
+         Cookie k = cookies[c];
+         if( k.getName().equalsIgnoreCase("JSESSIONID") )
+            sessionID = k;
+      }
+      if(sessionID == null)
+      {
+         fail("setCookieDomainToThisServer(): fail to find session id. Server name: " +server);
+      }
+      log.info("Saw JSESSIONID="+sessionID);
+      return sessionID;
+   }
+   
+   protected String stripJvmRoute(String id)
+   {
+      int index = id.indexOf(".");
+      if (index > 0)
+      {
+         return id.substring(0, index);
+      }
+      else
+      {
+         return id;
+      }
+   }
+}


Property changes on: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/WebTestBase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list