Author: [email protected]
Date: Tue Oct 18 10:29:26 2011
New Revision: 1520

Log:
[AMDATUCASSANDRA-113] Improved framework: additional clean work dir options, 
printUsage now displays all options, Amdatu launcher now invoked a fixed URL to 
test that startup is finished (which is now responsibility of the performance 
test bundle), removed obsolete noexamples option and applied some fixes needed 
for 0.2.1 compliance 

Modified:
   
trunk/test-performance/src/main/java/org/amdatu/test/performance/main/Main.java
   
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/AmdatuLauncher.java
   
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/ApplicationContext.java
   
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/TestContext.java

Modified: 
trunk/test-performance/src/main/java/org/amdatu/test/performance/main/Main.java
==============================================================================
--- 
trunk/test-performance/src/main/java/org/amdatu/test/performance/main/Main.java 
    (original)
+++ 
trunk/test-performance/src/main/java/org/amdatu/test/performance/main/Main.java 
    Tue Oct 18 10:29:26 2011
@@ -42,33 +42,33 @@
  */
 public class Main {
     public static String CONFIGFILE_ARG = "-config";
-    public static String VERBOSE_ARG = "-verbose";
-    public static String ANALYZE_ARG = "-analyze";
-    public static String RUNTEST_ARG = "-runtest";
-    public static String NOEXAMPLES_ARG = "-noexamples";
-    public static String VERIFY_ARG = "-verify";
+    public static String VERBOSE_ARG = "-verbose";
+    
+    public static String RUNTEST_ARG = "-runtest";
+    public static String ANALYZE_ARG = "-analyze";
+    public static String VERIFY_ARG = "-verify";   
+    
+    public static String VERSIONDIR_ARG = "-versiondir";
+    public static String AMDATU_X_ARG = "-amdatuVersionX";
+    public static String AMDATU_Y_ARG = "-amdatuVersionY";
+    
+    public static String TMPDIR_ARG = "-tmpdir";
     public static String CLEAN_ARG = "-clean";
-    public static String AMDATU_X_ARG = "-amdatuVersionX";
-    public static String AMDATU_Y_ARG = "-amdatuVersionY";
     public static String JMETERPLANSDIR_ARG = "-jmeterplansdir";
     public static String RESULTSDIR_ARG = "-resultsdir";
-    public static String TMPDIR_ARG = "-tmpdir";
+    
     public static String TESTLOOPS_ARG = "-testloops";
-    public static String OMIT_ARG = "-omit";
-    public static String PORT_ARG = "-port";
+    public static String OMIT_ARG = "-omit";
     public static String SAMPLESIZE_ARG = "-m";
-    public static String VERSIONDIR_ARG = "-versiondir";
-
-
+    public static String PORT_ARG = "-port";
+    
     // Wordy arguments
     private final static List<String> BOOLEAN_ARGS = new ArrayList<String>();
     static {
         BOOLEAN_ARGS.add(VERBOSE_ARG);
         BOOLEAN_ARGS.add(ANALYZE_ARG);
         BOOLEAN_ARGS.add(RUNTEST_ARG);
-        BOOLEAN_ARGS.add(NOEXAMPLES_ARG);
         BOOLEAN_ARGS.add(VERIFY_ARG);
-        BOOLEAN_ARGS.add(CLEAN_ARG);
     }
 
     // File arguments
@@ -94,7 +94,8 @@
         OTHER_ARGS.add(TESTLOOPS_ARG);
         OTHER_ARGS.add(OMIT_ARG);
         OTHER_ARGS.add(PORT_ARG);
-        OTHER_ARGS.add(SAMPLESIZE_ARG);
+        OTHER_ARGS.add(SAMPLESIZE_ARG);
+        OTHER_ARGS.add(CLEAN_ARG);
     }
     public static void main(String[] args) {
         try {
@@ -183,7 +184,7 @@
                 for (String[] test : tests) {
                     String t0 = 
test[0].substring(test[0].lastIndexOf(File.separator) + 1);
                     String t1 = 
test[1].substring(test[1].lastIndexOf(File.separator) + 1);
-                    Logger.log(c + ". " + t0 + " versus " + t1);
+                    Logger.log(c + ". " + t0 + " (X) versus " + t1 + " (Y)");
                     c++;
                 }
                 for (String[] test : tests) {
@@ -272,11 +273,23 @@
         System.err.println("Usage: ");
         System.err.println("-verbose         Set verbose mode on");
         System.err.println("-runtest         Runs a performance test");
-        System.err.println("-analyze         Runs a performance test 
analysis");
-        System.err.println("-amdatuVersionX  Absolute path to a binary 
distribution zip of an Amdatu release, called version X. This represents the 
new version to be compared with the previous version Y (required only for 
-runtest)");
-        System.err.println("-amdatuVersionY  Absolute path to a binary 
distribution zip of an Amdatu release, called version Y. This represents the 
original version. (required only for -runtest)");
+        System.err.println("-analyze         Run a performance test analysis");
+        System.err.println("-verify          Run a verification test, 
executing a performance test of version X against version X. This should 
obviously result " +
+                                            "in an outcome stating that there 
is no significant difference in performance");
+        System.err.println("-versiondir      Executes the test for all Amdatu 
versions available in this directory. Should not be combines with 
-amdatuVersionX " +
+                                            "and -amdatuVersionY, use one of 
the two");
+        System.err.println("-amdatuVersionX  Absolute path to a binary 
distribution zip of an Amdatu release to test, called version X.");
+        System.err.println("-amdatuVersionY  Absolute path to a binary 
distribution zip of an Amdatu release to test, called version Y.");
+        System.err.println("-tmpdir          Name of the temporary 
directory.");
+        System.err.println("-clean           Indicates if the work directory 
should be removed just before starting Amdatu. Options: 0 - Do not remove work 
" +
+                                            "directory, 1 - Remove work 
directory except for the bundle cache, 2 - Remove work directory completely");
         System.err.println("-jmeterplansdir  Absolute path to a directory that 
holds JMeter plans to execute during the performance test (required only for 
-runtest)");
-        System.err.println("-resultsdir      Absolute path to a directory to 
which the results of JMeter executions will be written as well as analysis 
results (required for both -runtest and -analyze)");
+        System.err.println("-resultsdir      Absolute path to a directory to 
which the results of JMeter executions will be written as well as analysis 
results " +
+                                            "(required for both -runtest and 
-analyze)");
+        System.err.println("-testloops       The amount of testloops to 
execute");
+        System.err.println("-omit            Omits the first [amount] results 
of each test run, with the purpose of reducing correlation between the 
results");
+        System.err.println("-m               The amount of samples to define Z 
for; each sample Z is the mean of m samples X-Y");
+        System.err.println("-port            The port on which the HTTP 
service runs (used by JMeter to invoke REST services)");
     }
 
     private static int runTest(ApplicationContext context) throws IOException, 
InterruptedException, ParserConfigurationException, SAXException, MathException 
{
@@ -284,7 +297,7 @@
         AmdatuLauncher launcher = new AmdatuLauncher(context);
         JMeterRunner jmeter = new JMeterRunner(context);
 
-        int n = context.clean ? 1 : 0;
+        int n = (context.clean == 2)? 1 : 0;
         for (;n<=context.testLoops; n++) {
             
Logger.log("*************************************************************");
             if (n == 0) {

Modified: 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/AmdatuLauncher.java
==============================================================================
--- 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/AmdatuLauncher.java
        (original)
+++ 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/AmdatuLauncher.java
        Tue Oct 18 10:29:26 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2010, 2011 The Amdatu Foundation
- * 
+ *
  * Licensed 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
@@ -28,14 +28,13 @@
 
 /**
  * This class is responsible for starting/stopping Amdatu distributions from a 
single zip file.
- * 
+ *
  * @author ivol
  */
 public class AmdatuLauncher {
     // For now hardcoded, could be read from deploy/org.apache.felix.http.cfg
     private static final String[] CHECK_URLS = new String[] {
-        "http://localhost:${PORT}/dashboard/jsp/dashboard.jsp";,
-        "http://localhost:${PORT}${REST}";
+        "http://localhost:${PORT}/rest/performancetest/status";
     };
 
     private ApplicationContext m_context;
@@ -56,12 +55,12 @@
             m_tmpDir.mkdir();
             Logger.log("Extracting '" + zipFile.getName() + "' to '" + 
m_tmpDir.getAbsolutePath() + "'");
             Utils.unzip(zipFile, m_tmpDir);
-            if (m_context.noExamples) {
-                removeExamples();
-            }
             addTestBundles();
             setPortNumber();
-        }
+        }
+        
+        // Clean up work directory if necessary
+        clean();
 
         // Start the Amdatu server in a separate process
         List<String> command = new ArrayList<String>();
@@ -69,10 +68,10 @@
         command.add("-Xms256m");
         command.add("-Xmx1024m");
         command.add("-XX:MaxPermSize=256m");
-        
command.add("-Dfelix.config.properties=file:conf/felix-config.properties");
+        
command.add("-Dfelix.config.properties=file:conf/amdatu-platform.properties");
         command.add("-Dfile.encoding=utf-8");
         command.add("-jar");
-        command.add("amdatu-system/" + getFelixMainJar());
+        command.add(getFelixMainJar());
 
         ProcessBuilder processBuilder = new ProcessBuilder(command);
         processBuilder.directory(m_tmpDir);
@@ -94,15 +93,16 @@
                 url = url.replace("${REST}", 
"/rest/services/authorization/authorization/status");
             }
             Logger.log("Waiting for " + url + " to return a 200");
-            ok |= waitForURL(new URL(url), 200, 180000);
+            ok |= waitForURL(new URL(url), 200, 60000); // timeout after 1 
minute
         }
         if (!ok) {
             throw new IllegalStateException("Amdatu could not be launched from 
'" + m_tmpDir + "'. Aborting test.");
         }
 
-        // For safety, additional wait for 5 seconds
-        Logger.log("Amdatu seems up and running, waiting another 5 
seconds...");
-        Thread.sleep(5000);
+        // When the performance REST service is available, we can start our 
tests. The
+        // performance test bundle that implements the REST service is 
responsible for defining 
+        // the proper service dependencies needed to run the test
+        Logger.log("Amdatu seems up and running!");
 
         long diff = System.currentTimeMillis() - before;
         Logger.log("Amdatu startup completed in " + diff + " ms, running 
JMeter test plans");
@@ -121,12 +121,23 @@
             m_amdatuProcess.waitFor();
         }
 
-        if (m_context.clean) {
-            // Clean up work directory after shutdown
-            FileUtils.deleteDirectory(new File(m_tmpDir, "work"));
-        }
-
         Logger.log("Amdatu shutdown completed");
+    }
+    
+    public void clean() throws IOException {
+        if (m_context.clean == 2) {
+            // Clean up work directory after shutdown
+            FileUtils.deleteDirectory(new File(m_tmpDir, "work"));
+        } else if (m_context.clean == 1) {
+            File tmpdir = new File(m_tmpDir, "work");
+            if (tmpdir.exists() && tmpdir.listFiles() != null) {
+                for (File dir : tmpdir.listFiles()) {
+                    if (!"cache".equals(dir.getName())) {
+                        FileUtils.deleteDirectory(dir);
+                    }
+                }
+            }
+        }
     }
 
     public void kill() throws IOException, InterruptedException {
@@ -137,34 +148,13 @@
         FileUtils.deleteDirectory(m_tmpDir);
     }
 
-    private void removeExamples() throws IOException {
-        // Remove all jar files in amdatu-examples
-        File exampleDir = new File (m_tmpDir, "amdatu-examples");
-        FileUtils.deleteDirectory(exampleDir);
-
-        // Remove from Felix config properties. Note that if 
felix-config.properties does not exist,
-        // this is a newer version which does not include examples anyway and 
so we can skip it
-        File felixConfig = new File(m_tmpDir, "conf/felix-config.properties");
-        if (felixConfig.exists()) {
-            List<String> lines = FileUtils.readLines(felixConfig);
-            List<String> newLines = new ArrayList<String>();
-            for (String line : lines) {
-                if 
(line.indexOf("reference:file:amdatu-examples/org.amdatu.example.") == -1) {
-                    newLines.add(line);
-                }
-            }
-            felixConfig.delete();
-            FileUtils.writeLines(felixConfig, newLines);
-        }
-    }
-    
     private void addTestBundles() throws IOException {
         if (m_context.versionDir != null) {
             File[] files = new File(m_context.versionDir).listFiles();
             for (File file : files) {
                 if (file.getName().endsWith(".jar")) {
                     // This is a test bundle, copy it to the deploy directory
-                    FileUtils.copyFile(file, new File(new File(m_tmpDir, 
"deploy"), file.getName()));
+                    //FileUtils.copyFile(file, new File(new File(m_tmpDir, 
"deploy"), file.getName()));
                 }
             }
         }
@@ -191,9 +181,12 @@
     private boolean waitForURL(URL url, int responseCode, int timeout) throws 
IOException {
         long deadline = System.currentTimeMillis() + timeout;
         while (System.currentTimeMillis() < deadline && 
amdatuProcessRunning()) {
-            try {
-                if (checkURL(url) == responseCode) {
+            try {
+                int status = checkURL(url);
+                if (status == responseCode) {
                     return true;
+                } else {
+                    Logger.log("Http response code: " + status + ", timeout in 
" + (deadline - System.currentTimeMillis()) + " ms");
                 }
                 Thread.sleep(2000);
             }
@@ -225,13 +218,19 @@
         }
     }
 
-    private String getFelixMainJar() {
-        File systemDir = new File(m_tmpDir, "amdatu-system");
-        for (File file : systemDir.listFiles()) {
-            if (file.getName().startsWith("org.apache.felix.main")) {
-                return file.getName();
-            }
-        }
+    private String getFelixMainJar() {
+        // Different versions use different 'system' dirs
+        String[] systemDirs = new String[]{"lib", "amdatu-system"};
+        for (String dirName : systemDirs) {
+            File systemDir = new File(m_tmpDir, dirName);
+            if (systemDir.exists()) {
+                for (File file : systemDir.listFiles()) {
+                    if (file.getName().startsWith("org.apache.felix.main")) {
+                        return dirName + "/" + file.getName();
+                    }
+                }
+            }
+        }
         return null;
     }
 }

Modified: 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/ApplicationContext.java
==============================================================================
--- 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/ApplicationContext.java
    (original)
+++ 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/ApplicationContext.java
    Tue Oct 18 10:29:26 2011
@@ -24,8 +24,7 @@
 public class ApplicationContext {
     public String jmeterPlanDir; // directory to read JMeter plans from
     public String resultsDir; // directory to write results to
-    public boolean noExamples; // Indication of examples should be removed 
prior to running the tests
-    public boolean clean = false; // Indicates if the Amdatu work directory 
must be deleted prior to running each test
+    public int clean = 0; // Indicates if the Amdatu work directory must be 
deleted prior to running each test
     public int omit; // Amount of initial results to omit
     public File rootTmpDir; // Root temporary directory
     public int testLoops;
@@ -46,7 +45,6 @@
             jmeterPlanDir = arguments.get(Main.JMETERPLANSDIR_ARG).toString();
         }
         resultsDir = arguments.get(Main.RESULTSDIR_ARG).toString();
-        noExamples = Boolean.TRUE.equals(arguments.get(Main.NOEXAMPLES_ARG));
         omit = arguments.containsKey(Main.OMIT_ARG) ? 
Integer.parseInt(arguments.get(Main.OMIT_ARG).toString()) : 0;
         rootTmpDir = getRootTmpDir(arguments.get(Main.TMPDIR_ARG));
         testLoops = arguments.containsKey(Main.TESTLOOPS_ARG) ? 
Integer.parseInt(arguments.get(Main.TESTLOOPS_ARG).toString()) : 1;
@@ -55,10 +53,8 @@
         }
         if (arguments.containsKey(Main.SAMPLESIZE_ARG)) {
             sampleSize = 
Integer.parseInt(arguments.get(Main.SAMPLESIZE_ARG).toString());
-        }
-        if (arguments.containsKey(Main.CLEAN_ARG)) {
-            clean = true;
-        }
+        }
+        clean = arguments.containsKey(Main.CLEAN_ARG) ? 
Integer.parseInt(arguments.get(Main.CLEAN_ARG).toString()) : 0;
         if (arguments.containsKey(Main.VERSIONDIR_ARG)) {
             versionDir = arguments.get(Main.VERSIONDIR_ARG).toString();
         }

Modified: 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/TestContext.java
==============================================================================
--- 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/TestContext.java
   (original)
+++ 
trunk/test-performance/src/main/java/org/amdatu/test/performance/runtest/TestContext.java
   Tue Oct 18 10:29:26 2011
@@ -31,9 +31,19 @@
     }
     
     private static String getVersionFromZipName(String zipName) {
-        // Syntax ...amdatu-release-[version]-bin.zip
-        String version = zipName.substring(0, zipName.indexOf("-bin.zip"));
-        version = version.substring(version.indexOf("amdatu-release-") + 
"amdatu-release-".length());
+        // Syntax ...amdatu-release-[version](-bin).zip ('-bin' is optional)
+        String version = "";
+        if (zipName.endsWith(".zip")) {
+           version =  zipName.substring(0, zipName.indexOf(".zip"));
+        }
+        if (version.endsWith("-bin")) {
+             version = zipName.substring(0, zipName.indexOf("-bin"));
+            
+        }
+        if (version.endsWith("-SNAPSHOT")) {
+             version = zipName.substring(0, zipName.indexOf("-SNAPSHOT"));
+        } 
+        version = version.substring(version.lastIndexOf("-") + 1);
         return version;
     }
     
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to