You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by rw...@apache.org on 2014/12/01 20:23:15 UTC

svn commit: r1642738 - in /portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test: AbstractJexlSpringTestCase.java AbstractJexlSpringTestServer.java

Author: rwatler
Date: Mon Dec  1 19:23:15 2014
New Revision: 1642738

URL: http://svn.apache.org/r1642738
Log:
JS2-1307: extend Jexl Scriptable Test Case to provide access to test process names and asynchronous close() to initiate parallel shutdown.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestCase.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestServer.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestCase.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestCase.java?rev=1642738&r1=1642737&r2=1642738&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestCase.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestCase.java Mon Dec  1 19:23:15 2014
@@ -41,6 +41,9 @@ import java.util.Map;
  */
 public abstract class AbstractJexlSpringTestCase extends AbstractSpringTestCase {
 
+    protected static final String SCRIPT_RESULT_LINE_PREFIX = AbstractJexlSpringTestServer.SCRIPT_RESULT_LINE_PREFIX;
+    protected static final String SCRIPT_RESULT_RETURN_VALUE_SEPARATOR = AbstractJexlSpringTestServer.SCRIPT_RESULT_RETURN_VALUE_SEPARATOR;
+
     private static final long LOGGING_PUMP_WAIT = 50;
 
     private Logger log = LoggerFactory.getLogger(getClass());
@@ -210,6 +213,7 @@ public abstract class AbstractJexlSpring
         private Process process;
         private BufferedWriter processInput;
         private BufferedReader processOutput;
+        private boolean closed;
 
         /**
          * Test program constructor.
@@ -306,7 +310,7 @@ public abstract class AbstractJexlSpring
             // read result or messages from process
             String resultLine = null;
             for (String line; ((line = processOutput.readLine()) != null);) {
-                if (! line.startsWith(AbstractJexlSpringTestServer.SCRIPT_RESULT_LINE_PREFIX)) {
+                if (!line.startsWith(SCRIPT_RESULT_LINE_PREFIX)) {
                     logProcessLine(line);
                 } else {
                     resultLine = line;
@@ -320,6 +324,18 @@ public abstract class AbstractJexlSpring
         }
 
         /**
+         * Asynchronously close test program process input. Shutdown must still
+         * be invoked which blocks on process termination.
+         *
+         * @throws IOException
+         */
+        public synchronized void close() throws IOException {
+            // close process input to trigger server close
+            processInput.close();
+            closed = true;
+        }
+
+        /**
          * Shutdown remote test program process, forcibly if necessary after
          * waiting for the specified timeout if it does not stop in its own.
          *
@@ -347,7 +363,9 @@ public abstract class AbstractJexlSpring
             destroyThread.start();
 
             // close process input to shutdown server and read messages
-            processInput.close();
+            if (!closed) {
+                processInput.close();
+            }
             for (String line; ((line = processOutput.readLine()) != null);) {
                 logProcessLine(line);
             }
@@ -374,6 +392,14 @@ public abstract class AbstractJexlSpring
                 log.info("{"+name+"} "+line);
             }
         }
+
+        public String getName() {
+            return name;
+        }
+
+        public int getIndex() {
+            return index;
+        }
     }
 
     /**

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestServer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestServer.java?rev=1642738&r1=1642737&r2=1642738&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestServer.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/test/AbstractJexlSpringTestServer.java Mon Dec  1 19:23:15 2014
@@ -41,6 +41,7 @@ import java.util.Map;
 public abstract class AbstractJexlSpringTestServer {
 
     public static final String SCRIPT_RESULT_LINE_PREFIX = "> ";
+    public static final String SCRIPT_RESULT_RETURN_VALUE_SEPARATOR = " -> ";
 
     protected String baseDir;
     protected SpringComponentManager scm;
@@ -123,10 +124,10 @@ public abstract class AbstractJexlSpring
             Script jexlScript = ScriptFactory.createScript(scriptLine);
             Object result = jexlScript.execute(jexlContext);
             if (result != null) {
-                resultLine += " -> "+result;
+                resultLine += SCRIPT_RESULT_RETURN_VALUE_SEPARATOR+result;
             }
         } catch (Exception e) {
-            resultLine += " -> "+e;
+            resultLine += SCRIPT_RESULT_RETURN_VALUE_SEPARATOR+e;
         }
         return resultLine;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org