Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private void startPostmaster(Map<String, String> connectConfig) throws IOExcepti
final Process postmaster = builder.start();

if (outputRedirector.type() == ProcessBuilder.Redirect.Type.PIPE) {
ProcessOutputLogger.logOutput(LOG, postmaster);
ProcessOutputLogger.logOutput(LOG, postmaster, "pg_ctl");
}

LOG.info("{} postmaster started as {} on port {}. Waiting up to {} for server startup to finish.", instanceId, postmaster.toString(), port, pgStartupWait);
Expand Down Expand Up @@ -573,20 +573,22 @@ public EmbeddedPostgres start() throws IOException {
}
}

private static List<String> system(String... command)
private void system(String... command)
{
try {
final ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectError(ProcessBuilder.Redirect.PIPE);
builder.redirectOutput(ProcessBuilder.Redirect.PIPE);
builder.redirectErrorStream(true);
builder.redirectError(errorRedirector);
builder.redirectOutput(outputRedirector);
final Process process = builder.start();

if (outputRedirector.type() == ProcessBuilder.Redirect.Type.PIPE) {
String processName = command[0].replaceAll("^.*[\\\\/](\\w+)(\\.exe)?$", "$1");
ProcessOutputLogger.logOutput(LOG, process, processName);
}
if (0 != process.waitFor()) {
throw new IllegalStateException(String.format("Process %s failed%n%s", Arrays.asList(command), IOUtils.toString(process.getErrorStream())));
}
try (InputStream stream = process.getInputStream()) {
return IOUtils.readLines(stream);
}
} catch (final RuntimeException e) { // NOPMD
throw e;
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
*/
package io.zonky.test.db.postgres.embedded;

import org.slf4j.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

import org.slf4j.Logger;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
* Read standard output of process and write lines to given {@link Logger} as INFO;
Expand Down Expand Up @@ -61,9 +63,10 @@ public void run() {
}
}

static void logOutput(final Logger logger, final Process process) {
static void logOutput(final Logger logger, final Process process, final String processName) {
final String threadName = isNotBlank(processName) ? processName + "@" + process.hashCode() : process.toString();
final Thread t = new Thread(new ProcessOutputLogger(logger, process));
t.setName("output redirector for " + process);
t.setName(threadName);
t.start();
}
}