Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java?rev=1634635&r1=1634634&r2=1634635&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java Mon Oct 27 18:21:39 2014 @@ -20,7 +20,6 @@ package org.apache.uima.ducc.cli.aio; import java.io.IOException; -import org.apache.commons.cli.MissingArgumentException; import org.apache.uima.analysis_engine.AnalysisEngineProcessException; import org.apache.uima.cas.CAS; import org.apache.uima.collection.CollectionException; @@ -80,7 +79,7 @@ public class AllInOne extends CliBase { } } - private void examine() throws MissingArgumentException, IllegalArgumentException { + private void examine() throws IllegalArgumentException { String mid = "examine"; mh.frameworkTrace(cid, mid, "enter"); examine_debug();
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java?rev=1634635&r1=1634634&r2=1634635&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java Mon Oct 27 18:21:39 2014 @@ -28,7 +28,6 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import org.apache.commons.cli.MissingArgumentException; import org.apache.uima.ducc.cli.CliBase; import org.apache.uima.ducc.cli.DuccJobSubmit; import org.apache.uima.ducc.cli.DuccManagedReservationSubmit; @@ -198,13 +197,13 @@ public class AllInOneLauncher extends Cl // all-in-one - private void examine_allInOne() throws MissingArgumentException, IllegalArgumentException { + private void examine_allInOne() throws IllegalArgumentException { String mid = "examine_allInOne"; mh.frameworkTrace(cid, mid, enter); String pname = UiOption.AllInOne.pname(); allInOneType = jobRequestProperties.getProperty(pname); if(allInOneType == null) { - throw new MissingArgumentException(pname); + throw new IllegalArgumentException("Illegal argument for all_in_one: " + pname); } if(allInOneType.equalsIgnoreCase(local)) { String message = allInOneType; @@ -328,7 +327,7 @@ public class AllInOneLauncher extends Cl // Don't need all the DUCC jars as user's classpath must have all the UIMA jars it needs. // For simplicity add only the jar that has the AllInOne class --- it will pull in other // jars that have dependencies such as the flow controller. - String duccClasspath = ducc_home + "/lib/uima-ducc-cli.jar"; + String duccClasspath = ducc_home + "/lib/uima-ducc-cli.jar:" + ducc_home + "/lib/uima-ducc-common-2.0.0-SNAPSHOT.jar:" + ducc_home + "/lib/uima-ducc-transport-2.0.0-SNAPSHOT.jar"; if (classpath_user_first) { classpath = classpath + File.pathSeparatorChar + duccClasspath; } else { Added: 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=1634635&view=auto ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ATestDriver.java (added) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ATestDriver.java Mon Oct 27 18:21:39 2014 @@ -0,0 +1,139 @@ +/* + * 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.uima.ducc.cli.test; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +/** + * Abstract test driver base for CLI tests + */ +public abstract class ATestDriver +{ + + List<String> failReasons = new ArrayList<String>(); + List<String> successReasons = new ArrayList<String>(); + + public ATestDriver() + { + } + + String join(String testid, Object ... toks) + { + StringBuffer sb = new StringBuffer(); + sb.append(testid); + sb.append(" -"); + for ( Object s : toks ) { + sb.append(" "); + sb.append(s.toString()); + } + return sb.toString(); + } + + /** + * Update running log, and save result for summary. + * + * Failure throws, to allow driver ability to easily abort if needed. + * + */ + void abort(String testid, Object ... reason) + throws FailedTestException + { + failReasons.add(join(testid, reason)); + throw new FailedTestException(join(testid, reason)); + } + + /** + * Update running log, and save result for summary. + * + * Don't abort so caller can continue. + * + */ + void fail(String testid, Object ... reason) + { + failReasons.add(join(testid, reason)); + System.out.println(join(testid, reason)); + } + + /** + * Create running log and save result for summary. + */ + void success(String testid, Object ... reason) + { + successReasons.add(join(testid, reason)); + System.out.println(join(testid, reason)); + } + + // + // Return the number of tests to run + // + public abstract String[] testsToRun(); + + + /** + * Here define each of your tests thus: + * public void runTestN() + * { + * } + * for each test 1 to N. Implement ntests() to return the number of tests + * to run, 1 through N. See TestCommandLine.java for a simple example. + */ + void runTests() + { + try { + + String[] testset = testsToRun(); + for ( String t : testset ) { // having too much fun with reflection + System.out.println(" -------------- START -------------------- " + t + " ---------- START ------------"); + + Method m = getClass().getDeclaredMethod("test" + t, String.class); + m.invoke(this, t); + + System.out.println(" -------------- END ---------------------- " + t + " ---------- END --------------"); + System.out.println(" "); + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("Test summary: successes[" + successReasons.size() + "] " + "failures[" + failReasons.size() + "]"); + System.out.println("Tests passed:"); + if ( successReasons.size() > 0 ) { + for (String s : successReasons) { + System.out.println(" " + s); + } + } else { + System.out.println(" None."); + } + + System.out.println("Tests failed:"); + if ( failReasons.size() > 0 ) { + for (String s : failReasons) { + System.out.println(" " + s); + } + } else { + System.out.println(" None."); + } + + } + +} Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ManagedReserveAndCancel.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ManagedReserveAndCancel.java?rev=1634635&r1=1634634&r2=1634635&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ManagedReserveAndCancel.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ManagedReserveAndCancel.java Mon Oct 27 18:21:39 2014 @@ -26,100 +26,134 @@ import org.apache.uima.ducc.cli.DuccMana import org.apache.uima.ducc.cli.IDuccCallback; public class ManagedReserveAndCancel + extends ATestDriver { - public static void main(String[] args) + ManagedReserveAndCancel() + { + + } + + public String[] testsToRun() + { + return new String[] { + "ReserveSleep", + "ReserveAndCancel", + "AttachConsole", + "WaitForCompletion", + "Callback", + }; + } + + void testReserveSleep(String testid) + throws Exception + { + Properties reserve_props = new Properties(); + DuccManagedReservationSubmit reserve; + + reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid); + reserve_props.setProperty("process_memory_size", "4"); + reserve_props.setProperty("process_executable", "/bin/sleep"); + reserve_props.setProperty("process_executable_args", "5"); + reserve_props.setProperty("scheduling_class", "fixed"); + + + + reserve = new DuccManagedReservationSubmit(reserve_props); + if ( reserve.execute() ) { + success(testid, "Managed reservation", ""+reserve.getDuccId(), "submitted successfully, rc", ""+reserve.getReturnCode()); + } else { + fail(testid, "Managed reservation submit failed, rc", ""+reserve.getReturnCode()); + } + } + + void testReserveAndCancel(String testid) + throws Exception + { + Properties reserve_props = new Properties(); + DuccManagedReservationSubmit reserve; + + reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid); + reserve_props.setProperty("process_executable_args", "30"); + reserve = new DuccManagedReservationSubmit(reserve_props); + if ( reserve.execute() ) { + success(testid, "Managed reservation", ""+reserve.getDuccId(), "submitted successfully, rc =" + reserve.getReturnCode()); + } else { + fail(testid, "Managed reservation submit failed, rc = " + reserve.getReturnCode()); + } + + Thread.sleep(10000); + Properties cancel_props = new Properties(); + cancel_props.setProperty("id", ""+reserve.getDuccId()); + DuccManagedReservationCancel cancel = new DuccManagedReservationCancel(cancel_props); + if ( cancel.execute() ) { + success(testid, "Reservation", cancel.getDuccId(), "cancelled, rc =", reserve.getReturnCode(), cancel.getResponseMessage()); + } else { + fail(testid, "Reservation", "cancel failed, rc =", reserve.getReturnCode(), cancel.getResponseMessage()); + } + } + + void testAttachConsole(String testid) + throws Exception + { + Properties reserve_props = new Properties(); + DuccManagedReservationSubmit reserve; + + reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid); + reserve_props.setProperty("process_executable", "/bin/ls"); + reserve_props.setProperty("process_executable_args", "-atl ${HOME}"); + reserve_props.setProperty("attach_console", "true"); + reserve = new DuccManagedReservationSubmit(reserve_props); + if ( reserve.execute() ) { + success(testid, "Managed reservation", reserve.getDuccId(), "submitted successfully, rc =", reserve.getReturnCode()); + } else { + fail(testid, "Managed reservation submit failed, rc = ", reserve.getReturnCode()); + } + } + + void testWaitForCompletion(String testid) + throws Exception { + Properties reserve_props = new Properties(); + DuccManagedReservationSubmit reserve; - try { - Properties reserve_props = new Properties(); - int testid = 1; - reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid++); - reserve_props.setProperty("process_memory_size", "4"); - reserve_props.setProperty("process_executable", "/bin/sleep"); - reserve_props.setProperty("process_executable_args", "5"); - reserve_props.setProperty("scheduling_class", "fixed"); - - DuccManagedReservationSubmit reserve; - - - System.out.println("------------------------------ Managed Reservation Sleep Normal ------------------------------"); - reserve = new DuccManagedReservationSubmit(reserve_props); - if ( reserve.execute() ) { - System.out.println("Managed reservation " + reserve.getDuccId() + " submitted successfully, rc =" + reserve.getReturnCode()); - } else { - System.out.println("Managed reservation submit failed, rc = " + reserve.getReturnCode()); - } - - System.out.println("------------------------------ Managed Reservation Sleep and Cancel ------------------------------"); - reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid++); - reserve_props.setProperty("process_executable_args", "30"); - reserve = new DuccManagedReservationSubmit(reserve_props); - if ( reserve.execute() ) { - System.out.println("Managed reservation " + reserve.getDuccId() + " submitted successfully, rc =" + reserve.getReturnCode()); - } else { - System.out.println("Managed reservation submit failed, rc = " + reserve.getReturnCode()); - } - - Thread.sleep(10000); - Properties cancel_props = new Properties(); - cancel_props.setProperty("id", ""+reserve.getDuccId()); - DuccManagedReservationCancel cancel = new DuccManagedReservationCancel(cancel_props); - if ( cancel.execute() ) { - System.out.println("Reservation " + cancel.getDuccId() + " cancelled, rc = " + reserve.getReturnCode() + " " + cancel.getResponseMessage()); - } else { - System.out.println("Reservation " + cancel.getDuccId() + " cancel failed, rc = " + reserve.getReturnCode() + " " + cancel.getResponseMessage()); - } - - System.out.println("------------------------------ Managed Reservation ls with Attached Console ------------------------------"); - reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid++); - reserve_props.setProperty("process_executable", "/bin/ls"); - reserve_props.setProperty("process_executable_args", "-atl ${HOME}*"); - reserve_props.setProperty("attach_console", "true"); - reserve = new DuccManagedReservationSubmit(reserve_props); - if ( reserve.execute() ) { - System.out.println("Managed reservation " + reserve.getDuccId() + " submitted successfully, rc =" + reserve.getReturnCode()); - } else { - System.out.println("Managed reservation submit failed, rc = " + reserve.getReturnCode()); - } - - - System.out.println("------------------------------ Managed Reservation ls Wait For Completion ------------------------------"); - reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid++); - reserve_props.setProperty("process_executable", "/bin/ls"); - reserve_props.setProperty("process_executable_args", "-atl ${HOME}"); - reserve_props.setProperty("attach_console", "true"); - reserve_props.setProperty("wait_for_completion", "true"); - reserve = new DuccManagedReservationSubmit(reserve_props); - if ( reserve.execute() ) { - System.out.println("Managed reservation " + reserve.getDuccId() + " submitted successfully, rc =" + reserve.getReturnCode()); - } else { - System.out.println("Managed reservation submit failed, rc = " + reserve.getReturnCode()); - } - - System.out.println("------------------------------ Managed Reservation ls With Callback ------------------------------"); - MyCallback cb = new MyCallback(); - reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid++); - reserve_props.setProperty("process_executable", "/bin/ls"); - reserve_props.setProperty("process_executable_args", "-atl ${HOME}"); - reserve_props.setProperty("attach_console", "true"); - reserve_props.setProperty("wait_for_completion", "true"); - reserve = new DuccManagedReservationSubmit(reserve_props, cb); - if ( reserve.execute() ) { - System.out.println("Managed reservation " + reserve.getDuccId() + " submitted successfully, rc =" + reserve.getReturnCode()); - } else { - System.out.println("Managed reservation submit failed, rc = " + reserve.getReturnCode()); - } - - - // Must see this, otherwise something is crashing that we didn't expect - System.out.println("------------------------------ Reservation Test Ends ------------------------------"); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid); + reserve_props.setProperty("process_executable", "/bin/ls"); + reserve_props.setProperty("process_executable_args", "-atl ${HOME}"); + reserve_props.setProperty("attach_console", "true"); + reserve_props.setProperty("wait_for_completion", "true"); + reserve = new DuccManagedReservationSubmit(reserve_props); + if ( reserve.execute() ) { + success("Managed reservation", reserve.getDuccId(), "submitted successfully, rc =", reserve.getReturnCode()); + } else { + fail("Managed reservation submit failed, rc = ", reserve.getReturnCode()); + } + } + + void testCallback(String testid) + throws Exception + { + Properties reserve_props = new Properties(); + DuccManagedReservationSubmit reserve; + + MyCallback cb = new MyCallback(); + reserve_props.setProperty("description", "Managed Reserve And Cancel " + testid); + reserve_props.setProperty("process_executable", "/bin/ls"); + reserve_props.setProperty("process_executable_args", "-atl ${HOME}"); + reserve_props.setProperty("attach_console", "true"); + reserve_props.setProperty("wait_for_completion", "true"); + reserve = new DuccManagedReservationSubmit(reserve_props, cb); + if ( reserve.execute() ) { + success("Managed reservation", reserve.getDuccId(), "submitted successfully, rc =", reserve.getReturnCode()); + } else { + fail("Managed reservation submit failed, rc = ", reserve.getReturnCode()); + } + } + + public static void main(String[] args) + { + ManagedReserveAndCancel tester = new ManagedReserveAndCancel(); + tester.runTests(); } static class MyCallback Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ReserveAndCancel.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ReserveAndCancel.java?rev=1634635&r1=1634634&r2=1634635&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ReserveAndCancel.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ReserveAndCancel.java Mon Oct 27 18:21:39 2014 @@ -23,99 +23,113 @@ import java.util.Properties; import org.apache.uima.ducc.cli.DuccReservationCancel; import org.apache.uima.ducc.cli.DuccReservationSubmit; -import org.apache.uima.ducc.cli.IDuccCallback; public class ReserveAndCancel + extends ATestDriver { - public static void main(String[] args) + String resid = null; + + ReserveAndCancel() { + } - try { - Properties reserve_props = new Properties(); - DuccReservationSubmit reserve; - int testid = 1; - - System.out.println("------------------------------ Reserve Normal ------------------------------"); - reserve_props.setProperty("description", "Reserve And Cancel " + testid++); - reserve_props.setProperty("instance_memory_size", "4"); - reserve_props.setProperty("number_of_instances", "2"); - reserve_props.setProperty("scheduling_class", "fixed"); - reserve = new DuccReservationSubmit(reserve_props); - if ( reserve.execute() ) { - System.out.println("Reservation " + reserve.getDuccId() + " successful, rc =" + reserve.getReturnCode() + ": " + reserve.getHostsAsString()); - String[] hosts = reserve.getHosts(); - System.out.println("" + hosts.length + " hosts assigned"); - if ( hosts.length > 0 ) { - for ( String h : reserve.getHosts() ) { - System.out.println(" " + h); - } - } + // + // establish the tests and the order of execution + // + public String[] testsToRun() + { - } else { - System.out.println("Reservation failed, rc = " + reserve.getReturnCode()); - } - - - Properties cancel_props = new Properties(); - cancel_props.setProperty("id", ""+reserve.getDuccId()); - DuccReservationCancel cancel = new DuccReservationCancel(cancel_props); - if ( cancel.execute() ) { - System.out.println("Reservation " + cancel.getDuccId() + " cancelled, rc = " + reserve.getReturnCode() + " " + cancel.getResponseMessage()); - } else { - System.out.println("Reservation " + cancel.getDuccId() + " cancel failed, rc = " + reserve.getReturnCode() + " " + cancel.getResponseMessage()); - } - - System.out.println("------------------------------ Reserve Fail ------------------------------"); - reserve_props.setProperty("description", "Reserve And Cancel " + testid++); - reserve_props.setProperty("instance_memory_size", "99"); - reserve_props.setProperty("number_of_instances", "99"); - reserve_props.setProperty("scheduling_class", "fixed"); - reserve = new DuccReservationSubmit(reserve_props); - if ( reserve.execute() ) { - System.out.println("Reservation " + reserve.getDuccId() + " successful, rc =" + reserve.getReturnCode() + ": " + reserve.getHostsAsString()); - String[] hosts = reserve.getHosts(); - System.out.println("" + hosts.length + " hosts assigned"); - if ( hosts.length > 0 ) { - for ( String h : reserve.getHosts() ) { - System.out.println(" " + h); - } - } - } else { - System.out.println("Reservation failed, rc = " + reserve.getReturnCode()); - } - - System.out.println("------------------------------ Cancel Fail ------------------------------"); - cancel_props.setProperty("id", "99999999999999"); - cancel = new DuccReservationCancel(cancel_props); - if ( cancel.execute() ) { - System.out.println("Reservation " + cancel.getDuccId() + " cancelled, rc = " + cancel.getReturnCode() + " " + cancel.getResponseMessage()); - } else { - System.out.println("Reservation " + cancel.getDuccId() + " cancel failed, rc = " + cancel.getReturnCode() + " " + cancel.getResponseMessage()); - } - - // Must see this, otherwise something is crashing that we didn't expect - System.out.println("------------------------------ Reservation Test Ends ------------------------------"); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + // if ( true ) return new int[] {5,}; + + return new String[] { + "Reserve", + "Cancel", + "ReserveFail", + "CancelFail", + }; } - static class MyCallback - implements IDuccCallback + void testReserve(String testid) + throws Exception + { + Properties reserve_props = new Properties(); + DuccReservationSubmit reserve; + + reserve_props.setProperty("description", "Reserve And Cancel"); + reserve_props.setProperty("instance_memory_size", "4"); + reserve_props.setProperty("number_of_instances", "2"); + reserve_props.setProperty("scheduling_class", "fixed"); + reserve = new DuccReservationSubmit(reserve_props); + if ( reserve.execute() ) { + resid = "" + reserve.getDuccId(); + success(testid, "Reservation", resid, "successful, rc =", ""+reserve.getReturnCode(), ":", reserve.getHostsAsString()); + String[] hosts = reserve.getHosts(); + System.out.println("" + hosts.length + " hosts assigned"); + if ( hosts.length > 0 ) { + for ( String h : reserve.getHosts() ) { + System.out.println(" " + h); + } + } + } else { + fail(testid, "Reservation failed, rc = " + reserve.getReturnCode()); + } + } + + void testCancel(String testid) + throws Exception { - public void console(int pnum, String msg) - { - System.out.println("---> " + pnum + " " + msg); + Properties cancel_props = new Properties(); + cancel_props.setProperty("id", resid); + DuccReservationCancel cancel = new DuccReservationCancel(cancel_props); + if ( cancel.execute() ) { + success(testid, "Reservation " + ""+cancel.getDuccId() + " cancelled, rc = " + cancel.getReturnCode() + " " + cancel.getResponseMessage()); + } else { + fail(testid, "Reservation " + ""+cancel.getDuccId() + " cancel failed, rc = " + cancel.getReturnCode() + " " + cancel.getResponseMessage()); } + } + + void testReserveFail(String testid) + throws Exception + { + Properties reserve_props = new Properties(); + DuccReservationSubmit reserve = null; + + reserve_props.setProperty("description", "Reserve And Cancel (fail)"); + reserve_props.setProperty("instance_memory_size", "99"); + reserve_props.setProperty("number_of_instances", "99"); + reserve_props.setProperty("scheduling_class", "fixed"); + reserve = new DuccReservationSubmit(reserve_props); + if ( reserve.execute() ) { + fail(testid, "Reservation " +""+ reserve.getDuccId() + " successful but should have failed, rc =" + ""+reserve.getReturnCode() + ": " + reserve.getHostsAsString()); + // designed to fail, if it doesn't we don't care about what is returned + } else { + success(testid, "Reservation failed as expected, rc = " + ""+reserve.getReturnCode()); + } + } + + void testCancelFail(String testid) + throws Exception + { + Properties cancel_props = new Properties(); + DuccReservationCancel cancel = null; - public void status(String msg) - { - System.out.println("---> " +msg); + System.out.println("------------------------------ Cancel Fail ------------------------------"); + cancel_props.setProperty("id", "9999999"); + cancel = new DuccReservationCancel(cancel_props); + if ( cancel.execute() ) { + fail(testid, "Reservation " + ""+cancel.getDuccId() + " cancelled but should have failed, rc = " + ""+cancel.getReturnCode() + " " + cancel.getResponseMessage()); + } else { + success(testid, "Reservation " + ""+cancel.getDuccId() + " cancel failed as expected, rc = " + ""+cancel.getReturnCode() + " " + cancel.getResponseMessage()); } + } + + public static void main(String[] args) + { + ReserveAndCancel tester = new ReserveAndCancel(); + tester.runTests(); + } + } 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=1634635&r1=1634634&r2=1634635&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 Mon Oct 27 18:21:39 2014 @@ -20,6 +20,7 @@ package org.apache.uima.ducc.cli.test; import java.io.FileInputStream; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -55,19 +56,11 @@ public class ServiceTester DuccProperties ducc_properties;; String ducc_home; - // Base props. These run a service from the examples - String[] props = { - "--description", "Test Service 1", - "--process_jvm_args", "-Xmx100M -DdefaultBrokerURL=", // note broken, gets fixed in a while - "--classpath", "${DUCC_HOME}/lib/uima-ducc/examples/*:${DUCC_HOME}/apache-uima/lib/*:${DUCC_HOME}/apache-uima/apache-activemq/lib/*:${DUCC_HOME}/examples/simple/resources/service", - "--service_ping_arguments", "broker-jmx-port=1099", - "--environment", "AE_INIT_TIME=5000 AE_INIT_RANGE=1000 INIT_ERROR=0 LD_LIBRARY_PATH=/yet/a/nother/dumb/path", - "--process_memory_size", "15", - "--process_DD", "${DUCC_HOME}/examples/simple/resources/service/Service_FixedSleep_1.xml", - "--scheduling_class", "fixed", - "--working_directory", "${HOME}", - "--service_linger", "10000", - }; + String testId; + String[] service_props; + String endpoint; + String service_id; + ApiRunner job; List<String> failReasons = new ArrayList<String>(); List<String> successReasons = new ArrayList<String>(); @@ -103,8 +96,6 @@ public class ServiceTester String mkBrokerString(String ducc_home) throws Exception { - ducc_properties = new DuccProperties(); - ducc_properties.load(new FileInputStream(ducc_home + "/resources/ducc.properties")); String proto = ducc_properties.getStringProperty("ducc.broker.protocol"); String host = ducc_properties.getStringProperty("ducc.broker.hostname"); String port = ducc_properties.getStringProperty("ducc.broker.port"); @@ -119,7 +110,7 @@ public class ServiceTester String type = desc.getType().toString(); - sb.append("Service: "); + sb.append("XService: "); sb.append(type); sb.append(":"); sb.append(desc.getEndpoint()); @@ -304,7 +295,8 @@ public class ServiceTester { try { int count = 0; - System.out.println("Waiting for service " + id + " to reach state " + desired_state); + String prev = ""; + System.out.println("Waiting for service " + id + " to reach state " + desired_state + " timeout " + timeout); do { IServiceDescription desc = getServiceDescription(id); if ( desc == null ) { @@ -312,6 +304,7 @@ public class ServiceTester } String state = desc.getServiceState().toString(); + if ( ! state.equals(prev) ) count = 0; if ( state.equals(desired_state) ) return true; @@ -319,14 +312,14 @@ public class ServiceTester System.out.println("Query times out after " + count + " tries."); return false; } - + prev = state; System.out.println(" ... " + state); - Thread.sleep(5000); + try { Thread.sleep(5000); } catch (InterruptedException e ) {} } while ( true ); - } catch (InterruptedException e) { - // I see this if the MR fails early - it interrupts the waiter which is me. - System.out.println("Query failed with sleep interruption."); - return false; +// } catch (InterruptedException e) { +// // I see this if the MR fails early - it interrupts the waiter which is me. +// System.out.println("Query failed with sleep interruption."); +// return false; } catch (Exception e) { System.out.println("Query failed with exception:"); e.printStackTrace(); @@ -486,17 +479,17 @@ public class ServiceTester props.setProperty("process_jvm_args", "-Xmx100M "); props.setProperty("process_thread_count", "2"); props.setProperty("process_per_item_time_max", "5"); - props.setProperty("environment", "AE_INIT_TIME=5 AE_INIT_RANGE=5 INIT_ERROR=0 LD_LIBRARY_PATH=/yet/a/nother/dumb/path"); + props.setProperty("environment", "AE_INIT_TIME=1 AE_INIT_RANGE=1 INIT_ERROR=0"); props.setProperty("process_deployments_max", "999"); props.setProperty("scheduling_class", "normal"); props.setProperty("service_dependency", service_dependency); props.setProperty("description", "Depdendent job for Services Test"); props.setProperty("wait_for_completion", "true"); + props.setProperty("timestamp", "true"); try { submit = new DuccJobSubmit(props, new ApiCallback(this)); - System.out.println("------------------------------ Submit Job for Services Test ------------------------------"); if ( submit.execute() ) { System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); this.id = submit.getDuccId(); @@ -542,8 +535,11 @@ public class ServiceTester int iterations = timeout / sleeptime; int count = 0; + String prev_status = ""; while ( true ) { String status = runner.getStatus(); + if ( !prev_status.equals(status) ) count = 0; // reset count on each state change + // System.out.println("======== wait for completion of " + Arrays.toString(states) + ". Current status:" + status); if ( runner.getStatus() == "Failed" ) return false; for ( String s : states ) { @@ -554,7 +550,8 @@ public class ServiceTester System.out.println("Timeout waiting for state " + Arrays.toString(states) + " for job " + runner.getId()); return false; } - + prev_status = status; + try { Thread.sleep(sleeptime); } catch (InterruptedException e) { @@ -598,7 +595,6 @@ public class ServiceTester boolean stopService(String service_id) { - System.out.println("---------------------------------------- Stop ----------------------------------------"); DuccServiceApi api = new DuccServiceApi(null); try { IServiceReply reply = api.stop(new String[] {"--stop", "" + service_id}); @@ -619,7 +615,6 @@ public class ServiceTester boolean modifyService(String service_id, String k, String v) { - System.out.println("---------------------------------------- Modify ----------------------------------------"); DuccServiceApi api = new DuccServiceApi(null); try { IServiceReply reply = api.modify(new String[] {"--modify", "" + service_id, k, v}); // again, so we can continue @@ -639,7 +634,6 @@ public class ServiceTester boolean enableService(String service_id) { - System.out.println("---------------------------------------- Enable ----------------------------------------"); DuccServiceApi api = new DuccServiceApi(null); try { IServiceReply reply = api.enable(new String[] {"--enable", "" + service_id}); // so disable has an effect @@ -658,7 +652,6 @@ public class ServiceTester boolean ignoreReferences(String service_id) { - System.out.println("---------------------------------------- Ignore References ----------------------------------------"); DuccServiceApi api = new DuccServiceApi(null); try { @@ -679,7 +672,6 @@ public class ServiceTester boolean observeReferences(String service_id) { - System.out.println("---------------------------------------- Observe References ----------------------------------------"); DuccServiceApi api = new DuccServiceApi(null); try { @@ -735,64 +727,50 @@ public class ServiceTester return false; } - - void runTests(String testId, String[] service_props) + void testRegister(String subtestId) throws Exception { - //x - register an MR as some anonymous remore service - //x - register a ping-only guy to ping him - //x - wait for Available - //x - stop the pinger - // - start the pinger and wait for available - // - stop the pinger - // - modify the registration to autorun - // - enable the pinger and wait for available - // - stop the pinger and wait for stopped - // - enable the pinger and wait for available - // - cancel the MR service - // - after stopping the service we want to see the pinger go to waiting - // - unregister the pinger - // - stop the MR - - String subtestId; - String endpoint; - ApiRunner job; - - - System.out.println(testId + " ---------------------------------------- Register ------------------------------"); - String service_id = registerService(service_props); + service_id = registerService(service_props); if ( service_id == null ) { - fail(testId, "<init>", "Service test failed: can't register service."); + fail(testId, subtestId, "Service test failed: can't register service."); } - success(testId, "<init>", "Service is registered for manual start."); + success(testId, subtestId, "Service is registered for manual start."); endpoint = getEndpoint(service_id); // should be comon throughout the tests + } - subtestId = "Basic function"; - System.out.println(testId + "---------------------------------------- Manual Start ------------------------------"); + void testManualStart(String subtestId) + throws Exception + { if ( startService(service_id) ) { // first start after registration success(testId, subtestId, "Manual service start issued."); } else { fail(testId, subtestId, "Manual service start failed."); } - if ( waitForState("Available", service_id) ) { + if ( waitForState("Available", service_id, 120000) ) { success(testId, subtestId, "Service is manually started."); } else { - fail(testId, subtestId, "State Available timeout, state did not occur manually starting pinger."); + fail(testId, subtestId, "State Available timeout, state did not occur manually starting pinger for service " + service_id); } + } - System.out.println(testId + "---------------------------------------- Manual Stop ------------------------------"); + void testManualStop(String subtestId, String reason) + throws Exception + { if ( stopService(service_id) ) { - success(testId, subtestId, "Manual service stop issued."); + success(testId, subtestId, "Manual service stop issued - " + reason); } else { - fail(testId, subtestId, "Manual service stop failed."); + fail(testId, subtestId, "Manual service stop failed - " + reason); } if ( waitForState("Stopped", service_id) ) { - success(testId, subtestId, "Service is manually stopped"); + success(testId, subtestId, "Service is manually stopped - " + reason); } else { - fail(testId, subtestId, "State Stopped timeout, state did not occur manually stopping pinger."); + fail(testId, subtestId, "Service did not reach Stopped state - " + reason); } - - System.out.println(testId + "---------------------------------------- Manual Restart ------------------------------"); + } + + void testManualRestart(String subtestId) + throws Exception + { if ( startService(service_id)) { //r restart, verifies the previous stop cleaned up ok in SM success(testId, subtestId, "Second Manual service start issued."); } else { @@ -803,33 +781,26 @@ public class ServiceTester } else { fail(testId, subtestId, "State Stopped timeout, state did not occur manually restarting pinger."); } - - - System.out.println(testId + "---------------------------------------- Manual Stop, prep for Autostart tests ------------------------------"); - if ( stopService(service_id)) { - success(testId, subtestId, "Manual service stop issued in preparation for autostart tests."); - } else { - fail(testId, subtestId, "Manual service stop failed preparing for autostart tests."); - } - if ( waitForState("Stopped", service_id) ) { - success(testId, subtestId, "Service is manually is stopped in preparation for autostart tests."); - } else { - fail(testId, subtestId, "State Stopped timeout, state did not occur manually stopping pinger in preparation for autostart tests."); - } + } - System.out.println(testId + "---------------------------------------- Modify autostart=true ------------------------------"); + void testModifyAutostartTrue(String subtestId) + throws Exception + { if ( modifyService(service_id, "--autostart", "true")) { // switch to autostart success(testId, subtestId, "Modify --autostart=true issued."); } else { fail(testId, subtestId, "Modify --autostart=true failed."); } if ( waitForStartState("autostart", service_id) ) { - success(testId, subtestId, "Service is modified for autostart, waiting for it to start."); + success(testId, subtestId, "Service is modified for autostart."); } else { fail(testId, subtestId, "Service modify for --autostart failed."); } - - System.out.println(testId + "---------------------------------------- Enable and wait to become Available ------------------------------"); + } + + void testEnableFromAutostart(String subtestId) + throws Exception + { if ( enableService(service_id) ) { // let it enable out of autostart success(testId, subtestId, "Enable issued to stopped/autostart service."); } else { @@ -840,32 +811,11 @@ public class ServiceTester } else { fail(testId, subtestId, "Service failed to start after autostart is enacled."); } + } - System.out.println(testId + "---------------------------------------- Stop autostarted service ------------------------------"); - if ( stopService(service_id) ) { // once more, make sure it will stop out of autostart - success(testId, subtestId, "Second stop issued to autostarted service."); - } else { - fail(testId, subtestId, "Second stop to autostarted service failed."); - } - if ( waitForState("Stopped", service_id) ) { - success(testId, subtestId, "Service is stopped from autostart mode. Reenabling ..."); - } else { - fail(testId, subtestId, "State Stopped timeout, did not reach stop start after stop from autostart."); - } - - System.out.println(testId + "---------------------------------------- Re-enable autostarted service and wait for Available ------------------------------"); - if ( enableService(service_id) ) { // once more, make sure it will restart out of autostart - success(testId, subtestId, "Second enable issued to autostarted service."); - } else { - fail(testId, subtestId, "Second enable to autostarted service failed."); - } - if ( waitForState("Available", service_id) ) { - success(testId, subtestId, "Service is enabled and running after stop from autostart."); - } else { - fail(testId, subtestId, "Service did not restart after enable from autostart."); - } - - System.out.println(testId + "---------------------------------------- Modify autostart=false ------------------------------"); + void testModifyAutostartFalse(String subtestId) + throws Exception + { if ( modifyService(service_id, "--autostart", "false")) { success(testId, subtestId, "Modify --autostart=false issued."); } else { @@ -875,21 +825,13 @@ public class ServiceTester success(testId, subtestId, "Service is in manual start mode"); } else { fail(testId, subtestId, "Service modify for --autostart=false failed."); + } + } - System.out.println(testId + "---------------------------------------- Manual Stop, prep for Reference tests ------------------------------"); - if ( stopService(service_id) ) { - success(testId, subtestId, "Manual service stop issued in prep for reference tests"); - } else { - fail(testId, subtestId, "Manual service stop failed, prep for reference tests"); - } - if ( waitForState("Stopped", service_id) ) { - success(testId, subtestId, "Service is manually stopped, prep for reference tests."); - } else { - fail(testId, subtestId, "State Stopped timeout, state did not occur manually stopping in prep for reference tests"); - } - - System.out.println(testId + "---------------------------------------- Enable in prep for reference tests ------------------------------"); + void testEnableFromManual(String subtestId) + throws Exception + { if ( enableService(service_id) ) { // let it enable out of autostart success(testId, subtestId, "Enable issued to stopped service, prep for reference tests"); } else { @@ -900,16 +842,18 @@ public class ServiceTester } else { fail(testId, subtestId, "Service did not reach stopped mode in prep for reference tests."); } + } - subtestId = "Reference test 1"; - System.out.println(testId + "---------------------------------------- " + subtestId + " ------------------------------"); + void testReferenceStart_1(String subtestId) + throws Exception + { + // not a test perse, but convenient to run as one System.out.println(testId + " Reference <--> Manual start mode -------"); System.out.println(testId + " Start with reference start, then ignore references, service should not exit. -------"); System.out.println(testId + " Then observe references, service should exit. -------"); - System.out.println(testId + "---------------------------------------- Reference Start Test 1 ------------------------------"); - job = startJob(endpoint); - if ( waitForJobState(job, new String[] {"Failed", "WaitingForResources", "Assigned", "Initializing", "Running"}, 30000) ) { + job = startJob(endpoint); + if ( waitForJobState(job, new String[] {"Failed", "WaitingForServices", "WaitingForResources", "Assigned", "Initializing", "Running"}, 60000) ) { success(testId, subtestId, "Dependent job " + job.getId() + " submitted."); } else { fail(testId, subtestId, "Could not start dependent job."); @@ -928,6 +872,14 @@ public class ServiceTester fail(testId, subtestId, "Service did not reference start."); } + // Wait for job to actually start + if ( waitForJobState(job, new String[] {"Running"}, 60000) ) { + success(testId, subtestId, "Job " + job.getId() + " is started."); + } else { + fail(testId, subtestId, "Job " + job.getId() + " did not start within a reasonable time."); + } + + // Now ignore refs and make sure SM agrees if ( ignoreReferences(endpoint) ) { success(testId, subtestId, "Ignore references."); } else { @@ -938,10 +890,12 @@ public class ServiceTester } else { fail(testId, subtestId, "Service could not switch to manual.."); } - + + // Now wait for job to go away waitForJobState(job, new String[] {"Completed", "Failed", "completion"}, -1); System.out.println("Job " + job.getId() + " has exited."); + // Now wait for linger stop which should not happen System.out.println("--- Waiting for service to linger stop, which we expect to fail as we should be in manual state ---"); if ( !waitForState("Stopped", service_id, default_timeout ) ) { success(testId, subtestId, "Service correctly did not linger-stop"); @@ -965,14 +919,16 @@ public class ServiceTester } else { fail(testId, subtestId, "Linger-stop service did not exit."); } + } + + void testReferenceStart_2(String subtestId) + throws Exception + { - subtestId = "Reference test 2"; - System.out.println(testId + "---------------------------------------- " + subtestId + " ------------------------------"); System.out.println(testId + " Autostart -> reference -------"); System.out.println(testId + " Set service to autostart, then submit job. When the job starts switch to -------"); System.out.println(testId + " reference start. When the job exits the service should also exit within its -------"); System.out.println(testId + " linger time. -------"); - System.out.println(testId + "---------------------------------------- Reference Start Test 2 ------------------------------"); // the previous test should leave the service linger-stopped so simply changing the registration shoul dstart it System.out.println(subtestId + ": Switching service to autostart."); @@ -992,7 +948,7 @@ public class ServiceTester // get the job into running state System.out.println(subtestId + ": Starting a job."); job = startJob(endpoint); - if ( waitForJobState(job, new String[] {"Running"}, 30000) ) { + if ( waitForJobState(job, new String[] {"Running"}, 60000) ) { success(testId, subtestId, "Dependent job " + job.getId() + " submitted."); } else { fail(testId, subtestId, "Could not start dependent job."); @@ -1027,7 +983,7 @@ public class ServiceTester System.out.println(subtestId + ": Waiting for job to complete."); - if ( waitForJobState(job, new String[] {"Completed", "Failed"}, 30000) ) { + if ( waitForJobState(job, new String[] {"Completed", "Failed"}, 60000) ) { success(testId, subtestId, "Dependent job " + job.getId() + " completed."); } else { fail(testId, subtestId, "Dependend job did not complete as expected."); @@ -1041,22 +997,19 @@ public class ServiceTester fail(testId, subtestId, "Service did not linger-stop"); } + } + void testReferenceStart_3(String subtestId) + throws Exception + { subtestId = "Reference test 3"; - System.out.println(testId + "---------------------------------------- " + subtestId + " ------------------------------"); System.out.println(testId + " Reference -> Autostart -------"); System.out.println(testId + " Let service reference start, then set to autostart. Service should not exit -------"); System.out.println(testId + " once the job completes. -------"); - System.out.println(testId + "---------------------------------------- Reference Start Test 2 ------------------------------"); // get the job into running state System.out.println(subtestId + ": Starting a job."); job = startJob(endpoint); - if ( waitForJobState(job, new String[] {"Running"}, 30000) ) { - success(testId, subtestId, "Dependent job " + job.getId() + " submitted."); - } else { - fail(testId, subtestId, "Could not start dependent job."); - } System.out.println("Waiting for service to acknowledge reference start."); if ( waitForStartState("reference", service_id) ) { @@ -1067,9 +1020,16 @@ public class ServiceTester System.out.println(subtestId + ": Waiting for service to become fully available."); if ( waitForState("Available", service_id, default_timeout) ) { - success(testId, subtestId, "Service is autostarted."); + success(testId, subtestId, "Service is reference started."); } else { - fail(testId, subtestId, "Service did not autostart."); + fail(testId, subtestId, "Service did not start correctly."); + } + + System.out.println(subtestId + ": Waiting for job to start."); + if ( waitForJobState(job, new String[] {"Running"}, 60000) ) { + success(testId, subtestId, "Dependent job " + job.getId() + " submitted."); + } else { + fail(testId, subtestId, "Could not start dependent job."); } System.out.println(subtestId + ": Switching service to autostart."); @@ -1079,8 +1039,15 @@ public class ServiceTester fail(testId, subtestId, "Modify --autostart=true failed."); } + System.out.println(subtestId + ": Wait for autostart modify to complete.."); + if ( waitForStartState("autostart", service_id) ) { + success(testId, subtestId, "Service switched to autostart."); + } else { + fail(testId, subtestId, "Service could not switch to autostart.."); + } + System.out.println(subtestId + ": Waiting for job to complete."); - if ( waitForJobState(job, new String[] {"Completed", "Failed"}, 30000) ) { + if ( waitForJobState(job, new String[] {"Completed", "Failed"}, 60000) ) { success(testId, subtestId, "Dependent job " + job.getId() + " completed."); } else { fail(testId, subtestId, "Dependend job did not complete as expected."); @@ -1093,13 +1060,129 @@ public class ServiceTester } else { success(testId, subtestId, "Service correctly did not stop"); } + } + void testUnregister(String subtestId) + throws Exception + { if ( unregisterService(service_id) ) { // finish the test success(testId, "<complete>", "Unregister issued."); } else { fail(testId, "<complete>", "Unregister failed."); } + } + + void runTestSet(String[] testset) + throws Exception + { + for ( int i = 0; i < testset.length; i++ ) { + String sti = testset[i]; + + + System.out.println(testId + " -------------- START -------------------- " + sti + " ---------- START ------------"); + if ( sti.equals("ManualStop") ) { + // stop happens for a lot of reasons, so we include a reason string + Method m = getClass().getDeclaredMethod("test" + sti, String.class, String.class); + String reason = testset[++i]; + m.invoke(this, new Object[] {sti, reason} ); + } else { + try { + Method m = getClass().getDeclaredMethod("test" + sti, String.class); + m.invoke(this, new Object[] {sti,} ); + } catch ( Exception e ) { + Throwable cause = e.getCause(); + System.out.println(cause.toString()); + cause.printStackTrace(); + } + } + System.out.println(testId + " -------------- END ---------------------- " + sti + " ---------- END --------------"); + System.out.println(" "); + } + } + + + void runTests(String testId, String[] service_props) + throws Exception + { + //x - register an MR as some anonymous remore service + //x - register a ping-only guy to ping him + //x - wait for Available + //x - stop the pinger + // - start the pinger and wait for available + // - stop the pinger + // - modify the registration to autorun + // - enable the pinger and wait for available + // - stop the pinger and wait for stopped + // - enable the pinger and wait for available + // - cancel the MR service + // - after stopping the service we want to see the pinger go to waiting + // - unregister the pinger + // - stop the MR + + // + // We run these complext tests in groups to make debug easier + // + + // + // Generic register, to initialize things + String[] testset0 = { + "Register" , + }; + + // + // Basic function + // + String[] testset1 = { + "ManualStart", + "ManualStop", "Basic test", // all ManualStop must include a reason string as well + "ManualRestart", + "ManualStop", "Prep for autostart tests", + "ModifyAutostartTrue", + "EnableFromAutostart", + "ManualStop", "Stop autostarted service.", + "EnableFromAutostart", // we do this again to make sure state didn't get messed up so far + "ModifyAutostartFalse", // go into manual + "ManualStop", "Prep for reference tests", // stopt the service + "EnableFromManual", // make it startable + }; + + // + // Reference start, manual <--> reference + // + String[] testset2 = { + "ReferenceStart_1", + }; + + // + // Reference start, autostart ---> reference + // + String[] testset3 = { + "ReferenceStart_2", + }; + + // + // Reference start, reference ---> autostart + // + String[] testset4 = { + "ReferenceStart_3", + }; + + // + // Generic unregister to finish up + // + String[] testset99 = { + "Unregister", + }; + + this.testId = testId; + this.service_props = service_props; + runTestSet(testset0); + runTestSet(testset1); + runTestSet(testset2); + runTestSet(testset3); + runTestSet(testset4); + runTestSet(testset99); } @@ -1107,6 +1190,7 @@ public class ServiceTester throws Exception { String testId = "Ping-Only"; + if ( startMr() ) { // hangs until it's running success(testId, "<init MR>", "Ping-only service test: anonymous service started as MR."); } else { @@ -1174,6 +1258,8 @@ public class ServiceTester if ( ducc_home == null ) { throw new IllegalArgumentException("DUCC_HOME must be set into system properties."); } + ducc_properties = new DuccProperties(); + ducc_properties.load(new FileInputStream(ducc_home + "/resources/ducc.properties")); // start by clearing all registrations owned by me @@ -1196,23 +1282,23 @@ public class ServiceTester } // - // Do "normal" tests + // Do ping-only tests // try { - runNormal(); + runPingOnly(); } catch ( Exception e ) { - System.out.println("Normal test failed."); + System.out.println("Ping-only test failed: " + e.toString()); } - // - // Do ping-only tests + // Do "normal" tests // try { - runPingOnly(); + runNormal(); } catch ( Exception e ) { - System.out.println("Ping-only test failed."); + System.out.println("Normal test failed:" + e.toString()); } + } Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/SubmitAndCancel.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/SubmitAndCancel.java?rev=1634635&r1=1634634&r2=1634635&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/SubmitAndCancel.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/SubmitAndCancel.java Mon Oct 27 18:21:39 2014 @@ -19,6 +19,7 @@ package org.apache.uima.ducc.cli.test; import java.util.ArrayList; +import java.util.List; import java.util.Properties; import org.apache.uima.ducc.cli.DuccJobCancel; @@ -26,9 +27,66 @@ import org.apache.uima.ducc.cli.DuccJobS import org.apache.uima.ducc.cli.IDuccCallback; public class SubmitAndCancel + extends ATestDriver { - static Properties mkproperties(String[] args) + String[] submit_args = new String[] { + "--driver_descriptor_CR", "org.apache.uima.ducc.test.randomsleep.FixedSleepCR", + "--driver_descriptor_CR_overrides", "jobfile=${DUCC_HOME}/examples/simple/1.inputs compression=10 error_rate=0.0", + "--driver_jvm_args", "-Xmx500M", + + "--process_descriptor_AE", "org.apache.uima.ducc.test.randomsleep.FixedSleepAE", + "--process_memory_size", "2", + "--classpath", "${DUCC_HOME}/lib/uima-ducc/examples/*", + "--process_jvm_args", "-Xmx100M ", + "--process_thread_count", "2", + "--process_per_item_time_max", "5", + "--environment", "AE_INIT_TIME=5 AE_INIT_RANGE=5 INIT_ERROR=0 LD_LIBRARY_PATH=/yet/a/nother/dumb/path", + "--process_deployments_max", "999", + + "--scheduling_class", "normal", + }; + List<String> failReasons = new ArrayList<String>(); + List<String> successReasons = new ArrayList<String>(); + + SubmitAndCancel() + { + } + + // + // establish the tests and the order of execution + // + public String[] testsToRun() + { + + // if ( true ) return new int[] {5,}; + + return new String[] { + "Submit", + "SubmitAndCancel", + "WaitForCompletion", + "AttachConsole", + "ServiceDependency", + "AllInOneLocal", + "AllInOneRemote", + "AllInOneBogus", + }; + } + + // void fail(String testid, String reason) + // throws FailedTestException + // { + // failReasons.add(testid + " - " + reason); + // System.out.println(testid + " - test failed: " + reason); + // } + + // void success(String testid, String reason) + // { + // successReasons.add(testid + " - " + reason); + // System.out.println(testid + " - test passed: " + reason); + // } + + Properties mkproperties(String[] args) { Properties props = new Properties(); if ( args.length % 2 != 0 ) { @@ -43,188 +101,216 @@ public class SubmitAndCancel return props; } - public static void main(String[] args) + void testSubmit(String testid) + throws Exception { - String[] submit_args = new String[] { - "--driver_descriptor_CR", "org.apache.uima.ducc.test.randomsleep.FixedSleepCR", - "--driver_descriptor_CR_overrides", "jobfile=${DUCC_HOME}/examples/simple/1.inputs compression=10 error_rate=0.0", - "--driver_jvm_args", "-Xmx500M", - - "--process_descriptor_AE", "org.apache.uima.ducc.test.randomsleep.FixedSleepAE", - "--process_memory_size", "2", - "--classpath", "${DUCC_HOME}/lib/uima-ducc/examples/*", - "--process_jvm_args", "-Xmx100M ", - "--process_thread_count", "2", - "--process_per_item_time_max", "5", - "--environment", "AE_INIT_TIME=5 AE_INIT_RANGE=5 INIT_ERROR=0 LD_LIBRARY_PATH=/yet/a/nother/dumb/path", - "--process_deployments_max", "999", - - "--scheduling_class", "normal", - }; + IDuccCallback cb = new MyCallback(); + DuccJobSubmit submit; - try { - IDuccCallback cb = new MyCallback(); - DuccJobSubmit submit; + submit = new DuccJobSubmit(submit_args, (IDuccCallback) cb); + submit.setProperty("description", "Submit-And-Cancel job 1"); + System.out.println(testid + " ------------------------------ Submit with a callback ------------------------------"); + System.out.println(testid + " Console attached: " + submit.isConsoleAttached()); + if ( submit.execute() ) { + success(testid, "Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); + } else { + fail(testid, "Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); + return; + } + } - - submit = new DuccJobSubmit(submit_args, (IDuccCallback) cb); - submit.setProperty("description", "Submit-And-Cancel job 1"); - System.out.println("------------------------------ Submit with a callback ------------------------------"); - System.out.println("Console attached: " + submit.isConsoleAttached()); - if ( submit.execute() ) { - System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); - return; - } + void testSubmitAndCancel(String testid) + throws Exception + { + DuccJobSubmit submit; - submit = new DuccJobSubmit(submit_args); - submit.setProperty("description", "Submit-And-Cancel job 2"); - System.out.println("------------------------------ Submit normal ------------------------------"); - System.out.println("Console attached: " + submit.isConsoleAttached()); - if ( submit.execute() ) { - System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); - return; + submit = new DuccJobSubmit(submit_args); + submit.setProperty("description", "Submit-And-Cancel job 2"); + System.out.println(testid + " ------------------------------ Submit normal ------------------------------"); + System.out.println(testid + "Console attached: " + submit.isConsoleAttached()); + if ( submit.execute() ) { + success(testid, "Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); + } else { + fail(testid, "Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); + return; + } + + Thread.sleep(10000); + + DuccJobCancel cancel = new DuccJobCancel( + new String[] { + "--id", "" + submit.getDuccId(), } + ); + + System.out.println(testid + "------------------------------ Cancel first job quickly ------------------------------"); + if ( cancel.execute() ) { + success(testid, "Job " + submit.getDuccId() + " canceled, rc = " + cancel.getReturnCode()); + } else { + fail(testid, "Job " + submit.getDuccId() + " cancel failed, rc = " + cancel.getReturnCode()); + } + + } - Thread.sleep(10000); - - DuccJobCancel cancel = new DuccJobCancel( - new String[] { - "--id", "" + submit.getDuccId(), - } - ); - - System.out.println("------------------------------ Cancel first job quickly ------------------------------"); - if ( cancel.execute() ) { - System.out.println("Job " + submit.getDuccId() + " canceled, rc = " + cancel.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " cancel failed, rc = " + cancel.getReturnCode()); - } + void testWaitForCompletion(String testid) + throws Exception + { + IDuccCallback cb = new MyCallback(); + DuccJobSubmit submit; - cb = new MyCallback(); // insert a callback because the earlier one just tested the constructor - // this time the callback will actually get called from the monitor - submit = new DuccJobSubmit(submit_args, (IDuccCallback) cb); - submit.setProperty("wait_for_completion", "true"); - submit.setProperty("description", "Submit-And-Cancel job 3"); - System.out.println("------------------------------ Submit and wait for completion ------------------------------"); - if ( submit.execute() ) { - System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); - return; - } + cb = new MyCallback(); // insert a callback because the earlier one just tested the constructor + // this time the callback will actually get called from the monitor + submit = new DuccJobSubmit(submit_args, (IDuccCallback) cb); + submit.setProperty("wait_for_completion", "true"); + submit.setProperty("description", "Submit-And-Cancel job 3"); + System.out.println(testid + " ------------------------------ Submit and wait for completion ------------------------------"); + if ( submit.execute() ) { + success(testid, "Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); + } else { + fail(testid, "Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); + } + } - // setProperty is broken for many things including attach_console. Copy the parms to a list and add - // attach console. - ArrayList<String> arglist = new ArrayList<String>(); // test ArrayList constructor - for ( String s : submit_args ) { - arglist.add(s); - } - arglist.add("--attach_console"); - arglist.add("--description"); - arglist.add("Submit-And-Cancel job 4"); + void testAttachConsole(String testid) + throws Exception + { + DuccJobSubmit submit; + // setProperty is broken for many things including attach_console. Copy the parms to a list and add + // attach console. + ArrayList<String> arglist = new ArrayList<String>(); // test ArrayList constructor + for ( String s : submit_args ) { + arglist.add(s); + } + arglist.add("--attach_console"); + arglist.add("--description"); + arglist.add("Submit-And-Cancel job 4"); - submit = new DuccJobSubmit(arglist); - System.out.println("------------------------------ Submit with attached console ------------------------------"); - System.out.println("Console attached: " + submit.isConsoleAttached()); - if ( submit.execute() ) { - System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); - return; - } + submit = new DuccJobSubmit(arglist); + System.out.println(testid + " ------------------------------ Submit with attached console ------------------------------"); + System.out.println(testid + " Console attached: " + submit.isConsoleAttached()); + if ( submit.execute() ) { + success(testid, "Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); + } else { + fail(testid, "Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); + } + } - System.out.println("------------------------------ Submit with service dependency ------------------------------"); - System.out.println(" ------ The job may fail if the service isn't registered -- that is OK ------------------"); - Properties props = mkproperties(submit_args); // test the constructor, plus easier to update - props.setProperty("service_dependency", "UIMA-AS:FixedSleepAE_1:tcp://localhost:61617"); - props.setProperty("wait_for_completion", "true"); - cb = new MyCallback(); // why not, lets go nuts - submit = new DuccJobSubmit(props, (IDuccCallback) cb); + void testServiceDependency(String testid) + throws Exception + { + IDuccCallback cb = new MyCallback(); + DuccJobSubmit submit; + System.out.println(testid + " ------------------------------ Submit with service dependency ------------------------------"); + System.out.println(testid + " ------ The job may fail if the service isn't registered -- that is OK ------------------"); + Properties props = mkproperties(submit_args); // test the constructor, plus easier to update + props.setProperty("service_dependency", "UIMA-AS:FixedSleepAE_1:tcp://localhost:61617"); + props.setProperty("wait_for_completion", "true"); + + cb = new MyCallback(); // why not, lets go nuts + submit = new DuccJobSubmit(props, (IDuccCallback) cb); + + System.out.println(testid + " Console attached: " + submit.isConsoleAttached()); + if ( submit.execute() ) { + success(testid, "Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); + } else { + fail(testid, "Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); + } - System.out.println("Console attached: " + submit.isConsoleAttached()); - if ( submit.execute() ) { - System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); - return; - } + } - + void testAllInOneLocal(String testid) + throws Exception + { + IDuccCallback cb = new MyCallback(); + DuccJobSubmit submit; - // Now some all-in-one variants - local - arglist = new ArrayList<String>(); - for ( String s : submit_args ) { - arglist.add(s); - } - arglist.add("--all_in_one"); - arglist.add("local"); - arglist.add("--description"); - arglist.add("Submit-And-Cancel job 5"); - - cb = new MyCallback(); // why not, lets go nuts - submit = new DuccJobSubmit(arglist, (IDuccCallback) cb); - System.out.println("------------------------------ Submit all_in_one local ------------------------------"); - System.out.println("Console attached: " + submit.isConsoleAttached()); - if ( submit.execute() ) { - System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); - return; - } + // Now some all-in-one variants - local + ArrayList<String> arglist = new ArrayList<String>(); + for ( String s : submit_args ) { + arglist.add(s); + } + arglist.add("--all_in_one"); + arglist.add("local"); + arglist.add("--description"); + arglist.add("Submit-And-Cancel job 5"); + + cb = new MyCallback(); // why not, lets go nuts + submit = new DuccJobSubmit(arglist, (IDuccCallback) cb); + System.out.println(testid + " ------------------------------ Submit all_in_one local ------------------------------"); + System.out.println(testid + " Console attached: " + submit.isConsoleAttached()); + if ( submit.execute() ) { + success(testid, "Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); + } else { + fail(testid, "Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); + } + } - props = mkproperties(submit_args); // test the constructor, plus easier to update - props.setProperty("all_in_one", "remote"); - props.setProperty("scheduling_class", "fixed"); - props.setProperty("description", "Submit-And-Cancel job 6"); + void testAllInOneRemote(String testid) + throws Exception + { + IDuccCallback cb = new MyCallback(); + DuccJobSubmit submit; - cb = new MyCallback(); // why not, lets go nuts - submit = new DuccJobSubmit(props, (IDuccCallback) cb); - System.out.println("------------------------------ Submit all_in_one remote ------------------------------"); - System.out.println("Console attached: " + submit.isConsoleAttached()); - if ( submit.execute() ) { - System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); - return; - } + Properties props = mkproperties(submit_args); // test the constructor, plus easier to update + props.setProperty("all_in_one", "remote"); + props.setProperty("scheduling_class", "fixed"); + props.setProperty("description", "Submit-And-Cancel job 6"); + + // for ( Object k : props.keySet() ) { + // System.out.println("Props: k=" + k + " v=" + props.get(k)); + // } + + cb = new MyCallback(); // why not, lets go nuts + submit = new DuccJobSubmit(props, (IDuccCallback) cb); + System.out.println(testid + " ------------------------------ Submit all_in_one remote ------------------------------"); + System.out.println(testid + " Console attached: " + submit.isConsoleAttached()); + if ( submit.execute() ) { + success(testid, "Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); + } else { + fail(testid, "Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); + } + } - props.setProperty("all_in_one", "bogus"); - props.setProperty("description", "Submit-And-Cancel job 7"); - props.setProperty("scheduling_class", "fixed"); - - cb = new MyCallback(); // why not, lets go nuts - try { - System.out.println("------------------------------ Submit all_in_one bogus, should fail ------------------------------"); - System.out.println("Console attached: " + submit.isConsoleAttached()); - submit = new DuccJobSubmit(props, (IDuccCallback) cb); - if ( submit.execute() ) { - System.out.println("Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); - } else { - System.out.println("Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); - return; - } - } catch (Exception e) { - System.out.println(" ... Expected failure ..."); - e.printStackTrace(); - } + void testAllInOneBogus(String testid) + throws Exception + { + IDuccCallback cb = new MyCallback(); + DuccJobSubmit submit = null; - // Must see this, otherwise something is crashing that we didn't expect - System.out.println("------------------------------ Submit Test Ends ------------------------------"); + Properties props = mkproperties(submit_args); // test the constructor, plus easier to update + props.setProperty("all_in_one", "bogus"); + props.setProperty("description", "Submit-And-Cancel job 7"); + props.setProperty("scheduling_class", "fixed"); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + cb = new MyCallback(); // why not, lets go nuts + try { + System.out.println(testid + " ------------------------------ Submit all_in_one bogus, should fail ------------------------------"); + submit = new DuccJobSubmit(props, (IDuccCallback) cb); + System.out.println(testid + " Console attached: " + submit.isConsoleAttached()); + if ( submit.execute() ) { + fail(testid, "Job " + submit.getDuccId() + " submitted, rc = " + submit.getReturnCode()); + } else { + success(testid, "Job " + submit.getDuccId() + " not submitted, rc = " + submit.getReturnCode()); + } + } catch (Exception e) { + success(testid, "Job " + submit.getDuccId() + " could not be submitted."); + return; + } + success(testid, "Job " + submit.getDuccId() + " was submited!"); } - static class MyCallback + public static void main(String[] args) + { + try { + SubmitAndCancel tester = new SubmitAndCancel(); + tester.runTests(); + } catch ( Exception e ) { + e.printStackTrace(); + } + } + class MyCallback implements IDuccCallback { public void console(int pnum, String msg)
