Author: lzoubek(a)redhat.com
Date: 2011-08-10 08:40:32 -0400 (Wed, 10 Aug 2011)
New Revision: 33761
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ESBBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/RuntimeBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ServerBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java
Log:
swtbotext: optimize multi-config test execution (do not download runtimes when no test
runs against given config, do not run test on all configs when it does not require any
runtime)
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java 2011-08-10
12:07:22 UTC (rev 33760)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java 2011-08-10
12:40:32 UTC (rev 33761)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
@@ -44,7 +45,7 @@
final static DoAfterAllTestsRunListener cleanUp = new DoAfterAllTestsRunListener();
final Filter categoryFilter;
-
+
public static class CategoryFilter extends Filter {
public static CategoryFilter include(Class<?> categoryType) {
return new CategoryFilter(categoryType, null);
@@ -55,8 +56,8 @@
public CategoryFilter(Class<?> includedCategory,
Class<?> excludedCategory) {
- fIncluded= includedCategory;
- fExcluded= excludedCategory;
+ fIncluded = includedCategory;
+ fExcluded = excludedCategory;
}
@Override
@@ -75,7 +76,7 @@
}
private boolean hasCorrectCategoryAnnotation(Description description) {
- List<Class<?>> categories= categories(description);
+ List<Class<?>> categories = categories(description);
if (categories.isEmpty())
return fIncluded == null;
for (Class<?> each : categories)
@@ -88,25 +89,26 @@
}
private List<Class<?>> categories(Description description) {
- ArrayList<Class<?>> categories= new ArrayList<Class<?>>();
+ ArrayList<Class<?>> categories = new ArrayList<Class<?>>();
categories.addAll(Arrays.asList(directCategories(description)));
- //categories.addAll(Arrays.asList(directCategories(parentDescription(description))));
+ //
categories.addAll(Arrays.asList(directCategories(parentDescription(description))));
return categories;
}
private Description parentDescription(Description description) {
// TODO: how heavy are we cringing?
- return Description.createSuiteDescription(description.getTestClass());
+ return Description.createSuiteDescription(description
+ .getTestClass());
}
private Class<?>[] directCategories(Description description) {
- Category annotation= description.getAnnotation(Category.class);
+ Category annotation = description.getAnnotation(Category.class);
if (annotation == null)
return new Class<?>[0];
return annotation.value();
}
- }
-
+ }
+
class ReqAwareClassRunner extends BlockJUnit4ClassRunner {
private final TestConfiguration config;
private final List<RequirementBase> requirements;
@@ -117,26 +119,31 @@
super(klass);
this.requirements = requirements;
this.config = config;
-
+
try {
filter(categoryFilter);
} catch (NoTestsRemainException e) {
// TODO Auto-generated catch block
throw new InitializationError(e);
}
-
+
}
+ public List<RequirementBase> getRequirements() {
+ return Collections.unmodifiableList(this.requirements);
+ }
+
@Override
protected List<FrameworkMethod> computeTestMethods() {
- List<FrameworkMethod> testMethods =
getTestClass().getAnnotatedMethods(Test.class);
+ List<FrameworkMethod> testMethods = getTestClass()
+ .getAnnotatedMethods(Test.class);
for (FrameworkMethod method : testMethods) {
method.getAnnotation(Category.class);
}
return testMethods;
-
+
}
-
+
@Override
public void run(RunNotifier notifier) {
// planned test counter must know about all tests (methods) within a
@@ -196,15 +203,25 @@
if (!this.config.equals(TestConfigurator.currentConfig)) {
TestConfigurator.currentConfig = this.config;
}
- log.info("class "+klass.getCanonicalName());
- List<RequirementBase> reqs = TestConfigurator.getClassRequirements(klass);
+ log.info("class " + klass.getCanonicalName());
+ List<RequirementBase> reqs = TestConfigurator
+ .getClassRequirements(klass);
if (reqs != null) {
- SWTBotTestRequires anno = klass.getAnnotation(SWTBotTestRequires.class);
- if (anno!=null && anno.runOnce() && cleanUp.isClassPlanned(klass)) {
- // class is already planned to run and contains annotation runOnce
- log.info("runOnce=true, class already planned");
- log.info("Skipped");
- return null;
+ if (cleanUp.isClassPlanned(klass)) {
+ if (TestConfigurator.isRequiresRunOnce(klass)) {
+ // class is already scheduled to run and contains
+ // annotation runOnce
+ log.info("runOnce=true, class already planned");
+ log.info("Skipped");
+ return null;
+ }
+ if (!TestConfigurator.isRequiresAnyRuntime(klass)) {
+ // class is scheduled and does not require any runtime, thus
+ // no need to run it against other configuration
+ log.info("no runtimes required + class already planned");
+ log.info("Skipped");
+ return null;
+ }
}
log.info("OK");
// increment number of tests planned to run by 1 (class contains
@@ -222,7 +239,8 @@
/**
* listener which listens to test runs, does some cleanup after all tests
- * have run it also holds set of all classes which run (usefull for runOnce annotation)
+ * have run it also holds set of all classes which run (usefull for runOnce
+ * annotation)
*
* @author lzoubek
*
@@ -238,13 +256,15 @@
public void incrPlanned() {
testsAboutToRun += 1;
}
+
/**
* adds class to the list of skipped classes
+ *
* @param klass
*/
public void addSkippedClass(Class<?> klass) {
skippedClasses.add(klass.getName());
-
+
}
public void incrPlanned(int amount) {
@@ -262,24 +282,31 @@
public int getFinished() {
return testsFinished;
}
+
private Set<String> classes = new HashSet<String>();
+
/**
* adds class to runList - as it is planned to run
+ *
* @param klass
*/
public void addClass(Class<?> klass) {
classes.add(klass.getName());
}
+
public boolean isClassPlanned(Class<?> klass) {
return classes.contains(klass.getName());
}
+
/**
* set of classes that has been skipped (annotations not met etc)
*/
private Set<String> skippedClasses = new TreeSet<String>();
+
private void reportSkippedClasses() {
Set<String> finalized = new TreeSet<String>();
- // lets figure out if a class that has been at least once skipped was not planned
+ // lets figure out if a class that has been at least once skipped
+ // was not planned
for (String clazz : skippedClasses) {
if (!classes.contains(clazz)) {
finalized.add(clazz);
@@ -288,17 +315,18 @@
if (!finalized.isEmpty()) {
log.info("Several test classes have been skipped, see head of log to figure out
why it happened");
for (String clazz : finalized) {
- log.info(" * "+clazz);
+ log.info(" * " + clazz);
}
}
}
+
@Override
public void testFinished(Description description) throws Exception {
incrFinished();
log.info("Finished test : " + description.getDisplayName());
log.info("Finished tests : " + getFinished() + "/" +
getPlanned());
if (getFinished() >= getPlanned()) {
- log.info("All tests finished, performing cleanup requirements ");
+ log.info("All tests finished, performing cleanup requirements ");
try {
RequirementBase.createStopServer().fulfill();
RequirementBase.createStopDBServer().fulfill();
@@ -329,7 +357,7 @@
public RequirementAwareSuite(Class<?> klass) throws Throwable {
super(klass, Collections.<Runner> emptyList());
log.info("Loading test configurations");
-
+
for (Entry<Object, Object> entry : TestConfigurator.multiProperties
.entrySet()) {
try {
@@ -338,23 +366,30 @@
String suiteName = config.getPropName() + " - "
+ klass.getCanonicalName();
log.info("Determine whether test classes meet configuration");
- runners.add(new NamedSuite(klass,
- new RequirementAwareRunnerBuilder(config), suiteName));
+ NamedSuite suite = new NamedSuite(klass,new RequirementAwareRunnerBuilder(config),
suiteName);
+ if (suite.getRunnerCount()>0) {
+ log.info("Suite (configuration) '"+suiteName+"' initialized
with "+suite.getRunnerCount()+" runners.");
+ log.info(suite.getRunnerCount());
+ runners.add(suite);
+ config.initialize();
+ }
+ else {
+ log.info("Suite (configuration) '"+suiteName+"' skipped, no
runners");
+ }
} catch (Exception ex) {
log.error("Error loading test configuration", ex);
- throw ex;
+ throw ex;
}
}
-
+
try {
categoryFilter = new CategoryFilter(getIncludedCategory(klass),
- getExcludedCategory(klass));
+ getExcludedCategory(klass));
filter(categoryFilter);
-
+
} catch (NoTestsRemainException e) {
throw new InitializationError(e);
}
-
}
@Override
@@ -370,21 +405,28 @@
super(klass, builder);
this.suiteName = name;
}
+ /**
+ * gets count of test runners within this suite
+ * @return
+ */
+ public int getRunnerCount() {
+ return getChildren().size();
+ }
@Override
protected String getName() {
return suiteName;
}
+ }
- }
-
private Class<?> getIncludedCategory(Class<?> klass) {
- IncludeCategory annotation= klass.getAnnotation(IncludeCategory.class);
+ IncludeCategory annotation = klass.getAnnotation(IncludeCategory.class);
return annotation == null ? null : annotation.value();
}
private Class<?> getExcludedCategory(Class<?> klass) {
- ExcludeCategory annotation= klass.getAnnotation(ExcludeCategory.class);
+ ExcludeCategory annotation = klass.getAnnotation(ExcludeCategory.class);
return annotation == null ? null : annotation.value();
}
+
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ESBBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ESBBean.java 2011-08-10
12:07:22 UTC (rev 33760)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ESBBean.java 2011-08-10
12:40:32 UTC (rev 33761)
@@ -5,10 +5,6 @@
this.key = TestConfigurator.Keys.ESB;
}
- public static ESBBean fromString(String propValue, String url) throws Exception {
- return (ESBBean)fromString(propValue, url, new ESBBean());
- }
-
public static ESBBean fromString(String propValue) throws Exception {
return (ESBBean)fromString(propValue, new ESBBean());
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/RuntimeBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/RuntimeBean.java 2011-08-10
12:07:22 UTC (rev 33760)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/RuntimeBean.java 2011-08-10
12:40:32 UTC (rev 33761)
@@ -36,16 +36,14 @@
}
}
- protected static RuntimeBean fromString(String propValue, String url, RuntimeBean bean)
throws Exception {
- bean = fromString(propValue, bean);
- if (bean!=null && url!=null) {
+ protected void getRuntime(String url) throws Exception {
+ if (url!=null) {
String runtimeFile = downloadRuntime(url);
if (runtimeFile!=null) {
- File runtimeHomeAbs = new File(bean.runtimeHome).getAbsoluteFile();
+ File runtimeHomeAbs = new File(runtimeHome).getAbsoluteFile();
FileHelper.unzipArchive(new File(runtimeFile), runtimeHomeAbs.getParentFile());
}
}
- return bean;
}
@Override
public String toString() {
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ServerBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ServerBean.java 2011-08-10
12:07:22 UTC (rev 33760)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ServerBean.java 2011-08-10
12:40:32 UTC (rev 33761)
@@ -21,15 +21,14 @@
* home of app server located in remote system
*/
public String remoteHome;
- public static ServerBean fromString(String propValue, String url) throws Exception {
- ServerBean bean = fromString(propValue);
- if (bean!=null && url!=null) {
+ public void getRuntime (String url) throws Exception {
+ if (url!=null) {
String runtimeFile = downloadRuntime(url);
if (runtimeFile!=null) {
// where to unzip it?
File runtimeOutput;
- File runtimeHomeAbs = new File(bean.runtimeHome).getAbsoluteFile();
- if (TestConfigurator.Values.SERVER_TYPE_JBOSSAS.equals(bean.type)) {
+ File runtimeHomeAbs = new File(runtimeHome).getAbsoluteFile();
+ if (TestConfigurator.Values.SERVER_TYPE_JBOSSAS.equals(type)) {
runtimeOutput=runtimeHomeAbs.getParentFile();
}
else {
@@ -38,7 +37,6 @@
FileHelper.unzipArchive(new File(runtimeFile), runtimeOutput);
}
}
- return bean;
}
/**
* creates bean instance from property string
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java 2011-08-10
12:07:22 UTC (rev 33760)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java 2011-08-10
12:40:32 UTC (rev 33761)
@@ -65,15 +65,13 @@
substSystemProperties();
java = JavaBean.fromString(getProperty(Keys.JAVA));
printConfig(Keys.JAVA, java);
- server = ServerBean.fromString(getProperty(Keys.SERVER),
- getProperty(Keys.SERVER + TestConfigurator.RUNTIME_URL_SUFFIX));
+ server = ServerBean.fromString(getProperty(Keys.SERVER));
printConfig(Keys.SERVER, server);
remoteSystem = RemoteSystemBean.fromString(getProperty(Keys.RS));
printConfig(Keys.RS, remoteSystem);
seam = SeamBean.fromString(getProperty(Keys.SEAM));
printConfig(Keys.SEAM, seam);
- esb = ESBBean.fromString(getProperty(Keys.ESB),
- getProperty(Keys.ESB + TestConfigurator.RUNTIME_URL_SUFFIX));
+ esb = ESBBean.fromString(getProperty(Keys.ESB));
printConfig(Keys.ESB, esb);
jbpm = JBPMBean.fromString(getProperty(Keys.JBPM));
printConfig(Keys.JBPM, jbpm);
@@ -81,8 +79,26 @@
printConfig(Keys.DB, db);
secureStorage = SecureStorage.fromString(Keys.SS, getProperty(Keys.SS));
printConfig("Secure Storage", secureStorage);
+ }
+ /**
+ * initializes this configuration - runtimes, downloaded, homes checked
+ */
+ public void initialize() throws Exception {
+ getRuntime(server);
+ getRuntime(esb);
+ getRuntime(seam);
checkConfig();
}
+ /**
+ * attempts to get (download) runtime zip for given bean
+ * @param bean
+ * @throws Exception
+ */
+ private void getRuntime(RuntimeBean bean) throws Exception {
+ if (bean!=null) {
+ bean.getRuntime(getProperty(bean.key+TestConfigurator.RUNTIME_URL_SUFFIX));
+ }
+ }
/**
* replaces system properties in configuration property values
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java 2011-08-10
12:07:22 UTC (rev 33760)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java 2011-08-10
12:40:32 UTC (rev 33761)
@@ -80,12 +80,12 @@
boolean loadDefault = true;
try {
- Pattern configMatch = Pattern.compile("nomatch");
+ Pattern configMatch = Pattern.compile("");
try {
- configMatch = Pattern.compile(System.getProperty(CONFIGURATIONS_IGNORE,
"nomatch"));
+ configMatch = Pattern.compile(System.getProperty(CONFIGURATIONS_IGNORE,
""));
}
catch (Exception ex) {
- log.error("Error parsing property "+CONFIGURATIONS_IGNORE,ex);
+ log.error("Error parsing regex property "+CONFIGURATIONS_IGNORE,ex);
}
// try to load from file first
String propFile = System.getProperty(SWTBOT_TEST_PROPERTIES_FILE,
@@ -316,8 +316,35 @@
}
return RequirementBase.prepareDB();
}
-
/**
+ * returns true if given class requires any of all possible runtimes
+ * @param klass
+ * @return
+ */
+ public static boolean isRequiresAnyRuntime(Class<?> klass) {
+ SWTBotTestRequires an = klass
+ .getAnnotation(SWTBotTestRequires.class);
+ if (an==null) {
+ return false;
+ }
+ return an.db().required() || an.esb().required()
+ || an.jbpm().required() || an.seam().required()
+ || an.server().required();
+ }
+ /**
+ * returns true if given class has {@link SWTBotTestRequires#runOnce()} annotation set
to true
+ * @param klass
+ * @return
+ */
+ public static boolean isRequiresRunOnce(Class<?> klass) {
+ SWTBotTestRequires an = klass
+ .getAnnotation(SWTBotTestRequires.class);
+ if (an==null) {
+ return false;
+ }
+ return an.runOnce();
+ }
+ /**
* returns list of requirements if given class (Test) can run, all this is
* done by exploring class'es annotations (see {@link SWTBotTestRequires}) and check
against
* current configuration