avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/piped PipedTestCase.java PipedTest.java PipedTestClient.java
Date Sun, 14 Jul 2002 20:59:47 GMT
hammant     2002/07/14 13:59:47

  Modified:    altrmi/src/test/org/apache/excalibur/altrmi/test/piped
                        PipedTest.java PipedTestClient.java
  Added:       altrmi/src/test/org/apache/excalibur/altrmi/test/piped
                        PipedTestCase.java
  Log:
  Unit test, incomplete...
  
  Revision  Changes    Path
  1.3       +46 -31    jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/piped/PipedTest.java
  
  Index: PipedTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/piped/PipedTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PipedTest.java	24 Apr 2002 12:43:04 -0000	1.2
  +++ PipedTest.java	14 Jul 2002 20:59:47 -0000	1.3
  @@ -8,8 +8,9 @@
   package org.apache.excalibur.altrmi.test.piped;
   
   import java.io.File;
  -import org.apache.excalibur.altrmi.server.ClassRetriever;
  -import org.apache.excalibur.altrmi.server.PublicationDescription;
  +import java.net.MalformedURLException;
  +
  +import org.apache.excalibur.altrmi.server.*;
   import org.apache.excalibur.altrmi.server.impl.classretrievers.DynamicGeneratorClassRetriever;
   import org.apache.excalibur.altrmi.server.impl.classretrievers.JarFileClassRetriever;
   import org.apache.excalibur.altrmi.server.impl.classretrievers.NoClassRetriever;
  @@ -30,36 +31,15 @@
   public class PipedTest
   {
   
  -    private static String serverOrClientFactory;
  -
  -    /**
  -     * Method main
  -     *
  -     *
  -     * @param args
  -     *
  -     * @throws Exception
  -     *
  -     */
  -    public static void main( String[] args ) throws Exception
  -    {
  -
  -        System.out.println( "Piped Test" );
  -
  -        serverOrClientFactory = args[ 0 ];
   
  -        AbstractPipedServer ps = new PipedObjectStreamServer();
  -        TestInterfaceImpl ti = new TestInterfaceImpl();
  -        ClassRetriever cr = new NoClassRetriever();
  +    public PipedTest() {
  +    }
   
  -        PublicationDescription pd = new PublicationDescription( TestInterface.class,
  -                                                                new Class[]{
  -                                                                    TestInterface3.class,
  -                                                                    TestInterface2.class}
);
   
  +    protected ClassRetriever getClassRetriever(String serverOrClientFactory, PublicationDescription
pd) throws MalformedURLException, PublicationException {
           if( serverOrClientFactory.equals( "S" ) )
           {
  -            cr = new JarFileClassRetriever( "build" + File.separator + "classes2" );
  +            return new JarFileClassRetriever( "build" + File.separator + "classes2" );
           }
           else if( serverOrClientFactory.equals( "D" ) )
           {
  @@ -79,17 +59,52 @@
   
               dr.generate( "Hello", pd, null );
   
  -            cr = dr;
  +            return dr;
           }
  +        return new NoClassRetriever();
  +    }
   
  -        ps.setClassRetriever( cr );
  -        ps.publish( ti, "Hello", pd );
  +    protected void test(ClassRetriever classRetriever, PublicationDescription publicationDescription,
String serverOrClientFactory) throws PublicationException {
  +        System.out.println( "Piped Test" );
  +
  +        AbstractPipedServer ps = new PipedObjectStreamServer();
  +        TestInterfaceImpl ti = new TestInterfaceImpl();
  +
  +        ps.setClassRetriever( classRetriever );
  +        ps.publish( ti, "Hello", publicationDescription );
           ps.start();
   
           PipedTestClient ptc = new PipedTestClient( ps, serverOrClientFactory );
           Thread thread = new Thread( ptc );
   
           thread.start();
  +    }
  +
  +    /**
  +     * Method main
  +     *
  +     *
  +     * @param args
  +     *
  +     * @throws Exception
  +     *
  +     */
  +    public static void main( String[] args ) throws Exception
  +    {
  +
  +        String serverOrClientFactory = args[ 0 ];
  +
  +        PipedTest pt = new PipedTest();
  +
  +        PublicationDescription publicationDescription = new PublicationDescription( TestInterface.class,
  +                                                                new Class[]{
  +                                                                    TestInterface3.class,
  +                                                                    TestInterface2.class}
);
  +
  +        ClassRetriever classRetriever = pt.getClassRetriever(serverOrClientFactory, publicationDescription);
  +
  +        pt.test(classRetriever, publicationDescription, serverOrClientFactory);
  +
       }
   
   }
  
  
  
  1.3       +26 -15    jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/piped/PipedTestClient.java
  
  Index: PipedTestClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/piped/PipedTestClient.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PipedTestClient.java	24 Apr 2002 12:43:04 -0000	1.2
  +++ PipedTestClient.java	14 Jul 2002 20:59:47 -0000	1.3
  @@ -31,8 +31,10 @@
   public class PipedTestClient implements Runnable
   {
   
  -    private AbstractPipedServer mPipedServer;
  -    private String mServerOrClientFactory;
  +    protected AbstractPipedServer mPipedServer;
  +    protected String mServerOrClientFactory;
  +    protected PipedInputStream in = new PipedInputStream();
  +    protected PipedOutputStream out = new PipedOutputStream();
   
       /**
        * Constructor PipedTestClient
  @@ -57,27 +59,19 @@
   
           try
           {
  -            PipedInputStream in = new PipedInputStream();
  -            PipedOutputStream out = new PipedOutputStream();
  +
               AltrmiHostContext arhc = new PipedObjectStreamHostContext( in, out );
   
               mPipedServer.makeNewConnection( in, out );
   
               AltrmiFactory af = null;
   
  -            if( mServerOrClientFactory.equals( "S" ) | mServerOrClientFactory.equals( "D"
) )
  -            {
  -                af = new ServerClassAltrmiFactory( false );
  -            }
  -            else
  -            {
  -                af = new ClientClassAltrmiFactory( false );
  -            }
  +            af = makeFactory();
   
               af.setHostContext( arhc );
   
  -            TestInterface ti = (TestInterface)af.lookup( "Hello" );
  -            TestClient tc = new TestClient( ti );
  +            TestInterface ti = (TestInterface) af.lookup( "Hello" );
  +            test(ti);
   
               af.close();
           }
  @@ -91,5 +85,22 @@
               System.err.println( "Some problem during connection to server : "
                                   + ace.getMessage() );
           }
  +    }
  +
  +    protected void test(TestInterface ti) {
  +        new TestClient( ti );
  +    }
  +
  +    protected AltrmiFactory makeFactory() {
  +        AltrmiFactory af;
  +        if( mServerOrClientFactory.equals( "S" ) | mServerOrClientFactory.equals( "D" )
)
  +        {
  +            af = new ServerClassAltrmiFactory( false );
  +        }
  +        else
  +        {
  +            af = new ClientClassAltrmiFactory( false );
  +        }
  +        return af;
       }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/piped/PipedTestCase.java
  
  Index: PipedTestCase.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.piped;
  
  import junit.framework.TestCase;
  import org.apache.excalibur.altrmi.server.*;
  import org.apache.excalibur.altrmi.server.impl.piped.AbstractPipedServer;
  import org.apache.excalibur.altrmi.server.impl.piped.PipedObjectStreamServer;
  import org.apache.excalibur.altrmi.test.*;
  import org.apache.excalibur.altrmi.client.AltrmiHostContext;
  import org.apache.excalibur.altrmi.client.AltrmiFactory;
  import org.apache.excalibur.altrmi.client.impl.piped.PipedObjectStreamHostContext;
  import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
  
  import java.io.IOException;
  import java.beans.PropertyVetoException;
  import java.util.HashMap;
  
  public class PipedTestCase extends TestCase {
  
      HashMap results = new HashMap();
  
      String helloString = "Howdie!!!";
  
      public PipedTestCase(String name) {
          super(name);
      }
  
      public void testClientSideBasic()
          throws Exception {
          String serverOrClientFactory = "C";
  
          PipedTest pt = new PipedTest();
  
          final PublicationDescription publicationDescription = new PublicationDescription(
TestInterface.class,
                                                                  new Class[]{
                                                                      TestInterface3.class,
                                                                      TestInterface2.class}
);
  
          final ClassRetriever classRetriever = pt.getClassRetriever(serverOrClientFactory,
publicationDescription);
  
          System.out.println( "Piped Test" );
  
          final AbstractPipedServer ps = new PipedObjectStreamServer();
  
          final TestInterface ti = new TestInterface() {
              public void hello(String greeting) {
                  results.put("hello", greeting);
              }
  
              public int hello2(int greeting) {
                  return 0;
              }
  
              public boolean hello3(short greeting) throws PropertyVetoException, IOException
{
                  return false;
              }
  
              public StringBuffer hello4(float greeting1, double greeting2) {
                  return null;
              }
  
              public void testSpeed() {
              }
  
              public String testSpeed2(String string) {
                  return null;
              }
  
              public TestInterface2 makeTestInterface2(String thingName) {
                  return null;
              }
  
              public void morphName(TestInterface2 forThisImpl) {
              }
  
              public TestInterface2 findTestInterface2ByName(String nameToFind) {
                  return null;
              }
  
              public TestInterface2[] getTestInterface2s() {
                  return new TestInterface2[0];
              }
  
              public TestObject[] getTestObjects() {
                  return new TestObject[0];
              }
  
              public void changeTestObjectNames() {
              }
  
              public void makeNewTestObjectNames() {
              }
          };
  
          Runnable server = new Runnable() {
              public void run() {
                ps.setClassRetriever( classRetriever );
                  try {
                      ps.publish( ti, "Hello", publicationDescription );
                  } catch (PublicationException e) {
                      System.err.println("Publication exception " + e.getMessage());
                  }
                  ps.start();
              }
          };
  
          Thread pipedTestServer = new Thread(server);
          pipedTestServer.start();
  
          Thread.sleep(500);
  
          PipedTestClient ptc = new JunitPipedTestClient( ps, serverOrClientFactory );
          Thread thread = new Thread( ptc );
  
          thread.start();
  
          Thread.sleep(5000);
  
          thread.interrupt();
  
          assertEquals("hello() method test", helloString, results.get("hello"));
  
      }
  
      class JunitPipedTestClient extends PipedTestClient {
          public JunitPipedTestClient(AbstractPipedServer pipedServer, String serverOrClient)
{
              super(pipedServer, serverOrClient);
          }
  
          public void run() {
              try
              {
  
                  AltrmiHostContext arhc = new PipedObjectStreamHostContext( in, out );
                  mPipedServer.makeNewConnection( in, out );
  
                  AltrmiFactory af = null;
  
                  af = makeFactory();
  
                  af.setHostContext( arhc );
  
                  // hangs here ....?
                  TestInterface ti = (TestInterface) af.lookup( "Hello" );
                  ti.hello(helloString);
                  af.close();
              }
              catch( IOException ioe )
              {
                  results.put( "IOE", "Some problem during connection to server : "
                                      + ioe.getMessage() );
              }
              catch( AltrmiConnectionException ace )
              {
                  results.put( "ACE", "Some problem during connection to server : "
                                      + ace.getMessage() );
              }
          }
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message