You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2009/08/02 09:58:52 UTC

svn commit: r800005 - in /servicemix/components/bindings/servicemix-rmi/trunk/src: main/java/org/apache/servicemix/rmi/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/servicemix/ test/java/org/apache/servicemix/rmi/ test/res...

Author: jbonofre
Date: Sun Aug  2 07:58:51 2009
New Revision: 800005

URL: http://svn.apache.org/viewvc?rev=800005&view=rev
Log:
Add servicemix-rmi unit tests.

Added:
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/Echo.java   (with props)
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java   (with props)
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/log4j.properties   (with props)
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml   (with props)
Modified:
    servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiBridgeEndpoint.java
    servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java
    servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java

Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiBridgeEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiBridgeEndpoint.java?rev=800005&r1=800004&r2=800005&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiBridgeEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiBridgeEndpoint.java Sun Aug  2 07:58:51 2009
@@ -40,7 +40,9 @@
  * </p>
  * 
  * @author jbonofre
+ * @org.apache.xbean.XBean element="bridge"
  */
+@Deprecated
 public class RmiBridgeEndpoint extends ConsumerEndpoint implements RmiEndpointType, InvocationHandler {
 
     private List<Class> remoteInterfaces; // the remote interfaces to use (consumer/provider)

Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java?rev=800005&r1=800004&r2=800005&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java Sun Aug  2 07:58:51 2009
@@ -39,6 +39,7 @@
  * </p>
  * 
  * @author jbonofre
+ * @org.apache.xbean.XBean element="consumer"
  */
 public class RmiConsumerEndpoint extends ConsumerEndpoint implements RmiEndpointType, InvocationHandler {
 
@@ -51,6 +52,68 @@
     private Remote stub; // the remote stub
     private Remote proxy; // the remote proxy
     
+    public List<Class> getRemoteInterfaces() {
+        return this.remoteInterfaces;
+    }
+    
+    /**
+     * <p>
+     * This attribute defines the remote interfaces implemented by RMI endpoint.
+     * </p>
+     * 
+     * @param remoteInterfaces the remote interfaces.
+     */
+    public void setRemoteInterfaces(List<Class> remoteInterfaces) {
+        this.remoteInterfaces = remoteInterfaces;
+    }
+    
+    public int getPort() {
+        return this.port;
+    }
+    
+    /**
+     * <p>
+     * This attribute defines the port number used by the RMI registry.
+     * </p>
+     * 
+     * @param port the RMI registry port number.
+     * @org.apache.xbean.Property description="The RMI registry port number."
+     */
+    public void setPort(int port) {
+        this.port = port;
+    }
+    
+    public String getName() {
+        return this.name;
+    }
+    
+    /**
+     * <p>
+     * This attribute defines the endpoint name in the RMI registry.
+     * </p>
+     * 
+     * @param name the endpoint name in the registry.
+     * @org.apache.xbean.Property description="The endpoint name into the RMI registry."
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public Object getPojo() {
+        return this.pojo;
+    }
+    
+    /**
+     * <p>
+     * This attribute defines the POJO on which method calls are delegated.
+     * </p>
+     * 
+     * @param pojo the delegation POJO.
+     * @org.apache.xbean.Property description="The POJO on which method calls are delegated."
+     */
+    public void setPojo(Object pojo) {
+        this.pojo = pojo;
+    }
     
     /*
      * (non-Javadoc)
@@ -58,10 +121,26 @@
      */
     @Override
     public void validate() throws DeploymentException {
+        
+        if (this.getTargetService() == null) {
+            logger.warn("Target service not defined, use the endpoint one.");
+            this.setTargetService(this.getService());
+        }
+        
+        if (this.getTargetEndpoint() == null) {
+            logger.warn("Target endpoint not defined, use the endpoint one.");
+            this.setTargetEndpoint(this.getEndpoint());
+        }
+
         super.validate();
         
+        if (remoteInterfaces == null || remoteInterfaces.size() < 1) {
+            throw new DeploymentException("The remoteInterfaces property is mandatory.");
+        }
+        
         if (name == null || name.trim().length() < 1) {
-            // if the user hasn't define the registry name, take the endpoint one
+            // if the user hasn't define the registry name, use the endpoint one
+            logger.debug("The user hasn't define the registry name, use the endpoint one.");
             name = this.getEndpoint();
         }
     }
@@ -73,8 +152,11 @@
     @Override
     public synchronized void start() throws Exception {
         super.start();
+        
         // create the dynamic proxy
-        proxy = (Remote) Proxy.newProxyInstance(this.getClass().getClassLoader(), (Class[])remoteInterfaces.toArray(), this);
+        Class[] interfaces = new Class[remoteInterfaces.size()];
+        remoteInterfaces.toArray(interfaces);
+        proxy = (Remote) Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaces, this);
         // create the remote stub
         stub = UnicastRemoteObject.exportObject(proxy, port);
         try {
@@ -120,11 +202,12 @@
         logger.debug("Method: " + method);
         logger.debug("Args: " + args);
         if (pojo != null) {
-            // bypass to POJO delegation
-            method.invoke(pojo, args);
+            // delegrate method call to the POJO
+            // WARNING: using POJO you bypass NMR and it's a direct POJO call
+            return method.invoke(pojo, args);
         } else {
             // going through the NMR
-            // TODO use a marshaler
+            // TODO use a marshaler and send to the target endpoint
         }
         return null;
     }

Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java?rev=800005&r1=800004&r2=800005&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java Sun Aug  2 07:58:51 2009
@@ -38,6 +38,7 @@
  * </p>
  * 
  * @author jbonofre
+ * @org.apache.xbean.XBean element="provider"
  */
 public class RmiProviderEndpoint extends ProviderEndpoint implements RmiEndpointType {
 

Added: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/Echo.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/Echo.java?rev=800005&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/Echo.java (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/Echo.java Sun Aug  2 07:58:51 2009
@@ -0,0 +1,17 @@
+package org.apache.servicemix.rmi;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * <p>
+ * Very simple remote interface to test remote.
+ * </p>
+ * 
+ * @author jbonofre
+ */
+public interface Echo extends Remote {
+    
+    public String echo(String message) throws RemoteException;
+
+}

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/Echo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java?rev=800005&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java Sun Aug  2 07:58:51 2009
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */package org.apache.servicemix.rmi;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.container.JBIContainer;
+
+/**
+ * <p>
+ * Test the RMI xbean deployment.
+ * </p>
+ * 
+ * @author jbonofre
+ */
+public class RmiXBeanTest extends TestCase {
+    
+    // logging facility
+    private final static transient Log LOG = LogFactory.getLog(RmiXBeanTest.class);
+    
+    protected JBIContainer container;
+    
+    /*
+     * (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        // create and start the JBI container
+        container = new JBIContainer();
+        container.setUseMBeanServer(false);
+        container.setCreateMBeanServer(false);
+        container.setEmbedded(true);
+        container.init();
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see junit.framework.TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        // stop the JBI container
+        if (container != null) {
+            container.shutDown();
+        }
+    }
+    
+    /**
+     * <p>
+     * Main deployment test using a xbean.xml.
+     * </p>
+     * 
+     * @throws Exception in case of deployment failure.
+     */
+    public void testDeployment() throws Exception {
+        // RMI component
+        RmiComponent rmiComponent = new RmiComponent();
+        // activate the RMI component into the JBI container
+        container.activateComponent(rmiComponent, "RmiComponent");
+        
+        // start the JBI container
+        container.start();
+        
+        // deploy the RMI SU corresponding to the xbean.xml
+        // deploy SU
+        URL url = getClass().getClassLoader().getResource("xbean/xbean.xml");
+        File path = new File(new URI(url.toString()));
+        path = path.getParentFile();
+        rmiComponent.getServiceUnitManager().deploy("xbean", path.getAbsolutePath());
+        rmiComponent.getServiceUnitManager().init("xbean", path.getAbsolutePath());
+        rmiComponent.getServiceUnitManager().start("xbean");
+        
+        // test if the SUs have been deployed
+        assertNotNull("RMI endpoint {http://servicemix.apache.org/test}rmiSimpleConsumer is not found in the JBI container.", container.getRegistry().getEndpoint(new QName("http://servicemix.apache.org/test", "rmi"), "SimpleConsumer"));
+        assertNotNull("RMI endpoint {http://servicemix.apache.org/test}rmiByPassConsumer is not found in the JBI container.", container.getRegistry().getEndpoint(new QName("http://servicemix.apache.org/test", "rmi"), "ByPassConsumer"));
+    }
+
+}

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/log4j.properties?rev=800005&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/log4j.properties (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/log4j.properties Sun Aug  2 07:58:51 2009
@@ -0,0 +1,43 @@
+# 
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed  under the  License is distributed on an "AS IS" BASIS,
+# WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+# implied.
+#  
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, stdout
+
+log4j.logger.org.springframework=INFO
+log4j.logger.org.apache.activemq=INFO
+log4j.logger.org.apache.activemq.spring=WARN
+
+
+log4j.logger.org.apache.servicemix=DEBUG
+
+# CONSOLE appender 
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/servicemix-test.log
+log4j.appender.out.append=true

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:executable = *

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml?rev=800005&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml Sun Aug  2 07:58:51 2009
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<beans xmlns:rmi="http://servicemix.apache.org/rmi/1.0"
+       xmlns:test="http://servicemix.apache.org/test">
+
+    <rmi:consumer service="test:rmi" endpoint="SimpleConsumer">
+        <property name="remoteInterfaces">
+            <list>
+                <value>org.apache.servicemix.rmi.Echo</value>
+            </list>
+        </property>
+    </rmi:consumer>
+    
+    <!-- 
+    <rmi:consumer service="test:rmi" endpoint="ByPassConsumer" remoteInterfaces="org.apache.servicemix.rmi.Echo">
+        <rmi:pojo>
+            <bean class="org.apache.servicenix.rmi.test.EchoImpl"/>
+        </rmi:pojo>
+    </rmi:consumer>
+    -->       
+       
+</beans>
\ No newline at end of file

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain