You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/02/23 16:21:10 UTC

svn commit: r915379 - in /tuscany/sca-java-2.x/trunk: itest/nodes/ itest/nodes/one-jvm-hazelcast/ itest/nodes/one-jvm-hazelcast/src/test/java/itest/ modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/

Author: slaws
Date: Tue Feb 23 15:21:10 2010
New Revision: 915379

URL: http://svn.apache.org/viewvc?rev=915379&view=rev
Log:
TUSCANY-3473 - where a local call (local interface) is used within a contribution but where the hazelcast registry is in operation I've updated the registry to return the actual endpoint rather than the serialized version so that the endpoint isn't marked as remote and so that the interface contract is intact. This also adds and enables a test case that ensures that this is working. 

Added:
    tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/OneNodeOneContributionTestCase.java   (with props)
Modified:
    tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/pom.xml
    tuscany/sca-java-2.x/trunk/itest/nodes/pom.xml
    tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java

Modified: tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/pom.xml?rev=915379&r1=915378&r2=915379&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/pom.xml Tue Feb 23 15:21:10 2010
@@ -31,6 +31,11 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>itest-nodes-helloworld-service-and-client</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>    
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>itest-nodes-helloworld-iface</artifactId>
             <version>2.0-SNAPSHOT</version>
         </dependency>

Added: tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/OneNodeOneContributionTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/OneNodeOneContributionTestCase.java?rev=915379&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/OneNodeOneContributionTestCase.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/OneNodeOneContributionTestCase.java Tue Feb 23 15:21:10 2010
@@ -0,0 +1,64 @@
+/*
+ * 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 itest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import itest.nodes.sac.Helloworld;
+
+import java.net.URI;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.oasisopen.sca.client.SCAClientFactory;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class OneNodeOneContributionTestCase{
+
+	private static URI domainURI = URI.create("tuscany:OneNodeTestCase");
+    private static Node node;
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        node = NodeFactory.getInstance().createNode(domainURI, "../helloworld-service-and-client/target/classes");
+        node.start();
+    }
+
+    @Test
+    public void testNode() throws Exception {
+
+        Helloworld client = node.getService(Helloworld.class, "HelloworldClient");
+        assertNotNull(client);
+        assertEquals("Hi Hello Petra", client.sayHello("Petra"));
+    
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {
+        if (node != null) {
+            node.stop();
+        }
+    }
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/OneNodeOneContributionTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/OneNodeOneContributionTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/sca-java-2.x/trunk/itest/nodes/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/pom.xml?rev=915379&r1=915378&r2=915379&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/pom.xml Tue Feb 23 15:21:10 2010
@@ -37,6 +37,7 @@
     <module>helloworld-iface</module>
     <module>helloworld-service</module>
     <module>helloworld-client</module>
+    <module>helloworld-service-and-client</module>
 <!--
     <module>helloworld-service-a</module>
     <module>helloworld-service-b</module>

Modified: tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java?rev=915379&r1=915378&r2=915379&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java Tue Feb 23 15:21:10 2010
@@ -58,7 +58,7 @@
 
     private HazelcastInstance hazelcastInstance;
     protected Map<Object, Object> map;
-    private List<String> localEndpoints = new ArrayList<String>();
+    private Map<String, Endpoint> localEndpoints = new HashMap<String, Endpoint>();
 
     public HazelcastEndpointRegistry(ExtensionPointRegistry registry,
                                      Map<String, String> attributes,
@@ -138,7 +138,7 @@
 
     public void addEndpoint(Endpoint endpoint) {
         map.put(endpoint.getURI(), endpoint);
-        localEndpoints.add(endpoint.getURI());
+        localEndpoints.put(endpoint.getURI(), endpoint);
         logger.info("Add endpoint - " + endpoint);
     }
 
@@ -150,8 +150,15 @@
             if (matches(uri, endpoint.getURI())) {
                 if (!isLocal(endpoint)) {
                     endpoint.setRemote(true);
+                    ((RuntimeEndpoint)endpoint).bind(registry, this);
+                } else {
+                    // get the local version of the endpoint
+                    // this local version won't have been serialized
+                    // won't be marked as remote and will have the 
+                    // full interface contract information
+                    endpoint = localEndpoints.get(endpoint.getURI());
                 }
-                ((RuntimeEndpoint)endpoint).bind(registry, this);
+                
                 foundEndpoints.add(endpoint);
                 logger.fine("Found endpoint with matching service  - " + endpoint);
             }
@@ -161,7 +168,7 @@
     
 
     private boolean isLocal(Endpoint endpoint) {
-        return localEndpoints.contains(endpoint.getURI());
+        return localEndpoints.containsKey(endpoint.getURI());
     }
 
     public Endpoint getEndpoint(String uri) {
@@ -200,7 +207,7 @@
         if (!isLocal(newEp)) {
             logger.info(" Remote endpoint added: " + newEp);
             newEp.setRemote(true);
-        }
+        } 
         endpointAdded(newEp);
     }