You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ch...@apache.org on 2003/08/27 06:50:39 UTC

cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/remoting RemotingInterceptorsTest.java

chirino     2003/08/26 21:50:39

  Modified:    modules/core/src/java/org/apache/geronimo/remoting
                        DeMarshalingInterceptor.java
                        InterVMRoutingInterceptor.java
                        MarshalingInterceptor.java
               modules/core/src/test/org/apache/geronimo/deployment/scanner
                        WebDAVScannerTest.java
               modules/core/src/test/org/apache/geronimo/remoting
                        RemotingInterceptorsTest.java
  Log:
  Updated the Marshaller/Demarshaller to marsahll Throwable system exeptions since the invoke(..) interface changed.
  
  Finished up the InterVMRouting interceptor.  Enabled the test cases for it.
  
  Revision  Changes    Path
  1.3       +6 -6      incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/DeMarshalingInterceptor.java
  
  Index: DeMarshalingInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/DeMarshalingInterceptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DeMarshalingInterceptor.java	26 Aug 2003 22:11:24 -0000	1.2
  +++ DeMarshalingInterceptor.java	27 Aug 2003 04:50:39 -0000	1.3
  @@ -70,11 +70,11 @@
       private ClassLoader classloader;
       private Interceptor next;
   
  -    public static class ExceptionWrapper implements Serializable {
  -        ExceptionWrapper(Exception exception) {
  +    public static class ThrowableWrapper implements Serializable {
  +        ThrowableWrapper(Throwable exception) {
               this.exception = exception;
           }
  -        public Exception exception;
  +        public Throwable exception;
       }
   
       /**
  @@ -107,8 +107,8 @@
                   InvocationResult rc = getNext().invoke(marshalledInvocation);
                   mo.set(rc.getResult());
                   return new SimpleInvocationResult(mo);
  -            } catch (Exception e) {
  -                mo.set(new ExceptionWrapper(e));
  +            } catch (Throwable e) {
  +                mo.set(new ThrowableWrapper(e));
                   return new SimpleInvocationResult(mo);
               }
   
  
  
  
  1.3       +15 -13    incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/InterVMRoutingInterceptor.java
  
  Index: InterVMRoutingInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/InterVMRoutingInterceptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InterVMRoutingInterceptor.java	26 Aug 2003 22:11:24 -0000	1.2
  +++ InterVMRoutingInterceptor.java	27 Aug 2003 04:50:39 -0000	1.3
  @@ -71,7 +71,7 @@
   
       String targetVMID = getLocalVMID();
       transient Interceptor next;
  -    Interceptor remotingInterceptor;
  +    TransportInterceptor transportInterceptor;
       Interceptor localInterceptor;
   
       /**
  @@ -86,7 +86,7 @@
        */
       public void writeExternal(ObjectOutput out) throws IOException {
           out.writeUTF(targetVMID);
  -        out.writeObject(remotingInterceptor);
  +        out.writeObject(transportInterceptor);
           out.writeObject(localInterceptor);
       }
   
  @@ -95,19 +95,21 @@
        */
       public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
           targetVMID = in.readUTF();
  -        remotingInterceptor = (Interceptor) in.readObject();
  +        transportInterceptor = (TransportInterceptor) in.readObject();
           localInterceptor = (Interceptor) in.readObject();
   
           if (getLocalVMID().equals(targetVMID)) {
  -            next.setNext(localInterceptor);
  +            next = localInterceptor;
           } else {
  -            next.setNext(remotingInterceptor);
  +            // We have to marshall first..
  +            next = new MarshalingInterceptor();
  +            next.setNext(transportInterceptor);
           }
       }
  -
  +    
  +    final static String localVMID = "VM:"+System.currentTimeMillis(); 
       public static String getLocalVMID() {
  -        // TODO: generate a GUID here and return it.
  -        return "";
  +        return localVMID;
       }
   
       /**
  @@ -127,15 +129,15 @@
       /**
        * @return
        */
  -    public Interceptor getRemotingInterceptor() {
  -        return remotingInterceptor;
  +    public TransportInterceptor getTransportInterceptor() {
  +        return transportInterceptor;
       }
   
       /**
        * @param remotingInterceptor
        */
  -    public void setRemotingInterceptor(Interceptor remotingInterceptor) {
  -        this.remotingInterceptor = remotingInterceptor;
  +    public void setTransportInterceptor(TransportInterceptor remotingInterceptor) {
  +        this.transportInterceptor = remotingInterceptor;
       }
   
       /**
  
  
  
  1.3       +3 -3      incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/MarshalingInterceptor.java
  
  Index: MarshalingInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/MarshalingInterceptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MarshalingInterceptor.java	26 Aug 2003 22:11:24 -0000	1.2
  +++ MarshalingInterceptor.java	27 Aug 2003 04:50:39 -0000	1.3
  @@ -85,8 +85,8 @@
           Object result = mo.get();
   
           // Are we demarshalling a thrown exception.
  -        if (result instanceof DeMarshalingInterceptor.ExceptionWrapper) {
  -            throw ((DeMarshalingInterceptor.ExceptionWrapper) result).exception;
  +        if (result instanceof DeMarshalingInterceptor.ThrowableWrapper) {
  +            throw ((DeMarshalingInterceptor.ThrowableWrapper) result).exception;
           }
   
           return new SimpleInvocationResult(result);
  
  
  
  1.3       +3 -4      incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/scanner/WebDAVScannerTest.java
  
  Index: WebDAVScannerTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/scanner/WebDAVScannerTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WebDAVScannerTest.java	12 Aug 2003 20:26:31 -0000	1.2
  +++ WebDAVScannerTest.java	27 Aug 2003 04:50:39 -0000	1.3
  @@ -55,12 +55,11 @@
    */
   package org.apache.geronimo.deployment.scanner;
   
  +import java.io.IOException;
  +import java.io.InputStream;
   import java.net.URL;
  -import java.net.URLConnection;
   import java.util.Iterator;
   import java.util.Set;
  -import java.io.IOException;
  -import java.io.InputStream;
   
   import junit.framework.TestCase;
   
  
  
  
  1.3       +42 -30    incubator-geronimo/modules/core/src/test/org/apache/geronimo/remoting/RemotingInterceptorsTest.java
  
  Index: RemotingInterceptorsTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/remoting/RemotingInterceptorsTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RemotingInterceptorsTest.java	25 Aug 2003 03:14:46 -0000	1.2
  +++ RemotingInterceptorsTest.java	27 Aug 2003 04:50:39 -0000	1.3
  @@ -62,11 +62,9 @@
   import java.net.URI;
   import java.net.URL;
   import java.net.URLClassLoader;
  -import java.util.ArrayList;
   
   import junit.framework.TestCase;
   
  -import org.apache.geronimo.common.Interceptor;
   import org.apache.geronimo.proxy.ProxyContainer;
   import org.apache.geronimo.proxy.ReflexiveInterceptor;
   import org.apache.geronimo.remoting.transport.BytesMarshalledObject;
  @@ -89,7 +87,6 @@
   
       private static final String PERSON_CLASS = "org.apache.geronimo.remoting.Person";
       private static final String TRANSIENT_CLASS = "org.apache.geronimo.remoting.TransientValue";
  -    ArrayList severContainers = new ArrayList();
       URLClassLoader cl1, cl2;
       
       TransportServer server;
  @@ -185,7 +182,7 @@
   
           // Simulate App1 creating a proxy.
           Thread.currentThread().setContextClassLoader(cl1);
  -        Object proxy1 = createProxy(object1);
  +        Object proxy1 = createProxy(object1, true);
           call(proxy1, "setSpouse", new Object[] { object1 });
       }
   
  @@ -206,7 +203,7 @@
   
           // Simulate App2 creating a proxy.
           Thread.currentThread().setContextClassLoader(cl2);
  -        Object proxy2 = createProxy(object2);
  +        Object proxy2 = createProxy(object2, true);
           MarshalledObject mo = new BytesMarshalledObject(proxy2);
   
           // Simulate App1 using the serialized proxy.    
  @@ -224,7 +221,6 @@
        * 
        * @throws Throwable
        */
  -    /* Disable until proxy knows how to do a local optimize.
       public void testSetTransientWithOptimizedProxy() throws Throwable {
           Thread.currentThread().setContextClassLoader(cl1);
           Class class1 = cl1.loadClass(PERSON_CLASS);
  @@ -234,7 +230,7 @@
           Object object2 = class2.newInstance();
           call(object2, "setValue", new Object[] { "foo" });
   
  -        Object proxy1 = createProxy(object1);
  +        Object proxy1 = createProxy(object1, false);
           call(proxy1, "setValue", new Object[] { object2 });
           Object rc = call(proxy1, "getValue", new Object[] {
           });
  @@ -243,7 +239,6 @@
   
           assertSame(rc, "foo");
       }
  -    */
       
       /**
        * Same as testSetTransientWithOptimizedProxy() but, the proxy is serialized before it is used.
  @@ -251,7 +246,6 @@
        * 
        * @throws Throwable
        */
  -    /* Disable until proxy knows how to do a local optimize.
       public void testSetTransientWithSerializedOptimizedProxy() throws Throwable {
           Thread.currentThread().setContextClassLoader(cl1);
           Class class1 = cl1.loadClass(PERSON_CLASS);
  @@ -261,17 +255,26 @@
           Object object2 = class2.newInstance();
           call(object2, "setValue", new Object[] { "foo" });
   
  -        Object proxy1 = createProxy(object1);
  +        // First test to see waht happens if we mock it to be a remote object.
  +        Object proxy1 = createProxy(object1,true);
           proxy1 = new BytesMarshalledObject(proxy1).get();
           call(proxy1, "setValue", new Object[] { object2 });
           Object rc = call(proxy1, "getValue", new Object[] {
           });
           rc = call(rc, "getValue", new Object[] {
           });
  +        assertSame(rc, null); // The value was marsalled cause it's remote.
   
  -        assertSame(rc, "foo");
  +        // Second test to see what happens if we mock it to be a local object.
  +        proxy1 = createProxy(object1,false);
  +        proxy1 = new BytesMarshalledObject(proxy1).get();
  +        call(proxy1, "setValue", new Object[] { object2 });
  +        rc = call(proxy1, "getValue", new Object[] {
  +        });
  +        rc = call(rc, "getValue", new Object[] {
  +        });
  +        assertSame(rc, "foo"); // No serialization occured.
       }
  -    */
       
       /**
        * Same as testSetTransientWithOptimizedProxy() but, the proxy is serialized before it is
  @@ -285,7 +288,7 @@
           Class class1 = cl1.loadClass(PERSON_CLASS);
           Object object1 = class1.newInstance();
   
  -        Object proxy1 = createProxy(object1);
  +        Object proxy1 = createProxy(object1, true);
           Thread.currentThread().setContextClassLoader(cl2);
           proxy1 = new BytesMarshalledObject(proxy1).get();
   
  @@ -353,26 +356,35 @@
         * @param object1
         * @return
         */
  -    private Object createProxy(Object object1) throws Exception {
  -        
  -        ProxyContainer serverContainer = new ProxyContainer();        
  +    private Object createProxy(Object target, boolean mockFromRemoteMV ) throws Exception {
   
  -        DeMarshalingInterceptor dmi = new DeMarshalingInterceptor();
  -        dmi.setClassloader(object1.getClass().getClassLoader());
  -        Long dmiid = InterceptorRegistry.instance.register(dmi);
  -        serverContainer.addInterceptor(dmi);      
  -        Interceptor reflexive = new ReflexiveInterceptor(object1);
  -        serverContainer.addInterceptor(reflexive);
  -        severContainers.add(serverContainer);
  +        // Setup the server side contianer..        
  +        ProxyContainer serverContainer = new ProxyContainer();        
  +        DeMarshalingInterceptor demarshaller = new DeMarshalingInterceptor();
  +        serverContainer.addInterceptor(demarshaller);      
  +        serverContainer.addInterceptor(new ReflexiveInterceptor(target));
  +        
  +        // Configure the server side interceptors.
  +        demarshaller.setClassloader(target.getClass().getClassLoader());
  +        Long dmiid = InterceptorRegistry.instance.register(demarshaller);
           
  +        // Setup the client side container..        
           ProxyContainer clientContainer = new ProxyContainer();
  -        clientContainer.addInterceptor(new MarshalingInterceptor());
  -        RemoteTransportInterceptor rti = new RemoteTransportInterceptor();
  -        URI u = URISupport.setFragment(connectURI, ""+dmiid);        
  -        rti.setRemoteURI(u);
  -        clientContainer.addInterceptor(rti);
  +        InterVMRoutingInterceptor remoteRouter = new InterVMRoutingInterceptor();
  +        clientContainer.addInterceptor(remoteRouter);
  +        IntraVMRoutingInterceptor localRouter = new IntraVMRoutingInterceptor();
  +        clientContainer.addInterceptor(localRouter);
  +
  +        // Configure the client side interceptors.
  +        localRouter.setDeMarshalingInterceptorID(dmiid);
  +        remoteRouter.setLocalInterceptor(localRouter);
  +        RemoteTransportInterceptor transport = new RemoteTransportInterceptor();
  +        transport.setRemoteURI(URISupport.setFragment(connectURI, ""+dmiid));
  +        remoteRouter.setTransportInterceptor(transport);
  +        if(mockFromRemoteMV)
  +            remoteRouter.setTargetVMID("THIS CRAP WILL NOT MATCH THE LOCAL VM ID");
           
  -        return clientContainer.createProxy(object1.getClass());
  +        return clientContainer.createProxy(target.getClass());
       }
   
   }