
org.perfcake.ScenarioExecution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of perfcake Show documentation
Show all versions of perfcake Show documentation
A Lightweight Performance Testing Framework
/*
* -----------------------------------------------------------------------\
* PerfCake
*
* Copyright (C) 2010 - 2013 the original author or authors.
*
* 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
*
* 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.perfcake;
import org.perfcake.scenario.Scenario;
import org.perfcake.scenario.ScenarioLoader;
import org.perfcake.util.Utils;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Calendar;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
/**
* The main class to start PerfCake from command line. It parses command line parameters, loads the scenario XML file and runs it.
*
* @author Pavel Macík
* @author Martin Večeřa
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DM_EXIT", justification = "This class is allowed to terminate the JVM.")
public class ScenarioExecution {
private static final Logger log = Logger.getLogger(ScenarioExecution.class);
/**
* Command line parameters.
*/
private CommandLine commandLine;
/**
* The scenario created from the specified XML file.
*/
private Scenario scenario;
/**
* Parses command line arguments and creates this class to take care of the Scenario execution.
*
* @param args
* command line arguments.
*/
private ScenarioExecution(final String[] args) {
parseCommandLine(args);
loadScenario();
}
/**
* Parses a single command line parameter/option.
*
* @param option
* The parameter/option name.
* @param property
* The system property to which the option value should be stored.
* @param defaultValue
* The default value for the option when it is not present at the command line.
*/
private void parseParameter(final String option, final String property, final String defaultValue) {
if (commandLine.hasOption(option)) {
System.setProperty(property, commandLine.getOptionValue(option));
} else {
if (defaultValue != null) {
System.setProperty(property, defaultValue);
}
}
}
/**
* Parses additional user properties specified in a property file and at the command line.
*/
private void parseUserProperties() {
Properties props = new Properties();
String propsFile = System.getProperty(PerfCakeConst.PROPERTIES_FILE_PROPERTY);
if (propsFile != null) {
try (final FileInputStream propsInputStream = new FileInputStream(propsFile)) {
props.load(propsInputStream);
} catch (IOException e) {
// we can still continue without reading file
log.warn(String.format("Unable to read the properties file '%s': ", propsFile), e);
}
}
props.putAll(commandLine.getOptionProperties("D"));
for (Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy