NIHVIVO-222 Start converting the output data collection from scanning the log to using a Listener.
This commit is contained in:
parent
2e8e7ee7dd
commit
2e0e61dd86
6 changed files with 244 additions and 61 deletions
|
@ -6,8 +6,6 @@ import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -19,18 +17,12 @@ import java.util.regex.Pattern;
|
||||||
* Extract any summary information from the log file.
|
* Extract any summary information from the log file.
|
||||||
*/
|
*/
|
||||||
public class LogStats {
|
public class LogStats {
|
||||||
private static final Pattern START_TIME_PATTERN = Pattern
|
|
||||||
.compile("(.*) Run started.");
|
|
||||||
private static final Pattern END_TIME_PATTERN = Pattern
|
|
||||||
.compile("(.*) Testing complete.");
|
|
||||||
private static final Pattern SUITE_NAME_PATTERN = Pattern
|
private static final Pattern SUITE_NAME_PATTERN = Pattern
|
||||||
.compile("Running suite (.*)");
|
.compile("Running suite (.*)");
|
||||||
private static final Pattern ERROR_PATTERN = Pattern
|
private static final Pattern ERROR_PATTERN = Pattern
|
||||||
.compile("ERROR\\s+(.*)");
|
.compile("ERROR\\s+(.*)");
|
||||||
private static final Pattern WARNING_PATTERN = Pattern
|
private static final Pattern WARNING_PATTERN = Pattern
|
||||||
.compile("WARN\\s+(.*)");
|
.compile("WARN\\s+(.*)");
|
||||||
private static final SimpleDateFormat dateParser = new SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss.SSS");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method.
|
* Factory method.
|
||||||
|
@ -39,8 +31,6 @@ public class LogStats {
|
||||||
return new LogStats(logFile);
|
return new LogStats(logFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long startTime;
|
|
||||||
private long endTime;
|
|
||||||
private final List<String> suiteNames = new ArrayList<String>();
|
private final List<String> suiteNames = new ArrayList<String>();
|
||||||
private final List<String> errors = new ArrayList<String>();
|
private final List<String> errors = new ArrayList<String>();
|
||||||
private final List<String> warnings = new ArrayList<String>();
|
private final List<String> warnings = new ArrayList<String>();
|
||||||
|
@ -53,27 +43,17 @@ public class LogStats {
|
||||||
reader = new BufferedReader(new FileReader(logFile));
|
reader = new BufferedReader(new FileReader(logFile));
|
||||||
while (null != (line = reader.readLine())) {
|
while (null != (line = reader.readLine())) {
|
||||||
Matcher m;
|
Matcher m;
|
||||||
m = START_TIME_PATTERN.matcher(line);
|
m = SUITE_NAME_PATTERN.matcher(line);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
startTime = parseTime(m.group(1));
|
suiteNames.add(m.group(1));
|
||||||
} else {
|
} else {
|
||||||
m = END_TIME_PATTERN.matcher(line);
|
m = ERROR_PATTERN.matcher(line);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
endTime = parseTime(m.group(1));
|
errors.add(m.group(1));
|
||||||
} else {
|
} else {
|
||||||
m = SUITE_NAME_PATTERN.matcher(line);
|
m = WARNING_PATTERN.matcher(line);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
suiteNames.add(m.group(1));
|
warnings.add(m.group(1));
|
||||||
} else {
|
|
||||||
m = ERROR_PATTERN.matcher(line);
|
|
||||||
if (m.matches()) {
|
|
||||||
errors.add(m.group(1));
|
|
||||||
} else {
|
|
||||||
m = WARNING_PATTERN.matcher(line);
|
|
||||||
if (m.matches()) {
|
|
||||||
warnings.add(m.group(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,15 +73,6 @@ public class LogStats {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long parseTime(String timeString) {
|
|
||||||
try {
|
|
||||||
return dateParser.parse(timeString).getTime();
|
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasErrors() {
|
public boolean hasErrors() {
|
||||||
return !errors.isEmpty();
|
return !errors.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -118,16 +89,4 @@ public class LogStats {
|
||||||
return Collections.unmodifiableCollection(warnings);
|
return Collections.unmodifiableCollection(warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStartTime() {
|
|
||||||
return startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getEndTime() {
|
|
||||||
return endTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getElapsedTime() {
|
|
||||||
return Math.abs(endTime - startTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.utilities.testrunner.listener.Listener;
|
import edu.cornell.mannlib.vitro.utilities.testrunner.listener.Listener;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.output.OutputManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the Selenium test suites. Provide the properties file and perhaps an
|
* Run the Selenium test suites. Provide the properties file and perhaps an
|
||||||
|
|
|
@ -0,0 +1,202 @@
|
||||||
|
package edu.cornell.mannlib.vitro.utilities.testrunner.output;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.listener.Listener;
|
||||||
|
|
||||||
|
public class OutputDataModel implements Listener {
|
||||||
|
private boolean runCompleted;
|
||||||
|
private long startTime;
|
||||||
|
private long endTime;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Listener methods that affect the data model
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runStarted() {
|
||||||
|
startTime = new Date().getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runEndTime() {
|
||||||
|
endTime = new Date().getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runStopped() {
|
||||||
|
runCompleted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Accessor methods
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
public boolean isRunCompleted() {
|
||||||
|
return runCompleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getElapsedTime() {
|
||||||
|
if ((startTime == 0) || (endTime == 0)) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return endTime - startTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Listener methods that don't affect the data model
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suiteIgnored(File suite) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suiteAdded(File suite) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runFailed(Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanOutputStart(File outputDirectory) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanOutputFailed(File outputDirectory, IOException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanOutputStop(File outputDirectory) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void webappStopping(String tomcatStopCommand) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void webappStopFailed(int returnCode) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void webappWaitingForStop(int tomcatStopDelay) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void webappStopped() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropDatabaseStarting(String statement) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropDatabaseFailed(int returnCode) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropDatabaseComplete() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadDatabaseStarting(String statement) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadDatabaseFailed(int returnCode) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadDatabaseComplete() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void webappStarting(String tomcatStartCommand) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void webappStartFailed(int returnCode) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void webappWaitingForStart(int tomcatStartDelay) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void webappStarted() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void subProcessStart(List<String> command) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void subProcessStartInBackground(List<String> command) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void subProcessStdout(String string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void subProcessErrout(String string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void subProcessStop(List<String> command) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suiteStarted(File suiteDir) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suiteTestingStarted(File suiteDir) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suiteFailed(File suiteDir, int returnCode) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suiteFailed(File suiteDir, Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suiteTestingStopped(File suiteDir) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suiteStopped(File suiteDir) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanUploadStart(File uploadDirectory) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanUploadFailed(File uploadDirectory, IOException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanUploadStop(File uploadDirectory) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logWarning(String message) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.utilities.testrunner;
|
package edu.cornell.mannlib.vitro.utilities.testrunner.output;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
|
@ -8,7 +8,11 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.utilities.testrunner.listener.Listener;
|
import edu.cornell.mannlib.vitro.utilities.testrunner.FileHelper;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.LogStats;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.SeleniumRunnerParameters;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.Status;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.SuiteStats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the contents of the output area. Removes old files prior to a run.
|
* Manages the contents of the output area. Removes old files prior to a run.
|
||||||
|
@ -16,11 +20,12 @@ import edu.cornell.mannlib.vitro.utilities.testrunner.listener.Listener;
|
||||||
*/
|
*/
|
||||||
public class OutputManager {
|
public class OutputManager {
|
||||||
private final SeleniumRunnerParameters parms;
|
private final SeleniumRunnerParameters parms;
|
||||||
private final Listener listener;
|
private final OutputDataModel dataModel;
|
||||||
|
|
||||||
public OutputManager(SeleniumRunnerParameters parms) {
|
public OutputManager(SeleniumRunnerParameters parms) {
|
||||||
this.parms = parms;
|
this.parms = parms;
|
||||||
this.listener = parms.getListener();
|
this.dataModel = new OutputDataModel();
|
||||||
|
parms.addListener(this.dataModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,7 +33,7 @@ public class OutputManager {
|
||||||
*/
|
*/
|
||||||
public void cleanOutputDirectory() throws IOException {
|
public void cleanOutputDirectory() throws IOException {
|
||||||
File outputDirectory = parms.getOutputDirectory();
|
File outputDirectory = parms.getOutputDirectory();
|
||||||
listener.cleanOutputStart(outputDirectory);
|
parms.getListener().cleanOutputStart(outputDirectory);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (File file : outputDirectory.listFiles()) {
|
for (File file : outputDirectory.listFiles()) {
|
||||||
|
@ -48,10 +53,10 @@ public class OutputManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
listener.cleanOutputFailed(outputDirectory, e);
|
parms.getListener().cleanOutputFailed(outputDirectory, e);
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
listener.cleanOutputStop(outputDirectory);
|
parms.getListener().cleanOutputStop(outputDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +77,7 @@ public class OutputManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputSummaryFormatter formatter = new OutputSummaryFormatter(parms);
|
OutputSummaryFormatter formatter = new OutputSummaryFormatter(parms);
|
||||||
formatter.format(log, suites);
|
formatter.format(log, suites, dataModel);
|
||||||
return formatter.figureOverallStatus(log, suites);
|
return formatter.figureOverallStatus(log, suites);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.utilities.testrunner;
|
package edu.cornell.mannlib.vitro.utilities.testrunner.output;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
@ -13,6 +13,11 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.FileHelper;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.LogStats;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.SeleniumRunnerParameters;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.Status;
|
||||||
|
import edu.cornell.mannlib.vitro.utilities.testrunner.SuiteStats;
|
||||||
import edu.cornell.mannlib.vitro.utilities.testrunner.SuiteStats.TestInfo;
|
import edu.cornell.mannlib.vitro.utilities.testrunner.SuiteStats.TestInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +32,7 @@ public class OutputSummaryFormatter {
|
||||||
|
|
||||||
private LogStats log;
|
private LogStats log;
|
||||||
private List<SuiteStats> suites;
|
private List<SuiteStats> suites;
|
||||||
|
private OutputDataModel dataModel;
|
||||||
private Status runStatus;
|
private Status runStatus;
|
||||||
private List<TestInfo> allTests = new ArrayList<TestInfo>();
|
private List<TestInfo> allTests = new ArrayList<TestInfo>();
|
||||||
private int passingTestCount;
|
private int passingTestCount;
|
||||||
|
@ -41,9 +47,11 @@ public class OutputSummaryFormatter {
|
||||||
* Create a summary HTML file from the info contained in this log file and
|
* Create a summary HTML file from the info contained in this log file and
|
||||||
* these suite outputs.
|
* these suite outputs.
|
||||||
*/
|
*/
|
||||||
public void format(LogStats log, List<SuiteStats> suites) {
|
public void format(LogStats log, List<SuiteStats> suites,
|
||||||
|
OutputDataModel dataModel) {
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.suites = suites;
|
this.suites = suites;
|
||||||
|
this.dataModel = dataModel;
|
||||||
this.runStatus = figureOverallStatus(log, suites);
|
this.runStatus = figureOverallStatus(log, suites);
|
||||||
tallyTests();
|
tallyTests();
|
||||||
|
|
||||||
|
@ -134,7 +142,7 @@ public class OutputSummaryFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeHeader(PrintWriter writer) {
|
private void writeHeader(PrintWriter writer) {
|
||||||
String startString = formatDateTime(log.getStartTime());
|
String startString = formatDateTime(dataModel.getStartTime());
|
||||||
|
|
||||||
writer.println("<html>");
|
writer.println("<html>");
|
||||||
writer.println("<head>");
|
writer.println("<head>");
|
||||||
|
@ -159,9 +167,9 @@ public class OutputSummaryFormatter {
|
||||||
String ignoreClass = this.ignoredTests.isEmpty() ? "" : Status.WARN
|
String ignoreClass = this.ignoredTests.isEmpty() ? "" : Status.WARN
|
||||||
.getHtmlClass();
|
.getHtmlClass();
|
||||||
|
|
||||||
String start = formatDateTime(log.getStartTime());
|
String start = formatDateTime(dataModel.getStartTime());
|
||||||
String end = formatDateTime(log.getEndTime());
|
String end = formatDateTime(dataModel.getEndTime());
|
||||||
String elapsed = formatElapsedTime(log.getElapsedTime());
|
String elapsed = formatElapsedTime(dataModel.getElapsedTime());
|
||||||
|
|
||||||
writer.println(" <div class=\"section\">Summary</div>");
|
writer.println(" <div class=\"section\">Summary</div>");
|
||||||
writer.println();
|
writer.println();
|
||||||
|
@ -338,6 +346,10 @@ public class OutputSummaryFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatElapsedTime(long elapsed) {
|
private String formatElapsedTime(long elapsed) {
|
||||||
|
if (elapsed == 0) {
|
||||||
|
return "---";
|
||||||
|
}
|
||||||
|
|
||||||
long elapsedSeconds = elapsed / 1000L;
|
long elapsedSeconds = elapsed / 1000L;
|
||||||
long seconds = elapsedSeconds % 60L;
|
long seconds = elapsedSeconds % 60L;
|
||||||
long elapsedMinutes = elapsedSeconds / 60L;
|
long elapsedMinutes = elapsedSeconds / 60L;
|
||||||
|
@ -357,6 +369,10 @@ public class OutputSummaryFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatDateTime(long dateTime) {
|
private String formatDateTime(long dateTime) {
|
||||||
|
if (dateTime == 0) {
|
||||||
|
return "---";
|
||||||
|
}
|
||||||
|
|
||||||
return dateFormat.format(new Date(dateTime));
|
return dateFormat.format(new Date(dateTime));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue