[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/lease/http/multiple ...

Tom Elrod tom.elrod at jboss.com
Thu Sep 21 00:43:06 EDT 2006


  User: telrod  
  Date: 06/09/21 00:43:06

  Added:       src/tests/org/jboss/test/remoting/lease/http/multiple   
                        HTTPLeaseTestCase.java HTTPLeaseTestClient.java
                        HTTPLeaseTestServer.java
  Log:
  JBREM-601 - changes to how leasing works within http invoker transport (basically so messaging will work with http transport).
  
  Revision  Changes    Path
  1.1      date: 2006/09/21 04:43:06;  author: telrod;  state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/lease/http/multiple/HTTPLeaseTestCase.java
  
  Index: HTTPLeaseTestCase.java
  ===================================================================
  /*
  * JBoss, a division of Red Hat
  * Copyright 2006, 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 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.remoting.lease.http.multiple;
  
  import org.apache.log4j.Level;
  import org.jboss.jrunit.harness.TestDriver;
  
  /**
   * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
   */
  public class HTTPLeaseTestCase extends TestDriver
  {
     public void declareTestClasses()
     {
        addTestClasses(HTTPLeaseTestClient.class.getName(),
                       1,
                       HTTPLeaseTestServer.class.getName());
     }
  
     protected Level getTestHarnessLogLevel()
     {
        return Level.DEBUG;
     }
  }
  
  
  1.1      date: 2006/09/21 04:43:06;  author: telrod;  state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/lease/http/multiple/HTTPLeaseTestClient.java
  
  Index: HTTPLeaseTestClient.java
  ===================================================================
  /*
  * JBoss, a division of Red Hat
  * Copyright 2006, 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 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.remoting.lease.http.multiple;
  
  import junit.framework.TestCase;
  import org.jboss.remoting.Client;
  import org.jboss.remoting.InvokerLocator;
  import org.jboss.remoting.callback.Callback;
  import org.jboss.remoting.callback.HandleCallbackException;
  import org.jboss.remoting.callback.InvokerCallbackHandler;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
   */
  public class HTTPLeaseTestClient extends TestCase
  {
     // Default locator values
     private static String transport = "http";
     private static String host = "localhost";
     private static int port = 5400;
  
     private String locatorURI = transport + "://" + host + ":" + port + "/?" + InvokerLocator.CLIENT_LEASE + "=" + "true";
     private String callbackLocatorURI = transport + "://" + host + ":" + (port + 1);
  
  //   public void setUp()
  //   {
  //      org.apache.log4j.BasicConfigurator.configure();
  //      org.apache.log4j.Category.getRoot().setLevel(Level.INFO);
  //      org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(XLevel.TRACE);
  //      org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.FATAL);
  //   }
  
     protected String getLocatorUri()
     {
        return locatorURI;
     }
  
     public void testMultipleLeases() throws Throwable
     {
        InvokerLocator locator = new InvokerLocator(getLocatorUri());
        System.out.println("Calling remoting server with locator uri of: " + getLocatorUri());
  
        //InvokerLocator callbackLocator = new InvokerLocator(callbackLocatorURI);
        //Connector callbackConnector = new Connector(callbackLocator);
        //callbackConnector.create();
        //callbackConnector.start();
  
        //TestCallbackHandler callbackHandler = new TestCallbackHandler();
  
        Map metadata = new HashMap();
        metadata.put("clientName", "test1");
        Client remotingClient1 = new Client(locator, metadata);
        remotingClient1.connect();
  
        //remotingClient1.addListener(callbackHandler, callbackLocator);
  
        Object ret = remotingClient1.invoke("test1");
        System.out.println("Response was: " + ret);
  
        Thread.currentThread().sleep(1000);
  
        // now create second client
        Map metadata2 = new HashMap();
        metadata2.put("clientName", "test1");
        Client remotingClient2 =new Client(locator, metadata2);
        remotingClient2.connect();
        //remotingClient2.addListener(callbackHandler, callbackLocator);
  
        ret = remotingClient2.invoke("test2");
        System.out.println("Response was: " + ret);
  
        ret = remotingClient1.invoke("test1");
        System.out.println("Response was: " + ret);
  
        Thread.currentThread().sleep(1000);
  
        if(remotingClient1 != null)
        {
           //remotingClient1.removeListener(callbackHandler);
           remotingClient1.disconnect();
        }
  
        System.out.println("remoting client 1 disconnected");
  
        //Thread.currentThread().sleep(10000);
        Thread.currentThread().sleep(30000);
  
        ret = remotingClient2.invoke("test2");
        System.out.println("Response was: " + ret);
  
        if(remotingClient2 != null)
        {
           //remotingClient2.removeListener(callbackHandler);
           remotingClient2.disconnect();
        }
  
     }
  
     public class TestCallbackHandler implements InvokerCallbackHandler
     {
  
        public void handleCallback(Callback callback) throws HandleCallbackException
        {
           System.out.println("callback: " + callback);
        }
     }
  
  
  }
  
  
  
  1.1      date: 2006/09/21 04:43:06;  author: telrod;  state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/lease/http/multiple/HTTPLeaseTestServer.java
  
  Index: HTTPLeaseTestServer.java
  ===================================================================
  package org.jboss.test.remoting.lease.http.multiple;
  
  import org.apache.log4j.Level;
  import org.jboss.logging.XLevel;
  import org.jboss.test.remoting.lease.LeaseTestServer;
  
  /**
   * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
   */
  public class HTTPLeaseTestServer extends LeaseTestServer
  {
     private static String transport = "http";
  
     protected String getTransport()
     {
        return transport;
     }
  
     public static void main(String[] args)
     {
        org.apache.log4j.BasicConfigurator.configure();
        org.apache.log4j.Category.getRoot().setLevel(Level.INFO);
        org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(XLevel.TRACE);
        org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.FATAL);
  
        final LeaseTestServer server = new HTTPLeaseTestServer();
        try
        {
           server.setupServer();
           try
           {
              new Thread(new Runnable() {
                 public void run()
                 {
                    server.testForError();
                 }
              }).start();
              Thread.currentThread().sleep(300000);
              server.isRunning = false;
           }
           catch(InterruptedException e)
           {
              e.printStackTrace();
           }
           server.tearDown();
        }
        catch(Exception e)
        {
           e.printStackTrace();
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list