Displayed standard error to see checkpoint errors
Closes gh-13
This commit is contained in:
@@ -26,18 +26,31 @@ import java.util.List;
|
||||
* Output from an application.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class Output {
|
||||
|
||||
private final Path path;
|
||||
private final Path outputPath;
|
||||
|
||||
private Output(Path path) {
|
||||
this.path = path;
|
||||
private final Path errorPath;
|
||||
|
||||
private Output(Path outputPath, Path errorPath) {
|
||||
this.outputPath = outputPath;
|
||||
this.errorPath = errorPath;
|
||||
}
|
||||
|
||||
public List<String> lines() {
|
||||
public List<String> outputLines() {
|
||||
try {
|
||||
return Files.readAllLines(this.path);
|
||||
return Files.readAllLines(this.outputPath);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> errorLines() {
|
||||
try {
|
||||
return Files.readAllLines(this.errorPath);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException();
|
||||
@@ -45,13 +58,19 @@ public class Output {
|
||||
}
|
||||
|
||||
public static Output current() {
|
||||
String property = System.getProperty("org.springframework.cr.smoketest.standard-output");
|
||||
if (property == null) {
|
||||
String outputProperty = System.getProperty("org.springframework.cr.smoketest.standard-output");
|
||||
if (outputProperty == null) {
|
||||
throw new IllegalStateException(
|
||||
"Standard output is not available as org.springframework.cr.smoketest.standard-output "
|
||||
+ "system property has not been set");
|
||||
}
|
||||
return new Output(new File(property).toPath());
|
||||
String errorProperty = System.getProperty("org.springframework.cr.smoketest.standard-error");
|
||||
if (errorProperty == null) {
|
||||
throw new IllegalStateException(
|
||||
"Standard error is not available as org.springframework.cr.smoketest.standard-error "
|
||||
+ "system property has not been set");
|
||||
}
|
||||
return new Output(new File(outputProperty).toPath(), new File(errorProperty).toPath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class OutputAssert extends AbstractAssert<OutputAssert, Output> {
|
||||
* @return {@code this} for fluent API
|
||||
*/
|
||||
public OutputAssert hasSingleLineContaining(String contents) {
|
||||
List<String> lines = this.actual.lines();
|
||||
List<String> lines = this.actual.outputLines();
|
||||
List<String> matchingLines = lines.stream().filter((line) -> line.contains(contents)).toList();
|
||||
if (matchingLines.size() != 1) {
|
||||
throwAssertionError(
|
||||
@@ -57,7 +57,7 @@ public class OutputAssert extends AbstractAssert<OutputAssert, Output> {
|
||||
* @return {@code this} for fluent API
|
||||
*/
|
||||
public OutputAssert hasLineContaining(String contents) {
|
||||
List<String> lines = this.actual.lines();
|
||||
List<String> lines = this.actual.outputLines();
|
||||
Optional<String> matchingLines = lines.stream().filter((line) -> line.contains(contents)).findAny();
|
||||
if (matchingLines.isEmpty()) {
|
||||
throwAssertionError(new BasicErrorMessageFactory(
|
||||
@@ -72,7 +72,7 @@ public class OutputAssert extends AbstractAssert<OutputAssert, Output> {
|
||||
* @return {@code this} for fluent API
|
||||
*/
|
||||
public OutputAssert hasLineMatching(String regex) {
|
||||
List<String> lines = this.actual.lines();
|
||||
List<String> lines = this.actual.outputLines();
|
||||
Optional<String> matchingLines = lines.stream().filter((line) -> line.matches(regex)).findAny();
|
||||
if (matchingLines.isEmpty()) {
|
||||
throwAssertionError(new BasicErrorMessageFactory(
|
||||
@@ -87,7 +87,7 @@ public class OutputAssert extends AbstractAssert<OutputAssert, Output> {
|
||||
* @return {@code this} for fluent API
|
||||
*/
|
||||
public OutputAssert hasNoLinesContaining(String contents) {
|
||||
List<String> lines = this.actual.lines();
|
||||
List<String> lines = this.actual.outputLines();
|
||||
boolean noMatch = lines.stream().noneMatch((line) -> line.contains(contents));
|
||||
if (!noMatch) {
|
||||
throwAssertionError(new BasicErrorMessageFactory(
|
||||
|
||||
@@ -49,7 +49,7 @@ final class ApplicationUnderTest {
|
||||
List<Pattern> portPatterns = List.of(Pattern.compile("Tomcat started on port ([0-9]+)"),
|
||||
Pattern.compile("Netty started on port ([0-9]+)"), Pattern.compile("Jetty started on port ([0-9]+)"),
|
||||
Pattern.compile("Undertow started on port ([0-9]+)"));
|
||||
List<String> lines = Output.current().lines();
|
||||
List<String> lines = Output.current().outputLines();
|
||||
for (String line : lines) {
|
||||
for (Pattern portPattern : portPatterns) {
|
||||
Matcher matcher = portPattern.matcher(line);
|
||||
|
||||
@@ -45,27 +45,35 @@ class AwaitApplication implements BeforeAllCallback {
|
||||
public void beforeAll(ExtensionContext context) throws Exception {
|
||||
Output output = Output.current();
|
||||
long end = Instant.now().plus(START_TIMEOUT).toEpochMilli();
|
||||
List<String> lines = null;
|
||||
List<String> outputLines = null;
|
||||
while (System.currentTimeMillis() < end) {
|
||||
lines = output.lines();
|
||||
for (String line : lines) {
|
||||
outputLines = output.outputLines();
|
||||
for (String line : outputLines) {
|
||||
if (this.APPLICATION_STARTED.matcher(line).find() || this.APPLICATION_RE_STARTED.matcher(line).find()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
StringBuilder message = new StringBuilder(
|
||||
"Started log message was not detected within " + START_TIMEOUT.getSeconds() + "s in output:");
|
||||
message.append("\n\n");
|
||||
if (lines == null || lines.isEmpty()) {
|
||||
"Started log message was not detected within " + START_TIMEOUT.getSeconds() + "s:.");
|
||||
message.append("\n\nStandard output:\n");
|
||||
if (outputLines == null || outputLines.isEmpty()) {
|
||||
message.append("<< none >>");
|
||||
}
|
||||
else {
|
||||
for (String line : lines) {
|
||||
for (String line : outputLines) {
|
||||
message.append(line + "\n");
|
||||
}
|
||||
}
|
||||
message.append("\n");
|
||||
List<String> errorLines = output.errorLines();
|
||||
if (!errorLines.isEmpty()) {
|
||||
message.append("\nStandard error:\n");
|
||||
for (String line : errorLines) {
|
||||
message.append(line + "\n");
|
||||
}
|
||||
message.append("\n");
|
||||
}
|
||||
System.err.println(message.toString());
|
||||
throw new IllegalStateException(message.toString());
|
||||
}
|
||||
|
||||
@@ -275,6 +275,8 @@ public class CrSmokeTestPlugin implements Plugin<Project> {
|
||||
.withPropertyName("applicationBinary");
|
||||
task.systemProperty("org.springframework.cr.smoketest.standard-output",
|
||||
startTask.get().getOutputFile().get().getAsFile().getAbsolutePath());
|
||||
task.systemProperty("org.springframework.cr.smoketest.standard-error",
|
||||
startTask.get().getErrorFile().get().getAsFile().getAbsolutePath());
|
||||
task.finalizedBy(stopTask);
|
||||
task.setDescription("Runs the app test suite against the " + type.description + " application.");
|
||||
task.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
|
||||
|
||||
Reference in New Issue
Block a user