You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2009/08/28 09:40:28 UTC

svn commit: r808793 - in /tuscany/java/sca/modules/domain-node/src: main/java/org/apache/tuscany/sca/node/DomainNode.java test/java/org/apache/tuscany/sca/node/StopStartNodesTestCase.java

Author: antelder
Date: Fri Aug 28 07:40:28 2009
New Revision: 808793

URL: http://svn.apache.org/viewvc?rev=808793&view=rev
Log:
Add testcase for restarting DomainNodes and work around a problem that uncovers with stopping the NodeFactory kills all DOmainNodes

Added:
    tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/StopStartNodesTestCase.java
Modified:
    tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java

Modified: tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java?rev=808793&r1=808792&r2=808793&view=diff
==============================================================================
--- tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java (original)
+++ tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java Fri Aug 28 07:40:28 2009
@@ -72,9 +72,10 @@
             node.stop();
         }
         
-        nodeFactory.destroy();
-        nodeFactory = null;
-        nodes.clear();
+// TODO: stopping the node factory stops _all_ domain nodes not just this instance        
+//        nodeFactory.destroy();
+//        nodeFactory = null;
+//        nodes.clear();
     }
 
     public String addContribution(String location) {

Added: tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/StopStartNodesTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/StopStartNodesTestCase.java?rev=808793&view=auto
==============================================================================
--- tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/StopStartNodesTestCase.java (added)
+++ tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/StopStartNodesTestCase.java Fri Aug 28 07:40:28 2009
@@ -0,0 +1,79 @@
+/*
+ * 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.tuscany.sca.node;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import itest.nodes.Helloworld;
+
+import org.junit.After;
+import org.junit.Test;
+import org.oasisopen.sca.client.SCAClient;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class StopStartNodesTestCase{
+
+    private static DomainNode clientNode;
+    private static DomainNode serviceNode;
+    
+    @Test
+    public void testTwoNodesSameDomain() throws Exception {
+        serviceNode = new DomainNode("vm://fooDomain", "target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar");
+        clientNode = new DomainNode("vm://fooDomain", "target/test-classes/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar");
+
+        Helloworld service = SCAClient.getService(Helloworld.class, "fooDomain/HelloworldService");
+        assertNotNull(service);
+        assertEquals("Hello Petra", service.sayHello("Petra"));
+
+        Helloworld client = SCAClient.getService(Helloworld.class, "fooDomain/HelloworldClient");
+        assertNotNull(client);
+        assertEquals("Hi Hello Petra", client.sayHello("Petra"));
+
+        serviceNode.stop();
+
+        client = SCAClient.getService(Helloworld.class, "fooDomain/HelloworldClient");
+        assertNotNull(client);
+        try {
+            assertEquals("Hi Hello Petra", client.sayHello("Petra"));
+            fail();
+        } catch (Exception e) {
+            e.printStackTrace();
+            // expected
+        }
+
+        serviceNode = new DomainNode("vm://fooDomain", "target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar");
+        client = SCAClient.getService(Helloworld.class, "fooDomain/HelloworldClient");
+        assertNotNull(client);
+        assertEquals("Hi Hello Petra", client.sayHello("Petra"));
+    }
+
+    @After
+    public void tearDownAfterClass() throws Exception {
+        if (clientNode != null && clientNode.isStarted()) {
+            clientNode.stop();
+        }
+        if (serviceNode != null && serviceNode.isStarted()) {
+            serviceNode.stop();
+        }
+    }
+}