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

Ovidiu Feodorov ovidiu.feodorov at jboss.com
Sun Jan 21 03:38:33 EST 2007


  User: ovidiu  
  Date: 07/01/21 03:38:33

  Added:       src/tests/org/jboss/test/remoting/lease/socket    Tag:
                        remoting_2_x ClientLeasePeriodTestCase.java
                        ClientLeasePeriodTestClient.java
                        ClientLeasePeriodTestServer.java
  Log:
  http://jira.jboss.org/jira/browse/JBREM-681
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +83 -0     JBossRemoting/src/tests/org/jboss/test/remoting/lease/socket/Attic/ClientLeasePeriodTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ClientLeasePeriodTestCase.java
  ===================================================================
  RCS file: ClientLeasePeriodTestCase.java
  diff -N ClientLeasePeriodTestCase.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ClientLeasePeriodTestCase.java	21 Jan 2007 08:38:33 -0000	1.1.2.1
  @@ -0,0 +1,83 @@
  +/**
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.test.remoting.lease.socket;
  +
  +import org.jboss.jrunit.harness.TestDriver;
  +
  +/**
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + * @version <tt>$Revision: 1.1.2.1 $</tt>
  + * $Id: ClientLeasePeriodTestCase.java,v 1.1.2.1 2007/01/21 08:38:33 ovidiu Exp $
  + */
  +public class ClientLeasePeriodTestCase extends TestDriver
  +{
  +   // Constants ------------------------------------------------------------------------------------
  +
  +   // Static ---------------------------------------------------------------------------------------
  +
  +   // Attributes -----------------------------------------------------------------------------------
  +
  +   // Constructors ---------------------------------------------------------------------------------
  +
  +   // TestDriver overrides -------------------------------------------------------------------------
  +
  +   public void declareTestClasses()
  +   {
  +      addTestClasses(ClientLeasePeriodTestClient.class.getName(), 1,
  +                     ClientLeasePeriodTestServer.class.getName());
  +   }
  +
  +   // Public ---------------------------------------------------------------------------------------
  +
  +   // Package protected ----------------------------------------------------------------------------
  +
  +   // Protected ------------------------------------------------------------------------------------
  +
  +   protected String getClientJVMArguments()
  +   {
  +      if (Boolean.getBoolean("clientdebug"))
  +      {
  +         return "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=n,suspend=n,address=jrunit_client";
  +      }
  +
  +      return "";
  +   }
  +
  +   protected long getResultsTimeout()
  +   {
  +      if (Boolean.getBoolean("clientdebug"))
  +      {
  +         return 3600000L;
  +      }
  +
  +      return super.getResultsTimeout();
  +   }
  +
  +   protected long getTearDownTimeout()
  +   {
  +      if (Boolean.getBoolean("clientdebug"))
  +      {
  +         return 3600000L;
  +      }
  +
  +      return super.getTearDownTimeout();
  +   }
  +
  +   protected long getRunTestTimeout()
  +   {
  +      if (Boolean.getBoolean("clientdebug"))
  +      {
  +         return 3600000L;
  +      }
  +
  +      return super.getRunTestTimeout();
  +   }
  +
  +   // Private --------------------------------------------------------------------------------------
  +
  +   // Inner classes --------------------------------------------------------------------------------
  +}
  
  
  
  1.1.2.1   +149 -0    JBossRemoting/src/tests/org/jboss/test/remoting/lease/socket/Attic/ClientLeasePeriodTestClient.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ClientLeasePeriodTestClient.java
  ===================================================================
  RCS file: ClientLeasePeriodTestClient.java
  diff -N ClientLeasePeriodTestClient.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ClientLeasePeriodTestClient.java	21 Jan 2007 08:38:33 -0000	1.1.2.1
  @@ -0,0 +1,149 @@
  +/**
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.test.remoting.lease.socket;
  +
  +import junit.framework.TestCase;
  +import org.jboss.remoting.Client;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.LeasePinger;
  +
  +import java.util.HashMap;
  +import java.util.Map;
  +
  +/**
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + * @version <tt>$Revision: 1.1.2.1 $</tt>
  + * $Id: ClientLeasePeriodTestClient.java,v 1.1.2.1 2007/01/21 08:38:33 ovidiu Exp $
  + */
  +public class ClientLeasePeriodTestClient extends TestCase
  +{
  +   // Constants ------------------------------------------------------------------------------------
  +
  +   // Static ---------------------------------------------------------------------------------------
  +
  +   // Attributes -----------------------------------------------------------------------------------
  +
  +   // Constructors ---------------------------------------------------------------------------------
  +
  +   // Public ---------------------------------------------------------------------------------------
  +
  +   public void testLeasePeriodNoLease() throws Throwable
  +   {
  +      Client client = new Client(new InvokerLocator(ClientLeasePeriodTestServer.locatorURINoLease));
  +
  +      assertEquals(-1, client.getLeasePeriod());
  +   }
  +
  +   public void testLeasePeriodDefaultLease() throws Throwable
  +   {
  +      Map conf = new HashMap();
  +      conf.put(Client.ENABLE_LEASE, Boolean.TRUE);
  +
  +      Client client =
  +         new Client(new InvokerLocator(ClientLeasePeriodTestServer.locatorURILease), conf);
  +
  +      client.connect();
  +
  +      assertEquals(LeasePinger.DEFAULT_LEASE_PERIOD, client.getLeasePeriod());
  +   }
  +
  +   public void testLeasePeriodCustomLease() throws Throwable
  +   {
  +      // the custom lease value should be smaller than the default lease, because the smalles
  +      // lease interval takes precedence
  +      long customLeasePeriod = LeasePinger.DEFAULT_LEASE_PERIOD - 7;
  +
  +      Map conf = new HashMap();
  +      conf.put(Client.ENABLE_LEASE, Boolean.TRUE);
  +      conf.put(InvokerLocator.CLIENT_LEASE_PERIOD, Long.toString(customLeasePeriod));
  +
  +      Client client =
  +         new Client(new InvokerLocator(ClientLeasePeriodTestServer.locatorURILease), conf);
  +
  +      client.connect();
  +
  +      assertEquals(customLeasePeriod, client.getLeasePeriod());
  +
  +   }
  +
  +   public void testLeasePeriodTwoClients() throws Throwable
  +   {
  +      // the custom lease value should be smaller than the default lease, because the smalles
  +      // lease interval takes precedence
  +      long customLeasePeriod = LeasePinger.DEFAULT_LEASE_PERIOD - 9;
  +      long customLeasePeriod2 = LeasePinger.DEFAULT_LEASE_PERIOD - 10;
  +
  +      Map conf = new HashMap();
  +      conf.put(Client.ENABLE_LEASE, Boolean.TRUE);
  +      conf.put(InvokerLocator.CLIENT_LEASE_PERIOD, Long.toString(customLeasePeriod));
  +
  +      Client client =
  +         new Client(new InvokerLocator(ClientLeasePeriodTestServer.locatorURILease), conf);
  +
  +      client.connect();
  +
  +      assertEquals(customLeasePeriod, client.getLeasePeriod());
  +
  +      conf.put(InvokerLocator.CLIENT_LEASE_PERIOD, Long.toString(customLeasePeriod2));
  +      Client client2 =
  +         new Client(new InvokerLocator(ClientLeasePeriodTestServer.locatorURILease), conf);
  +
  +      // this client will get a brand new invoker (because the configuration is different and
  +      // InvokerRegistry looks at that), so we'll have different LeasePinger instances, so will
  +      // have different lease periods
  +
  +      client2.connect();
  +
  +      assertEquals(customLeasePeriod, client.getLeasePeriod());
  +      assertEquals(customLeasePeriod2, client2.getLeasePeriod());
  +
  +   }
  +
  +   public void testLeasePeriodMultipleClientsSameInvoker() throws Throwable
  +   {
  +      Map conf = new HashMap();
  +      conf.put(Client.ENABLE_LEASE, Boolean.TRUE);
  +
  +      Client client =
  +         new Client(new InvokerLocator(ClientLeasePeriodTestServer.locatorURILease), conf);
  +
  +      client.connect();
  +
  +      assertEquals(LeasePinger.DEFAULT_LEASE_PERIOD, client.getLeasePeriod());
  +
  +      Client client2 =
  +         new Client(new InvokerLocator(ClientLeasePeriodTestServer.locatorURILease), conf);
  +
  +      client2.connect();
  +
  +      assertEquals(LeasePinger.DEFAULT_LEASE_PERIOD, client2.getLeasePeriod());
  +
  +      // test terminating lease
  +
  +      client2.getInvoker().terminateLease(client2.getSessionId(), false);
  +      assertEquals(-1, client2.getLeasePeriod());
  +      assertEquals(LeasePinger.DEFAULT_LEASE_PERIOD, client.getLeasePeriod());
  +
  +
  +      // make sure that invoking terminateLease() again on a client with no lease is a noop
  +      client2.getInvoker().terminateLease(client2.getSessionId(), false);
  +
  +
  +      client.getInvoker().terminateLease(client.getSessionId(), false);
  +      assertEquals(-1, client2.getLeasePeriod());
  +      assertEquals(-1, client.getLeasePeriod());
  +
  +   }
  +
  +   // Package protected ----------------------------------------------------------------------------
  +
  +   // Protected ------------------------------------------------------------------------------------
  +
  +   // Private --------------------------------------------------------------------------------------
  +
  +   // Inner classes --------------------------------------------------------------------------------
  +}
  
  
  
  1.1.2.1   +86 -0     JBossRemoting/src/tests/org/jboss/test/remoting/lease/socket/Attic/ClientLeasePeriodTestServer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ClientLeasePeriodTestServer.java
  ===================================================================
  RCS file: ClientLeasePeriodTestServer.java
  diff -N ClientLeasePeriodTestServer.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ClientLeasePeriodTestServer.java	21 Jan 2007 08:38:33 -0000	1.1.2.1
  @@ -0,0 +1,86 @@
  +/**
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.test.remoting.lease.socket;
  +
  +import org.jboss.jrunit.extensions.ServerTestCase;
  +import org.jboss.remoting.transport.Connector;
  +import org.jboss.remoting.ConnectionListener;
  +import org.jboss.remoting.Client;
  +
  +/**
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + * @version <tt>$Revision: 1.1.2.1 $</tt>
  + * $Id: ClientLeasePeriodTestServer.java,v 1.1.2.1 2007/01/21 08:38:33 ovidiu Exp $
  + */
  +public class ClientLeasePeriodTestServer extends ServerTestCase
  +{
  +   // Constants ------------------------------------------------------------------------------------
  +
  +   public static String locatorURINoLease = "socket://localhost:9900";
  +   public static String locatorURILease = "socket://localhost:9909";
  +
  +   // Static ---------------------------------------------------------------------------------------
  +
  +   // Attributes -----------------------------------------------------------------------------------
  +
  +   private Connector connectorNoLease;
  +   private Connector connectorLease;
  +   private ConnectionListener connectionListener;
  +
  +   // Constructors ---------------------------------------------------------------------------------
  +
  +   // Public ---------------------------------------------------------------------------------------
  +
  +   // Package protected ----------------------------------------------------------------------------
  +
  +   // Protected ------------------------------------------------------------------------------------
  +
  +   protected void setUp() throws Exception
  +   {
  +      connectorNoLease = new Connector(ClientLeasePeriodTestServer.locatorURINoLease);
  +      connectorNoLease.create();
  +      connectorNoLease.start();
  +
  +      connectorLease = new Connector(ClientLeasePeriodTestServer.locatorURILease);
  +      connectorLease.create();
  +      connectorLease.start();
  +
  +      connectionListener = new ConnectionListener()
  +      {
  +         public void handleConnectionException(Throwable throwable, Client client)
  +         {
  +         }
  +      };
  +
  +      // activate leases
  +      connectorLease.addConnectionListener(connectionListener);
  +
  +      super.setUp();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      if(connectorLease != null)
  +      {
  +         connectorLease.removeConnectionListener(connectionListener);
  +         connectorLease.stop();
  +         connectorLease.destroy();
  +      }
  +
  +      if(connectorNoLease != null)
  +      {
  +         connectorNoLease.stop();
  +         connectorNoLease.destroy();
  +      }
  +
  +      super.tearDown();
  +   }
  +
  +   // Private --------------------------------------------------------------------------------------
  +
  +   // Inner classes --------------------------------------------------------------------------------
  +}
  
  
  



More information about the jboss-cvs-commits mailing list