Skip to content

Commit c6eba11

Browse files
committed
add debug logging
1 parent ec213a6 commit c6eba11

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

e2e-tests/src/test/java/dev/streamx/cli/StreamxCliPublicationIT.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.streamx.cli;
22

33
import static dev.streamx.cli.test.tools.ResourcePathResolver.absolutePath;
4+
import static org.assertj.core.api.Assertions.fail;
45

56
import dev.streamx.cli.test.tools.terminal.TerminalCommandRunner;
67
import dev.streamx.cli.test.tools.terminal.process.ShellProcess;
@@ -10,10 +11,14 @@
1011
import jakarta.inject.Inject;
1112
import jakarta.inject.Named;
1213
import java.io.IOException;
14+
import java.nio.charset.StandardCharsets;
1315
import java.nio.file.Files;
1416
import java.nio.file.Path;
1517
import java.time.Duration;
18+
import org.apache.commons.io.IOUtils;
19+
import org.apache.commons.lang3.StringUtils;
1620
import org.eclipse.microprofile.config.inject.ConfigProperty;
21+
import org.jboss.logging.Logger;
1722
import org.junit.jupiter.api.BeforeAll;
1823
import org.junit.jupiter.api.Test;
1924
import org.junit.jupiter.api.TestInstance;
@@ -67,7 +72,19 @@ public void shouldPublishAndUnpublishPageUsingStreamOperation() {
6772
"Sent com.streamx.blueprints.page.published.v1 event using stream with key 'hello.html'"
6873
);
6974

70-
validateStreamxPage("hello.html", "<b>Hello World!</b>");
75+
// TODO remove the catch
76+
try {
77+
validateStreamxPage("hello.html", "<b>Hello World!</b>");
78+
} catch (Throwable t) {
79+
String dockerPsOutput = readProcessOutput("docker ps");
80+
String containerLine = dockerPsOutput.lines()
81+
.filter(line -> line.contains("web-server-sink"))
82+
.findFirst().orElseThrow();
83+
String containerId = StringUtils.substringBefore(containerLine, " ");
84+
String logs = readProcessOutput("docker logs " + containerId);
85+
Logger log = Logger.getLogger(StreamxCliPublicationIT.class);
86+
log.info("\n---- DOCKER CONTAINER LOGS ---\n" + logs);
87+
}
7188

7289
runStreamxIngestionCommand(
7390
"stream_v2",
@@ -78,6 +95,18 @@ public void shouldPublishAndUnpublishPageUsingStreamOperation() {
7895
validateStreamxPageNotAvailable("hello.html");
7996
}
8097

98+
private static String readProcessOutput(String command) {
99+
String[] words = command.split(" ");
100+
ProcessBuilder builder = new ProcessBuilder(words);
101+
builder.redirectErrorStream(true); // merge STDOUT + STDERR
102+
try {
103+
Process process = builder.start();
104+
return IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8);
105+
} catch (IOException ex) {
106+
return fail("Error reading output of command", ex);
107+
}
108+
}
109+
81110
@Test
82111
public void shouldPublishAndUnpublishPageUsingBatchOperation() {
83112
runStreamxIngestionCommand(

0 commit comments

Comments
 (0)