hammant     2003/01/05 02:53:21

  Added:       altrmi/src/test/org/apache/excalibur/altrmi/test/mismatch
                        SocketMismatchTestCase.java
  Log:
  Tests for mismatch on connections.
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/mismatch/SocketMismatchTestCase.java
  
  Index: SocketMismatchTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.altrmi.test.mismatch;
  
  import junit.framework.TestCase;
  import 
org.apache.excalibur.altrmi.server.impl.socket.CompleteSocketCustomStreamServer;
  import 
org.apache.excalibur.altrmi.server.impl.socket.CompleteSocketObjectStreamServer;
  import org.apache.excalibur.altrmi.server.impl.rmi.RmiServer;
  import org.apache.excalibur.altrmi.server.PublicationDescription;
  import org.apache.excalibur.altrmi.test.TestInterfaceImpl;
  import org.apache.excalibur.altrmi.test.TestInterface;
  import org.apache.excalibur.altrmi.test.TestInterface3;
  import org.apache.excalibur.altrmi.test.TestInterface2;
  import org.apache.excalibur.altrmi.client.impl.ClientClassAltrmiFactory;
  import org.apache.excalibur.altrmi.client.impl.rmi.RmiHostContext;
  import org.apache.excalibur.altrmi.client.impl.socket.SocketCustomStreamHostContext;
  import org.apache.excalibur.altrmi.client.impl.socket.SocketObjectStreamHostContext;
  import org.apache.excalibur.altrmi.common.BadConnectionException;
  
  /**
   * Test Custom Stream over sockets.
   * @author Paul Hammant
   */
  public class SocketMismatchTestCase extends TestCase
  {
  
  
      public SocketMismatchTestCase(String name)
      {
          super(name);
      }
  
      public void testCustomStreamObjectStreamMismatch() throws Exception
      {
  
          // server side setup.
          CompleteSocketCustomStreamServer server = new 
CompleteSocketCustomStreamServer(12001);
          TestInterfaceImpl testServer = new TestInterfaceImpl();
          PublicationDescription pd = new PublicationDescription(TestInterface.class,
                  new Class[]{TestInterface3.class, TestInterface2.class});
          server.publish(testServer, "Hello", pd);
          server.start();
  
          ClientClassAltrmiFactory altrmiFactory = null;
          try
          {
  
              // Client side setup
              altrmiFactory = new ClientClassAltrmiFactory(false);
              altrmiFactory.setHostContext(new 
SocketObjectStreamHostContext("127.0.0.1", 12001), false);
              TestInterface testClient = (TestInterface) altrmiFactory.lookup("Hello");
  
              // just a kludge for unit testing given we are intrinsically dealing with
              // threads, AltRMI being a client/server thing
              Thread.yield();
  
              testClient.hello("hello");
              fail("CustomStreams and ObjectStreams cannot interoperate");
          }
          catch (BadConnectionException bce)
          {
              // expected.
          }
          finally
          {
  
              System.gc();
              Thread.yield();
  
              try
              {
                  altrmiFactory.close();
              }
              catch (Exception e)
              {
              }
              Thread.yield();
              server.stop();
              Thread.yield();
          }
      }
  
      public void dont_testObjectStreamCustomStreamMismatch() throws Exception
      {
  
          // server side setup.
          CompleteSocketObjectStreamServer server = new 
CompleteSocketObjectStreamServer(12002);
          TestInterfaceImpl testServer = new TestInterfaceImpl();
          PublicationDescription pd = new PublicationDescription(TestInterface.class,
                  new Class[]{TestInterface3.class, TestInterface2.class});
          server.publish(testServer, "Hello", pd);
          server.start();
  
          ClientClassAltrmiFactory altrmiFactory = null;
          try
          {
  
              // Client side setup
              altrmiFactory = new ClientClassAltrmiFactory(false);
              altrmiFactory.setHostContext(new 
SocketCustomStreamHostContext("127.0.0.1", 12002), false);
              TestInterface testClient = (TestInterface) altrmiFactory.lookup("Hello");
  
              // just a kludge for unit testing given we are intrinsically dealing with
              // threads, AltRMI being a client/server thing
              Thread.yield();
  
              testClient.hello("hello");
              fail("CustomStreams and ObjectStreams cannot interoperate");
          }
          catch (BadConnectionException bce)
          {
              // expected.
          }
          finally
          {
  
              System.gc();
              Thread.yield();
  
              try
              {
                  altrmiFactory.close();
              }
              catch (Exception e)
              {
              }
              Thread.yield();
              server.stop();
              Thread.yield();
          }
      }
  
  
      public void dont_testCustomStreamRmiMismatch() throws Exception
      {
  
          // server side setup.
          CompleteSocketCustomStreamServer server = new 
CompleteSocketCustomStreamServer(12003);
          TestInterfaceImpl testServer = new TestInterfaceImpl();
          PublicationDescription pd = new PublicationDescription(TestInterface.class,
                  new Class[]{TestInterface3.class, TestInterface2.class});
          server.publish(testServer, "Hello", pd);
          server.start();
  
          ClientClassAltrmiFactory altrmiFactory = null;
          try
          {
  
              // Client side setup
              altrmiFactory = new ClientClassAltrmiFactory(false);
              altrmiFactory.setHostContext(new RmiHostContext("127.0.0.1", 12003), 
false);
              TestInterface testClient = (TestInterface) altrmiFactory.lookup("Hello");
  
              // just a kludge for unit testing given we are intrinsically dealing with
              // threads, AltRMI being a client/server thing
              Thread.yield();
  
              testClient.hello("hello");
              fail("CustomStreams and RMI trasnports cannot interoperate");
          }
          catch (BadConnectionException bce)
          {
              // expected.
          }
          finally
          {
  
              System.gc();
              Thread.yield();
  
              try
              {
                  altrmiFactory.close();
              }
              catch (Exception e)
              {
              }
              Thread.yield();
              server.stop();
              Thread.yield();
          }
      }
  
      public void dont_testRmiCustomStreamMismatch() throws Exception
      {
  
          // server side setup.
          RmiServer server = new RmiServer("127.0.0.1", 12004);
          TestInterfaceImpl testServer = new TestInterfaceImpl();
          PublicationDescription pd = new PublicationDescription(TestInterface.class,
                  new Class[]{TestInterface3.class, TestInterface2.class});
          server.publish(testServer, "Hello", pd);
          server.start();
  
          ClientClassAltrmiFactory altrmiFactory = null;
          try
          {
  
              // Client side setup
              altrmiFactory = new ClientClassAltrmiFactory(false);
              altrmiFactory.setHostContext(new 
SocketCustomStreamHostContext("127.0.0.1", 12004), false);
              TestInterface testClient = (TestInterface) altrmiFactory.lookup("Hello");
  
              // just a kludge for unit testing given we are intrinsically dealing with
              // threads, AltRMI being a client/server thing
              Thread.yield();
  
              testClient.hello("hello");
              fail("CustomStreams and RMI trasnports cannot interoperate");
          }
          catch (BadConnectionException bce)
          {
              // expected.
          }
          finally
          {
  
              System.gc();
              Thread.yield();
  
              try
              {
                  altrmiFactory.close();
              }
              catch (Exception e)
              {
              }
              Thread.yield();
              server.stop();
              Thread.yield();
          }
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to