You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ch...@apache.org on 2014/12/02 16:22:14 UTC

svn commit: r1642900 - in /uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src: main/java/org/apache/uima/ducc/cli/ test/java/org/apache/uima/ducc/cli/test/ test/scripts/

Author: challngr
Date: Tue Dec  2 15:22:14 2014
New Revision: 1642900

URL: http://svn.apache.org/r1642900
Log:
UIMA-4064 Update tests and provide a script driver.

Added:
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/scripts/
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/scripts/test_api.py   (with props)
Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ATestDriver.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ServiceTester.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/TestCommandLine.java

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java?rev=1642900&r1=1642899&r2=1642900&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java Tue Dec  2 15:22:14 2014
@@ -515,7 +515,6 @@ public class CommandLine
 
         if ( args       != null ) addCommandLine();
         if ( properties != null ) addProperties();
-
     }
         
 }

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ATestDriver.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ATestDriver.java?rev=1642900&r1=1642899&r2=1642900&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ATestDriver.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ATestDriver.java Tue Dec  2 15:22:14 2014
@@ -56,7 +56,7 @@ public abstract class ATestDriver
     void abort(String testid, Object ... reason)
         throws FailedTestException
     {
-        failReasons.add(join(testid, reason));
+        failReasons.add(join("FAILURE", testid, reason));
         throw new FailedTestException(join(testid, reason));
     }
     
@@ -68,7 +68,7 @@ public abstract class ATestDriver
      */
     void fail(String testid, Object ... reason)
     {
-        failReasons.add(join(testid, reason));
+        failReasons.add(join("FAILURE", testid, reason));
         System.out.println(join(testid, reason));        
     }
     
@@ -77,7 +77,7 @@ public abstract class ATestDriver
      */
     void success(String testid, Object ... reason)
     {
-        successReasons.add(join(testid, reason));
+        successReasons.add(join("SUCCESS", testid, reason));
         System.out.println(join(testid, reason));
     }
         

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ServiceTester.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ServiceTester.java?rev=1642900&r1=1642899&r2=1642900&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ServiceTester.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ServiceTester.java Tue Dec  2 15:22:14 2014
@@ -73,7 +73,7 @@ public class ServiceTester
     void fail(String testid, String subtestId, String reason)
         throws FailedTestException
     {
-        failReasons.add(testid + " - " + subtestId + " - " + reason);
+        failReasons.add("FAILURE " + testid + " - " + subtestId + " - " + reason);
         throw new FailedTestException(testid + " - " + subtestId + " - test failed: " + reason);
     }
 
@@ -86,7 +86,7 @@ public class ServiceTester
 
     void success(String testid, String subtestId, String reason)
     {
-        successReasons.add(testid + " - " + subtestId + " - " + reason);
+        successReasons.add("SUCCESS " + testid + " - " + subtestId + " - " + reason);
         System.out.println(testid + " - " + subtestId + " - test passed: " + reason);
     }
 
@@ -1285,11 +1285,11 @@ public class ServiceTester
         //
         // Do ping-only tests
         //
-        try {
-            runPingOnly();
-        } catch ( Exception e ) {
-            System.out.println("Ping-only test failed: " + e.toString());
-        }
+//        try {
+//            runPingOnly();
+//        } catch ( Exception e ) {
+//            System.out.println("Ping-only test failed: " + e.toString());
+//        }
 
         //
         // Do "normal" tests

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/TestCommandLine.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/TestCommandLine.java?rev=1642900&r1=1642899&r2=1642900&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/TestCommandLine.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/TestCommandLine.java Tue Dec  2 15:22:14 2014
@@ -399,15 +399,17 @@ public class TestCommandLine
         cl = new CommandLine(args, opts);
         testid = tid + ": optargs=T, multiargs=T, fetch deflt";
         try {
+            // TODO: If we implement multi args this block should register success, not failure
             cl.parse();
-            success(testid, "Parse succeeded.");
+            fail(testid, "Parse succeeded but should have failed because multargs is not implemented.");
             if ( cl.get(opts[0]).equals("bob")) {
                 success(testid, "Default of 'bob' correctly found.");
             } else {
                 fail(testid, "Did not fetch default. Expeced 'bob', found", cl.get(opts[0]));
             }
         } catch ( Exception e ) {
-            fail(testid, "Parse failed", e.getMessage());
+            // TODO: If we implement multi args this block should register failure, not success
+            success(testid, "Parse failed as expected, because multargs is not implemented.");
         }        
         
         args = new String[] {
@@ -416,15 +418,17 @@ public class TestCommandLine
         cl = new CommandLine(args, opts);
         testid = tid + ": optargs=T, multiargs=T, fetch value";
         try {
+            // TODO: If we implement multi args this block should register success, not failure
             cl.parse();
-            success(testid, "Parse succeeded.");
+            fail(testid, "Parse succeeded but should have failed because multargs is not implemented.");
             if ( cl.get(opts[0]).equals("mary")) {
                 success(testid, "Valu of 'mary' correctly found.");
             } else {
                 fail(testid, "Did not fetch default. Expeced 'mary', found", cl.get(opts[0]));
             }
         } catch ( Exception e ) {
-            fail(testid, "Parse failed", e.getMessage());
+            // TODO: If we implement multi args this block should register failure, not success
+            success(testid, "Parse failed as expected, because multargs is not implemented.");
         }        
         
     }
@@ -684,10 +688,11 @@ public class TestCommandLine
 
         try {            
             cl.parse();
+            cl.verify();
             fail(testid, "Incomplete option set should have failed but didn't");
 
         } catch (Exception e) {
-            success(testid, "Parse failed.", e.getMessage());
+            success(testid, "Parse failed as expected.", e.getMessage());
         }
         
     }

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/scripts/test_api.py
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/scripts/test_api.py?rev=1642900&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/scripts/test_api.py (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/scripts/test_api.py Tue Dec  2 15:22:14 2014
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+
+# -----------------------------------------------------------------------
+# 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.
+# -----------------------------------------------------------------------
+import os
+import sys
+import getopt
+import subprocess
+
+# 
+# Try to poison the CLI with a bogus xstream class (simulating an incorrect version of
+# xstreadm)
+#
+
+#
+# map the test id to the proper test class
+#
+testset = { 
+    '1' : 'TestCommandLine',
+    '2' : 'ClassSeparation',
+    '3' : 'ReserveAndCancel',
+    '4' : 'SubmitAndCancel',
+    '5' : 'ManagedReserveAndCancel',
+    '6' : 'ServiceTester',
+    }
+
+keys = testset.keys()
+
+def usage(*msg):
+    if ( msg[0] != None ):
+        print ' '
+        print 'Error:', ' '.join(msg)
+        print ' '
+
+    print 'Usage:'
+    print '    test_api.py --ducc_home <path-to-ducc-home> <testid>'
+    print ' '
+    print 'Where:'
+    print '    <path-to-ducc-home> is the full path to th einstalled Ducc Runtime to run against.'          
+    print ' '
+    print '    <testid> any of the following.  Multiple ids may be specified in a single run. If you'
+    print '    specify the same id multple times it will be run multiple times.'
+    print '        all: Run all tests'
+
+    for k in keys:
+        print '        ' + k + ":", testset[k]
+
+    sys.exit(1)
+
+def main():
+
+    test_classes = '../../../target/test-classes'
+    DUCC_HOME = None
+
+    argv = sys.argv[1:]
+
+    #
+    # get DUCC_HOME from caller
+    #
+    try:
+        opts, args = getopt.getopt(argv, '-h?', ['ducc_home='])
+    except:
+        usage("Invalid arguments " + ' '.join(argv))
+
+    for ( o, a ) in opts:
+        if o in ('-h', '-?'):
+            usage(None)
+        elif o in ('--ducc_home'):
+            DUCC_HOME = a
+        else:
+            usage('Invalid argument ' + a)
+
+    if ( DUCC_HOME == None ):
+        usage("Missing ducc_home")
+
+    #
+    # swap in all keys for 'all' and check for validity of specified test ids
+    #
+    realargs = []
+    for a in args:
+        if ( a == 'all' ):
+            realargs = realargs + keys
+        elif (a in keys):
+            realargs.append(a)
+        elif ( a in '?' ):
+            usage(None)
+        else:
+            usage('Invalid testid:', a)
+
+    #
+    # find the configured java
+    #
+    sys.path.append(DUCC_HOME + '/bin')
+    from ducc_base  import DuccProperties
+    props = DuccProperties()
+    props.load(DUCC_HOME + '/resources/ducc.properties')
+    java = props.get('ducc.jvm')
+
+    #
+    # establish test classpath
+    #
+    parts = [test_classes,                                      # test code
+             DUCC_HOME + '/lib/uima-ducc-cli.jar',              # DUCC API
+             DUCC_HOME + '/apache-uima/lib/uima-core.jar',      # Uima, for service tests
+             DUCC_HOME + '/apache-uima/lib/uimaj-as-core.jar',  # Uima-as, for service tests
+             ]
+    CLASSPATH = ':'.join(parts)
+
+    #
+    # run the tests
+    #
+    failures = []
+    for k in realargs:
+        print '============================== Test', k, ':', testset[k], '=============================='
+        CMD = [java, '-DDUCC_HOME='+DUCC_HOME, '-cp', CLASSPATH, 'org.apache.uima.ducc.cli.test.' + testset[k]]
+        CMD = ' '.join(CMD)
+        print CMD
+        proc = subprocess.Popen(CMD, bufsize=0, stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT)
+        for lines in proc.stdout:
+            if ( 'FAILURE' in lines ) :
+                failures.append((testset[k], lines))
+            print lines.strip()
+
+    os.system('rm -rf *.output')
+    # 
+    # finally summarize failures
+    #
+    if (len(failures) > 0 ):
+        print '============================== Failed tests =============================='
+        for f in failures:
+            print f[0], f[1]
+        
+main()

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/scripts/test_api.py
------------------------------------------------------------------------------
    svn:executable = *