Author: slaws
Date: Wed Apr 27 09:36:49 2011
New Revision: 1097055

URL: http://svn.apache.org/viewvc?rev=1097055&view=rev
Log:
make the test runner a simple deamon so it can be shut down properly

Modified:
    tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/build.xml
    
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
    
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/test/resources/domain-domain1/node-nodeService/node.xml

Modified: 
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/build.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/build.xml?rev=1097055&r1=1097054&r2=1097055&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/build.xml 
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/build.xml 
Wed Apr 27 09:36:49 2011
@@ -19,20 +19,22 @@
 <project name="itest-nodes-two-jvms-hazelcast" default="run">
        
     <target name="run"> 
-       <parallel failonany="true">
-
-            <daemons>
-                <java 
classpath="../../../../distribution/all/target/apache-tuscany-sca-all-2.0-SNAPSHOT.dir/tuscany-sca-2.0-SNAPSHOT/features/tuscany-sca-manifest.jar:./target/classes"
        
-                      classname="org.apache.tuscany.sca.impl.Tuscany"
-                      fork="true"
-                      failonerror="true">   
-                    <arg value="domain1"/>
-                    <arg value="nodeService"/>
-                </java>
-            </daemons>
+       <parallel failonany="true">          
+            
+            <!-- start a node that will be part of the domain -->
+            <java 
classpath="../../../../distribution/all/target/apache-tuscany-sca-all-2.0-SNAPSHOT.dir/tuscany-sca-2.0-SNAPSHOT/features/tuscany-sca-manifest.jar:./target/classes"
        
+                  classname="org.apache.tuscany.sca.impl.Tuscany"
+                  fork="true"
+                  failonerror="true">   
+                <arg value="domain1"/>
+                <arg value="nodeService"/>
+                <arg value="8088"/>
+            </java>            
         
-            <sequential>
-                <sleep seconds="5"/>
+            <sequential>         
+                <!-- give the first node a chance to start --> 
+                <sleep seconds="5"/>   
+                <!-- start a second node that automatically tries to call a 
service in the first node -->            
                 <java 
classpath="../../../../distribution/all/target/apache-tuscany-sca-all-2.0-SNAPSHOT.dir/tuscany-sca-2.0-SNAPSHOT/features/tuscany-sca-manifest.jar:./target/classes"
        
                       classname="org.apache.tuscany.sca.impl.Tuscany"
                       fork="true"
@@ -40,6 +42,10 @@
                     <arg value="domain1"/>
                     <arg value="nodeClient"/>
                 </java> 
+                <!-- use a HTTP GET to ping the first node to tell it to stop 
-->
+                <get src="http://localhost:8088"; 
+                     dest="target/deamon.txt"
+                     ignoreerrors="true"/>
             </sequential>
 
        </parallel>         

Modified: 
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java?rev=1097055&r1=1097054&r2=1097055&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
 Wed Apr 27 09:36:49 2011
@@ -21,6 +21,9 @@ package org.apache.tuscany.sca.impl;
 
 import java.io.File;
 import java.io.FilenameFilter;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
 import java.net.URL;
 
 import org.apache.tuscany.sca.node.Node;
@@ -35,6 +38,11 @@ public class Tuscany {
     public static void main(String[] args) throws Exception {
         String domainName = args[0];
         String nodeName = args[1];
+        int deamonPort = -1;
+        
+        if (args.length > 2){
+            deamonPort = Integer.parseInt(args[2]);
+        }
         
         // find the domain directory
         File currentDirectory = new File(".");
@@ -57,8 +65,38 @@ public class Tuscany {
         URL nodeConfigURL = nodeDirectory.toURI().resolve("node.xml").toURL();
         Node node = nodeFactory.createNode(nodeConfigURL);
         
+        ShutdownThread shutdown = new ShutdownThread(node);
+        Runtime.getRuntime().addShutdownHook(shutdown);
+        
         node.start();
         
+        // for testing we're going to set up a deamon that listens for 
+        // a shutdown message on a specified port (well it actually just 
+        // waits for a client to connect to the port as that's all we need
+        // for now). If no port is specified then just stop straight away
+        
+        if (deamonPort >= 0){
+            // Its a runtime that has to act as a deamon
+            ServerSocket serverSocket = null;
+                
+            try {
+                serverSocket = new ServerSocket(deamonPort);
+            } catch (IOException e) {
+                System.out.println("Can't create a ServerSocket on port: " + 
deamonPort);
+            }
+            
+            // all we're doing here is waiting for a connection. If we wanted 
to implement
+            // a real deamon we should perhaps listen to what's coming in over 
the resulting socket
+            // and see if a shutdown has been requested
+            Socket clientSocket = null;
+            try {
+                clientSocket = serverSocket.accept();
+            } catch (IOException e) {
+                System.out.println("Accept failed on port: " + deamonPort);
+            }
+        } 
+        
+        node.stop();
     }
     
     /**
@@ -94,4 +132,18 @@ public class Tuscany {
             return false;
         }
     }
+    
+    private static class ShutdownThread extends Thread {
+        private Node node;
+
+        public ShutdownThread(Node node) {
+            super();
+            this.node = node;
+        }
+
+        @Override
+        public void run() {
+            node.stop();
+        }
+    }    
 }
\ No newline at end of file

Modified: 
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/test/resources/domain-domain1/node-nodeService/node.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/test/resources/domain-domain1/node-nodeService/node.xml?rev=1097055&r1=1097054&r2=1097055&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/test/resources/domain-domain1/node-nodeService/node.xml
 (original)
+++ 
tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/test/resources/domain-domain1/node-nodeService/node.xml
 Wed Apr 27 09:36:49 2011
@@ -21,8 +21,8 @@
     xmlns="http://tuscany.apache.org/xmlns/sca/1.1";
     xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1";
     uri="http://sample/nodes/TestNode2";
-    domain="default"
-    domainRegistry="tuscany:default?listen=127.0.0.1:14820">
+    domain="default"  
+    domainRegistry="tuscany:default?listen=127.0.0.1:14820">   
 
     <!-- Configure the base URIs for a given binding -->
     <!-- Each base URI is for a protocol supported by the binding -->


Reply via email to