[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/callback/timeout ...

Ron Sigal ron_sigal at yahoo.com
Mon Aug 6 00:07:12 EDT 2007


  User: rsigal  
  Date: 07/08/06 00:07:12

  Modified:    src/tests/org/jboss/test/remoting/callback/timeout  Tag:
                        remoting_2_2_0_GA
                        SocketCallbackTimeoutTestCase.java
  Log:
  JBREM-765: Added two new test methods.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +139 -1    JBossRemoting/src/tests/org/jboss/test/remoting/callback/timeout/Attic/SocketCallbackTimeoutTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SocketCallbackTimeoutTestCase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/callback/timeout/Attic/SocketCallbackTimeoutTestCase.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -b -r1.1.2.1 -r1.1.2.2
  --- SocketCallbackTimeoutTestCase.java	5 Aug 2007 17:19:00 -0000	1.1.2.1
  +++ SocketCallbackTimeoutTestCase.java	6 Aug 2007 04:07:11 -0000	1.1.2.2
  @@ -62,7 +62,7 @@
    * Unit test for JBREM-765.
    * 
    * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
  - * @version $Revision: 1.1.2.1 $
  + * @version $Revision: 1.1.2.2 $
    * <p>
    * Copyright Aug 5, 2007
    * </p>
  @@ -478,6 +478,144 @@
      }
   
   
  +   /**
  +    * Verifies that "callbackTimeout" specified in Client.addListener() metadata
  +    * map overrides values in server InvokerLocator and server configuration map.
  +    */
  +   public void testMetadataOverridesLocatorAndConfigMap() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +
  +      // Start server.
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      port = PortUtil.findFreePort(host);
  +      String locatorURI = getTransport() + "://" + host + ":" + port; 
  +      locatorURI += "/?callbackTimeout=3000";
  +      serverLocator = new InvokerLocator(locatorURI);
  +      log.info("Starting remoting server with locator uri of: " + locatorURI);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      config.put(ServerInvokerCallbackHandler.CALLBACK_TIMEOUT, "7000");
  +      addExtraServerConfig(config);
  +      connector = new Connector(serverLocator, config);
  +      connector.create();
  +      invocationHandler = new TestInvocationHandler();
  +      connector.addInvocationHandler("sample", invocationHandler);
  +      connector.start();
  +
  +      // Create client.
  +      HashMap clientConfig = new HashMap();
  +      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraClientConfig(clientConfig);
  +      final Client client = new Client(serverLocator, clientConfig);
  +      client.connect();
  +      assertEquals("abc", client.invoke("abc"));
  +      log.info("client is connected");
  +
  +      // Add callback handler.
  +      TestInvokerCallbackHandler callbackHandler = new TestInvokerCallbackHandler();
  +      Map metadata = new HashMap();
  +      metadata.put(ServerInvokerCallbackHandler.CALLBACK_TIMEOUT, "11000");
  +      client.addListener(callbackHandler, metadata, null, true);
  +      client.invoke(CALLBACK_TEST);
  +      assertEquals(1, callbackHandler.counter);
  +      log.info("callback handler is installed");
  +
  +      // Verify that "callbackTimeout" from Client.addListener() metadata
  +      // has precedence.
  +      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
  +      Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
  +      field.setAccessible(true);
  +      Map callbackHandlers = (Map) field.get(serverInvoker);
  +      assertEquals(1, callbackHandlers.size());
  +      ServerInvokerCallbackHandler serverInvokerCallbackHandler;
  +      serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().iterator().next();
  +      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
  +      assertTrue(callbackClient.getInvoker() instanceof MicroSocketClientInvoker);
  +      MicroSocketClientInvoker callbackClientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
  +      field = MicroSocketClientInvoker.class.getDeclaredField("pool");
  +      field.setAccessible(true);
  +      LinkedList pool = (LinkedList) field.get(callbackClientInvoker);
  +      assertEquals(1, pool.size());
  +      Object o = pool.iterator().next();
  +      assertTrue(o instanceof ClientSocketWrapper);
  +      ClientSocketWrapper clientWrapper = (ClientSocketWrapper) o;
  +      assertEquals(11000, clientWrapper.getTimeout());
  +
  +      client.removeListener(callbackHandler);
  +      client.disconnect();
  +      connector.stop();
  +   }
  +   
  +   
  +   /**
  +    * Verifies that "callbackTimeout" specified in server InvokerLocator
  +    * overrides value specified in server configuration map.
  +    */
  +   public void testLocatorOverridesConfigMap() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +
  +      // Start server.
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      port = PortUtil.findFreePort(host);
  +      String locatorURI = getTransport() + "://" + host + ":" + port; 
  +      locatorURI += "/?callbackTimeout=3000";
  +      serverLocator = new InvokerLocator(locatorURI);
  +      log.info("Starting remoting server with locator uri of: " + locatorURI);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      config.put(ServerInvokerCallbackHandler.CALLBACK_TIMEOUT, "7000");
  +      addExtraServerConfig(config);
  +      connector = new Connector(serverLocator, config);
  +      connector.create();
  +      invocationHandler = new TestInvocationHandler();
  +      connector.addInvocationHandler("sample", invocationHandler);
  +      connector.start();
  +
  +      // Create client.
  +      HashMap clientConfig = new HashMap();
  +      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraClientConfig(clientConfig);
  +      final Client client = new Client(serverLocator, clientConfig);
  +      client.connect();
  +      assertEquals("abc", client.invoke("abc"));
  +      log.info("client is connected");
  +
  +      // Add callback handler.
  +      TestInvokerCallbackHandler callbackHandler = new TestInvokerCallbackHandler();
  +      client.addListener(callbackHandler, new HashMap(), null, true);
  +      client.invoke(CALLBACK_TEST);
  +      assertEquals(1, callbackHandler.counter);
  +      log.info("callback handler is installed");
  +
  +      // Verify that "callbackTimeout" from InvokerLocator overrides value
  +      // in configuration map.
  +      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
  +      Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
  +      field.setAccessible(true);
  +      Map callbackHandlers = (Map) field.get(serverInvoker);
  +      assertEquals(1, callbackHandlers.size());
  +      ServerInvokerCallbackHandler serverInvokerCallbackHandler;
  +      serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().iterator().next();
  +      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
  +      assertTrue(callbackClient.getInvoker() instanceof MicroSocketClientInvoker);
  +      MicroSocketClientInvoker callbackClientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
  +      field = MicroSocketClientInvoker.class.getDeclaredField("pool");
  +      field.setAccessible(true);
  +      LinkedList pool = (LinkedList) field.get(callbackClientInvoker);
  +      assertEquals(1, pool.size());
  +      Object o = pool.iterator().next();
  +      assertTrue(o instanceof ClientSocketWrapper);
  +      ClientSocketWrapper clientWrapper = (ClientSocketWrapper) o;
  +      assertEquals(3000, clientWrapper.getTimeout());
  +
  +      client.removeListener(callbackHandler);
  +      client.disconnect();
  +      connector.stop();
  +   }
  +   
  +   
      protected String getTransport()
      {
         return "socket";
  
  
  



More information about the jboss-cvs-commits mailing list