package test.stress; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * The class responsible for generate tasks or resource range experiments and * running memory and time analysis on them. * * @author Jarek Szymczak * @version $Id$ */ public class GeneratingAndTestingManager { /** Class logger. */ private static final Log LOGGER = LogFactory.getLog(GeneratingAndTestingManager.class); /** * The file paths of generated experiments passed to memory and time * analysis. */ private static List parameters = new ArrayList(); /** List of paramters (after they're parsed from main method arguments). */ private static Map methodParameters = new HashMap(); /** * It determines whether memory and time analysis should be performed after * experiments generation. */ private static boolean run; /** * The main method. Apart arguments the program is run with, generation of * experiments depends on file "properties/variables.properties" and * "*properties/template*.*" files * * @param args * the following arguments (other are not allowed - arguments * predecessed by "#" are integers): *
    *
  • -r - memory and time analysis will be performed * after generation (if specified) *
  • --rg #tasks #start #step #end - experiments with * #tasks number of tasks will be generated for range of * resources from #start to #end with step #step *
  • --rv #tasks #resources_1 ... #resources_n - * experiments with #tasks number of tasks will be generated for * #resources_1, ..., #resources_n number of resources *
  • --tg #start #step #end - experiments with tasks * range from #start to #end with step #step will be generated *
  • --tv #tasks_1 ... #tasks_n - experiments with * #tasks_1, ..., #tasks_n number of tasks will be generated *
* * @throws FileNotFoundException * if one of necessary files was not found * @throws IOException * Signals that an I/O exception has occurred. * @throws InterruptedException * should not occur */ public static void main(String args[]) throws FileNotFoundException, IOException, InterruptedException { String argsProcessed[] = args; while (argsProcessed.length != 0) { argsProcessed = processArguments(argsProcessed); } if (methodParameters.containsKey("tg") && methodParameters.containsKey("tv")) { System.out .println("Argumets --tg and --tv cannot be used together"); return; } if (methodParameters.containsKey("rg") && methodParameters.containsKey("rv")) { System.out .println("Argumets --rg and --rv cannot be used together"); return; } if (methodParameters.containsKey("tg") && (methodParameters.get("tg").length != 4)) { System.out.println("Wrong usage of --tg argument"); return; } if (methodParameters.containsKey("rg") && (methodParameters.get("rg").length != 5)) { System.out.println("Wrong usage of --rg argument"); return; } if (methodParameters.containsKey("tv") && (methodParameters.get("tv").length < 2)) { System.out.println("Wrong usage of --tg argument"); return; } if (methodParameters.containsKey("rv") && (methodParameters.get("rv").length < 3)) { System.out.println("Wrong usage of --rg argument"); return; } if (methodParameters.containsKey("tg") && methodParameters.containsKey("tv")) { System.out .println("Argumets --tg and --tv cannot be used together"); return; } if (methodParameters.containsKey("tg")) { TasksExperimentsGenerator teg = new TasksExperimentsGenerator(); parameters.add(teg.run(methodParameters.get("tg"))); } if (methodParameters.containsKey("tv")) { TasksExperimentsGenerator teg = new TasksExperimentsGenerator(); parameters.add(teg.run(methodParameters.get("tv"))); } if (methodParameters.containsKey("rg")) { ResourcesExperimentsGenerator reg = new ResourcesExperimentsGenerator(); parameters.add(reg.run(methodParameters.get("rg"))); } if (methodParameters.containsKey("rv")) { ResourcesExperimentsGenerator reg = new ResourcesExperimentsGenerator(); parameters.add(reg.run(methodParameters.get("rv"))); } if (run) { LOGGER .info("Memory and time consumption analysis will begin in 3 seconds, please wait..."); for (int i = 0; i < 5; i++) { System.gc(); Thread.sleep(600); } MemoryAndTimeAnalyzer.main(parameters.toArray(new String[parameters .size()])); } } /** * It processes the arguments. It moves arguments with it's parameters from * an args array (they're removed) to methodParameters map. * * @param args * array with (possibly) many groups of parameters (arguments) * @return separated group of parameters */ private static String[] processArguments(String args[]) { int offset = 0; if ("-r".equals(args[0])) { run = true; offset = 1; } else { do { offset++; } while ((offset < args.length) && !args[offset].startsWith("-")); if ("--rv".equals(args[0])) { String[] rvArgs = arrayCopyOfRange(args, 0, offset); rvArgs[0] = "-v"; methodParameters.put("rv", rvArgs); } else if ("--rg".equals(args[0])) { String[] rvArgs = arrayCopyOfRange(args, 0, offset); rvArgs[0] = "-g"; methodParameters.put("rg", rvArgs); } else if ("--tv".equals(args[0])) { String[] rvArgs = arrayCopyOfRange(args, 0, offset); rvArgs[0] = "-v"; methodParameters.put("tv", rvArgs); } else if ("--tg".equals(args[0])) { String[] rvArgs = arrayCopyOfRange(args, 0, offset); rvArgs[0] = "-g"; methodParameters.put("tg", rvArgs); } else { System.out.println("Incorrect switch (" + args[0] + "). Supported are:"); System.out .println("-r\t\tif specified after generation tests will be performed"); System.out .println("--rv\t\tif resources experiment generation from certain values"); System.out .println("--rg\t\tif resources experiment generation"); System.out .println("--tv\t\tif tasks experiment generation from certain values"); System.out.println("--tg\t\tif tasks experiment generation"); System.exit(-1); } } return arrayCopyOfRange(args, offset, args.length); } /** * Copy of array's range. Method written as a wrapper to System method * arraycopy(). * * @param original * the original array * @param from * from index * @param to * to index * @return truncated array */ private static String[] arrayCopyOfRange(String[] original, int from, int to) { String[] result = new String[to - from]; System.arraycopy(original, from, result, 0, to - from); return result; } }