Add code for working sanity test in windows. 93/1893/6
authorRyan Moats <rmoats@us.ibm.com>
Mon, 14 Oct 2013 23:40:37 +0000 (18:40 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 16 Oct 2013 21:52:11 +0000 (21:52 +0000)
Refactor application windows batch file to avoid delayed
execution issues.  Add windows batch file to run sanity test.
Refactor sanity test class to call windows batch file properly.
Refactor activator class to close System.out stream before exiting
so that ProcessBuilder detects the exit.

Refactor to first check at 10 seconds and then recheck every second
if bundles are still in the STARTING state.

Refactor to inherit IO and add limit of 60 retries.

And fix style errors

Change-Id: Ifa4d78ebfcf0eeaaccf99e56e84a88d33377f0fa
Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
opendaylight/distribution/opendaylight/run.bat
opendaylight/distribution/opendaylight/src/main/resources/run.bat
opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java
opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java

index 8981709bb1e9131c2079aad11ab621efe402ff03..f219828bad3dc0c927689e2bbc33f04f066984f0 100644 (file)
@@ -1 +1,23 @@
-REM This is where the sanity test execution for windows needs to go (see run.sh)
+rem Inject the sanitytest jar as a controller plugin
+copy .\target\dependency\sanitytest*.jar .\target\distribution.opendaylight-osgipackage\opendaylight\plugins
+
+rem Store the current working directory in a variable so that we can get back to it later
+set cwd=%cd%
+
+rem Switch to the distribution folder
+cd .\target\distribution.opendaylight-osgipackage\opendaylight
+
+rem Run the controller
+cmd.exe /c run.bat
+
+rem Store the exit value of the controller in a variable
+set success=%ERRORLEVEL%
+
+rem Switch back to the directory from which this script was invoked
+cd %cwd%
+
+rem Remove the sanitytest jar from the plugins directory
+del .\target\distribution.opendaylight-osgipackage\opendaylight\plugins\sanitytest*.jar
+
+rem Exit using the exit code that we had captured earlier after running the controller
+exit /b %SUCCESS%
\ No newline at end of file
index 6fb9f0655cc4bbfe310dfac27d4354f7160710f3..d6583a021de96f3e12c111aefdcad211f9e3f25c 100644 (file)
@@ -1,22 +1,24 @@
 @ECHO OFF
 @ECHO OFF
-SETLOCAL
-SETLOCAL ENABLEDELAYEDEXPANSION
 IF EXIST "%JAVA_HOME%" (
 IF EXIST "%JAVA_HOME%" (
-        set basedir=%~dp0
+    REM CONTINUE
+) ELSE (
+    ECHO JAVA_HOME environment variable is not set
+    EXIT 2
+)
+
+set basedir=%~dp0
 REM       Now set the classpath:
 REM       Now set the classpath:
-                set cp="!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar;!basedir!lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar;!basedir!lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
+set cp="%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar;%basedir%lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar;%basedir%lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
 
 REM       Now set framework classpath
 
 REM       Now set framework classpath
-               set fwcp="file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar,file:\!basedir!lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar,file:\!basedir!lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
+set fwcp="file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar,file:\%basedir%lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar,file:\%basedir%lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
 
 REM echo cp: %cp%
 REM echo fwcp: %fwcp%
 
 
 REM echo cp: %cp%
 REM echo fwcp: %fwcp%
 
-REM echo %JAVA_HOME%\bin\java.exe %* -Djava.io.tmpdir=!basedir!work\tmp -Dosgi.install.area=!basedir! -Dosgi.configuration.area=!basedir!configuration -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework=file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog
-"%JAVA_HOME%\bin\java.exe" %* -Djava.io.tmpdir="!basedir!work\tmp" -Dosgi.install.area=!basedir! -Dosgi.configuration.area="!basedir!configuration" -Dosgi.frameworkClassPath=!fwcp! -Dosgi.framework="file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar" -classpath !cp! org.eclipse.equinox.launcher.Main -console -consoleLog
+REM echo %JAVA_HOME%\bin\java.exe %* -Djava.io.tmpdir=%basedir%work\tmp -Dosgi.install.area=%basedir% -Dosgi.configuration.area=%basedir%configuration -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework=file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog
+"%JAVA_HOME%\bin\java.exe" %* -Djava.io.tmpdir="%basedir%work\tmp" -Dosgi.install.area=%basedir% -Dosgi.configuration.area="%basedir%configuration" -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework="file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar" -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog
+
+exit %ERRORLEVEL%
+
 
 
-) ELSE (
-    ECHO JAVA_HOME environment variable is not set
-    PAUSE
-)
-ENDLOCAL
index 33ff8ea18a19d84764061ff3aefbb259d1c185d2..6f395c9e6ca22aca1f7eec805cfbed156745767c 100644 (file)
@@ -4,6 +4,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class Sanity {
 
     static void copy(InputStream in, OutputStream out) throws IOException {
 public class Sanity {
 
     static void copy(InputStream in, OutputStream out) throws IOException {
@@ -20,16 +23,18 @@ public class Sanity {
         System.out.println("Current working directory = " + cwd);
 
         String os = System.getProperty("os.name").toLowerCase();
         System.out.println("Current working directory = " + cwd);
 
         String os = System.getProperty("os.name").toLowerCase();
-        String script = "./run.sh";
+        List<String> script = new ArrayList<String>();
 
         if(os.contains("windows")){
 
         if(os.contains("windows")){
-            System.out.println("Sorry no sanity testing on Windows yet");
-            System.exit(0);
-            return;
+            script.add("cmd.exe");
+            script.add("/c");
+            script.add("run.bat");
+        } else {
+            script.add("./run.sh");
         }
 
         ProcessBuilder processBuilder = new ProcessBuilder();
         }
 
         ProcessBuilder processBuilder = new ProcessBuilder();
-        processBuilder.command(script);
+        processBuilder.inheritIO().command(script);
         Process p = processBuilder.start();
 
         copy(p.getInputStream(), System.out);
         Process p = processBuilder.start();
 
         copy(p.getInputStream(), System.out);
index c27cd07a7e7673e6dd147d46744cc4665da131e8..d92277269a01f2f8fc3eac7df8af6d78f212bf22 100644 (file)
@@ -9,8 +9,9 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.wiring.BundleRevision;
 
 public class Activator implements BundleActivator {
 import org.osgi.framework.wiring.BundleRevision;
 
 public class Activator implements BundleActivator {
-    //30 Second
-    private static final int DELAY = 30000;
+    //10 Second initial, 1 second subsequent
+    private static final int INITIAL_DELAY = 10000;
+    private static final int SUBSEQUENT_DELAY = 1000;
 
 
     private String stateToString(int state) {
 
 
     private String stateToString(int state) {
@@ -23,8 +24,10 @@ public class Activator implements BundleActivator {
             return "RESOLVED";
         case Bundle.UNINSTALLED:
             return "UNINSTALLED";
             return "RESOLVED";
         case Bundle.UNINSTALLED:
             return "UNINSTALLED";
+        case Bundle.STARTING:
+            return "STARTING";
         default:
         default:
-            return "Not CONVERTED";
+            return "Not CONVERTED: state value is " + state;
         }
     }
 
         }
     }
 
@@ -33,27 +36,61 @@ public class Activator implements BundleActivator {
         monitorTimer.schedule(new TimerTask() {
             @Override
             public void run() {
         monitorTimer.schedule(new TimerTask() {
             @Override
             public void run() {
+                int countup = 0;
                 boolean failed = false;
                 boolean failed = false;
-                for(Bundle bundle : bundleContext.getBundles()){
-                    /*
-                     * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED
-                     */
-                    if(!(bundle.getState() == Bundle.ACTIVE) ||
-                        (bundle.getState() != Bundle.RESOLVED &&
-                        (bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0))
-                    if(bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.RESOLVED) {
-                        System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
-                        failed = true;
+                boolean resolved = false;
+                while (!resolved) {
+                    resolved = true;
+                    failed = false;
+                    for(Bundle bundle : bundleContext.getBundles()){
+                        /*
+                         * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED
+                         */
+                        int state = bundle.getState();
+                        if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+                            //fragment
+                            if (state != Bundle.RESOLVED) {
+                                System.out.println("------ Failed to activate/resolve fragment = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
+                                failed = true;
+                                if (state == Bundle.STARTING)
+                                    resolved = false;
+                            }
+                        } else {
+                            if(state != Bundle.ACTIVE) {
+                                System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
+                                failed = true;
+                                if (state == Bundle.STARTING)
+                                    resolved = false;
+                            }
+                        }
+                    }
+                    if (!resolved) {
+                        countup++;
+                        if (countup < 60) {
+                            System.out.println("all bundles haven't finished starting, will repeat");
+                            try {
+                                Thread.sleep(SUBSEQUENT_DELAY);
+                            } catch (Exception e) {
+                                ;
+                            }
+                        } else
+                            resolved = true;
                     }
                 }
 
                 if(failed){
                     }
                 }
 
                 if(failed){
-                    System.exit(-1);
+                    System.out.flush();
+                    System.out.println("exiting with 1 as failed");
+                    System.out.close();
+                    Runtime.getRuntime().exit(1);
                 } else {
                 } else {
-                    System.exit(0);
+                    System.out.flush();
+                    System.out.println("exiting with 0 as succeeded");
+                    System.out.close();
+                    Runtime.getRuntime().exit(0);
                 }
             }
                 }
             }
-        }, DELAY);
+        }, INITIAL_DELAY);
     }
 
     public void stop(BundleContext bundleContext) throws Exception {
     }
 
     public void stop(BundleContext bundleContext) throws Exception {