Author: [email protected]
Date: Wed Mar 30 15:01:27 2011
New Revision: 928

Log:
[AMDATU-332] Added -versiondir option

Modified:
   
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/main/Main.java

Modified: 
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/main/Main.java
==============================================================================
--- 
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/main/Main.java
  (original)
+++ 
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/main/Main.java
  Wed Mar 30 15:01:27 2011
@@ -54,7 +54,8 @@
     public static String OMIT_ARG = "-omit";
     public static String PORT_ARG = "-port";
     public static String SAMPLESIZE_ARG = "-m";
-    
+    public static String VERSIONDIR_ARG = "-versiondir";
+
 
     // Wordy arguments
     private final static List<String> BOOLEAN_ARGS = new ArrayList<String>();
@@ -80,8 +81,9 @@
         DIR_ARGS.add(JMETERPLANSDIR_ARG);
         DIR_ARGS.add(RESULTSDIR_ARG);
         DIR_ARGS.add(TMPDIR_ARG);
+        DIR_ARGS.add(VERSIONDIR_ARG);
     }
-    
+
     // Other arguments
     private final static List<String> OTHER_ARGS = new ArrayList<String>();
     static {
@@ -146,46 +148,66 @@
                     System.out.println(key + "=" + arguments.get(key)) ;
                 }
             }
-            
+
             if (!Boolean.TRUE.equals(arguments.get(RUNTEST_ARG)) && 
!Boolean.TRUE.equals(arguments.get(ANALYZE_ARG))) {
                 System.err.println("Invalid arguments provided");
                 printUsage();
             }
-            
-            ApplicationContext context = new ApplicationContext(arguments);
-            
-            if (Boolean.TRUE.equals(arguments.get(RUNTEST_ARG))) {
-                if (verifyRunTest(arguments)) {
-                    String amdatuX = arguments.get(AMDATU_X_ARG).toString();
-                    String amdatuY = arguments.get(AMDATU_Y_ARG).toString();
-                    
-                    TestContext contextX = new TestContext(new File(amdatuX));
-                    TestContext contextY = new TestContext(new File(amdatuY));
-                    context.setContext(contextX, contextY);
-                       
-                    runTest(context);
-                    
-                    if (Boolean.TRUE.equals(arguments.get(VERIFY_ARG))) {
-                        // Run additional test runs to verify that the H0 
tests of X versus X and Y versus Y
-                        // are all accepted
-                        // Verify X
-                        context.setContext(contextX, contextX);
-                        runTest(context);
-                        
-                        // Verify Y
-                        context.setContext(contextY, contextY);
-                        runTest(context);
+
+            List<String[]> tests = new ArrayList<String[]>();
+            if (arguments.containsKey(VERSIONDIR_ARG)) {
+                boolean verify = 
Boolean.TRUE.equals(arguments.get(VERIFY_ARG));
+                File[] versions = new 
File(arguments.get(VERSIONDIR_ARG).toString()).listFiles();
+                for (File v1: versions) {
+                    for (File v2: versions) {
+                        if (verify || 
!v1.getAbsolutePath().equals(v2.getAbsolutePath())) {
+                            tests.add(new String[]{v1.getAbsolutePath(), 
v2.getAbsolutePath()});
+                        } 
                     }
-                }                   
+                }
+
+                // Remove verify flag if set, verification runs are already 
explicitly set in the test array
+                if (verify) {
+                    arguments.remove(VERIFY_ARG);
+                }
+            } else {
+                tests.add(new String[]{arguments.get(AMDATU_X_ARG).toString(), 
arguments.get(AMDATU_Y_ARG).toString()});
             }
-            if (Boolean.TRUE.equals(arguments.get(ANALYZE_ARG))) {
-                if (!arguments.containsKey(RESULTSDIR_ARG)) {
-                    printUsage();
-                } else {
-                    Statistics stats = new Statistics(context);
-                    stats.analyze();
-                    stats.print();
-                    System.out.println("Amdatu performance test analysis 
completed.");
+
+            for (String[] test : tests) {
+                String amdatuX = test[0];
+                String amdatuY = test[1];
+                ApplicationContext context = new ApplicationContext(arguments);
+                if (Boolean.TRUE.equals(arguments.get(RUNTEST_ARG))) {
+                    if (verifyRunTest(arguments)) {
+                        TestContext contextX = new TestContext(new 
File(amdatuX));
+                        TestContext contextY = new TestContext(new 
File(amdatuY));
+                        context.setContext(contextX, contextY);
+
+                        runTest(context);
+
+                        if (Boolean.TRUE.equals(arguments.get(VERIFY_ARG))) {
+                            // Run additional test runs to verify that the H0 
tests of X versus X and Y versus Y
+                            // are all accepted
+                            // Verify X
+                            context.setContext(contextX, contextX);
+                            runTest(context);
+
+                            // Verify Y
+                            context.setContext(contextY, contextY);
+                            runTest(context);
+                        }
+                    }                   
+                }
+                if (Boolean.TRUE.equals(arguments.get(ANALYZE_ARG))) {
+                    if (!arguments.containsKey(RESULTSDIR_ARG)) {
+                        printUsage();
+                    } else {
+                        Statistics stats = new Statistics(context);
+                        stats.analyze();
+                        stats.print();
+                        System.out.println("Amdatu performance test analysis 
completed.");
+                    }
                 }
             }
         } catch (Throwable t) {
@@ -196,11 +218,11 @@
 
     private static boolean verifyRunTest(Map<String, Object> arguments) {
         boolean ok = true;
-        if (!arguments.containsKey(AMDATU_X_ARG) || 
arguments.get(AMDATU_X_ARG).toString().isEmpty()) {
+        if (!arguments.containsKey(VERSIONDIR_ARG) && 
(!arguments.containsKey(AMDATU_X_ARG) || 
arguments.get(AMDATU_X_ARG).toString().isEmpty())) {
             System.err.println("No argument " + AMDATU_X_ARG + " provided");
             ok = false;
         }
-        if (!arguments.containsKey(AMDATU_Y_ARG) || 
arguments.get(AMDATU_Y_ARG).toString().isEmpty()) {
+        if (!arguments.containsKey(VERSIONDIR_ARG) && 
(!arguments.containsKey(AMDATU_Y_ARG) || 
arguments.get(AMDATU_Y_ARG).toString().isEmpty())) {
             System.err.println("No argument " + AMDATU_Y_ARG + " provided");
             ok = false;
         }
@@ -220,6 +242,10 @@
             System.err.println("Directory '" + arguments.get(RESULTSDIR_ARG) + 
"' is not a valid, existing, directory");
             ok = false;
         }
+        if (arguments.containsKey(VERSIONDIR_ARG) && !new 
File(arguments.get(VERSIONDIR_ARG).toString()).exists()) {
+            System.err.println("Directory " + arguments.get(VERSIONDIR_ARG) + 
" does not exist");
+            ok = false;
+        }
         if (!ok) {
             printUsage();
         } 
@@ -236,17 +262,17 @@
         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)");
     }
-    
+
     private static int runTest(ApplicationContext context) throws IOException, 
InterruptedException, ParserConfigurationException, SAXException, MathException 
{
         // Build the context
         AmdatuLauncher launcher = new AmdatuLauncher(context);
         JMeterRunner jmeter = new JMeterRunner(context);
-       
+
         int n;
         for (n=1; n<=context.testLoops; n++) {
             
System.out.println("*************************************************************");
             System.out.println("Running test loop " + n + " of " + 
context.testLoops + "...");
-            
+
             String[] versions = new String[]{ApplicationContext.VERSION_X, 
ApplicationContext.VERSION_Y};
             for (String version : versions) {
                 try {
@@ -264,16 +290,16 @@
                 }
             }
         }
-        
+
         String[] versions = new String[]{ApplicationContext.VERSION_X, 
ApplicationContext.VERSION_Y};
         for (String version : versions) {
             context.setCurrentContext(version);
             launcher.kill();
         }
-        
+
         System.out.println("Amdatu performance test completed.");
         return n;
     }
-    
-    
+
+
 }
\ No newline at end of file
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to