You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2019/05/15 21:43:46 UTC
[geode] branch develop updated: GEODE-6771: Have ProcessWrapper
implement Consumer (#3588)
This is an automated email from the ASF dual-hosted git repository.
jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new ee4b105 GEODE-6771: Have ProcessWrapper implement Consumer (#3588)
ee4b105 is described below
commit ee4b1056222c21330fa128879b5af53a52b9bbd9
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Wed May 15 14:43:25 2019 -0700
GEODE-6771: Have ProcessWrapper implement Consumer (#3588)
- Log all stdout/stderr from DeprecatedCacheServerLauncherIntegrationTest
java invocations.
- Ensure LogManager is initialized correctly in ProcessLogger
- Clean up manifest jars created by ProcessWrapper
Authored-by: Jens Deppe <jd...@pivotal.io>
---
...precatedCacheServerLauncherIntegrationTest.java | 1 +
.../junit/rules/gfsh/internal/ProcessLogger.java | 3 +++
.../geode/test/process/ProcessStreamReader.java | 14 ++++-------
.../apache/geode/test/process/ProcessWrapper.java | 27 ++++++++++++++++++----
4 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/DeprecatedCacheServerLauncherIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/DeprecatedCacheServerLauncherIntegrationTest.java
index cbcbf6b..8148503 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/DeprecatedCacheServerLauncherIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/DeprecatedCacheServerLauncherIntegrationTest.java
@@ -446,6 +446,7 @@ public class DeprecatedCacheServerLauncherIntegrationTest {
throws InterruptedException, TimeoutException {
ProcessWrapper processWrapper = new ProcessWrapper.Builder()
.mainClass(CacheServerLauncher.class).mainArguments(args).build();
+ processWrapper.setConsumer(c -> logger.info(c));
processWrapper.execute();
if (regex != null) {
processWrapper.waitForOutputToMatch(regex, 2 * 60 * 1000);
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/ProcessLogger.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/ProcessLogger.java
index 81be549..e84ba55 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/ProcessLogger.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/ProcessLogger.java
@@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LoggerContext;
@@ -62,6 +63,8 @@ public class ProcessLogger {
}
private static LoggerContext createLoggerContext() {
+ LogManager.shutdown();
+
ConfigurationBuilder<BuiltConfiguration> builder =
ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setStatusLevel(Level.ERROR);
diff --git a/geode-junit/src/main/java/org/apache/geode/test/process/ProcessStreamReader.java b/geode-junit/src/main/java/org/apache/geode/test/process/ProcessStreamReader.java
index efe317c..e0b2444 100755
--- a/geode-junit/src/main/java/org/apache/geode/test/process/ProcessStreamReader.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/process/ProcessStreamReader.java
@@ -18,8 +18,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.List;
-import java.util.Queue;
+import java.util.function.Consumer;
/**
* Reads the output from a process stream and stores it for test validation.
@@ -34,17 +33,15 @@ public class ProcessStreamReader extends Thread {
private final String command;
private final BufferedReader reader;
- private final Queue<String> lineBuffer;
- private final List<String> allLines;
+ private final Consumer<String> consumer;
private int lineCount = 0;
public ProcessStreamReader(final String command, final InputStream stream,
- final Queue<String> lineBuffer, final List<String> allLines) {
+ final Consumer<String> consumer) {
this.command = command;
this.reader = new BufferedReader(new InputStreamReader(stream));
- this.lineBuffer = lineBuffer;
- this.allLines = allLines;
+ this.consumer = consumer;
}
@Override
@@ -59,8 +56,7 @@ public class ProcessStreamReader extends Thread {
String line;
while ((line = this.reader.readLine()) != null) {
this.lineCount++;
- this.lineBuffer.offer(line);
- this.allLines.add(line);
+ consumer.accept(line);
}
// EOF
diff --git a/geode-junit/src/main/java/org/apache/geode/test/process/ProcessWrapper.java b/geode-junit/src/main/java/org/apache/geode/test/process/ProcessWrapper.java
index c523fe3..76071c3 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/process/ProcessWrapper.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/process/ProcessWrapper.java
@@ -38,6 +38,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
@@ -55,7 +56,7 @@ import org.apache.geode.internal.logging.LogService;
*
* @since GemFire 4.1.1
*/
-public class ProcessWrapper {
+public class ProcessWrapper implements Consumer<String> {
private static final Logger logger = LogService.getLogger();
private static final long PROCESS_TIMEOUT_MILLIS = 10 * 60 * 1000L; // 10 minutes
@@ -86,6 +87,7 @@ public class ProcessWrapper {
private Thread processThread;
private ProcessStreamReader stdout;
private ProcessStreamReader stderr;
+ private Consumer<String> consumer;
private ProcessWrapper(final String[] jvmArguments, final Class<?> mainClass,
final String[] mainArguments, final boolean useMainLauncher, final boolean headless,
@@ -97,8 +99,22 @@ public class ProcessWrapper {
this.headless = headless;
this.timeoutMillis = timeoutMillis;
- this.lineBuffer = new LinkedBlockingQueue<String>();
- this.allLines = Collections.synchronizedList(new ArrayList<String>());
+ this.lineBuffer = new LinkedBlockingQueue<>();
+ this.allLines = Collections.synchronizedList(new ArrayList<>());
+ }
+
+ public void setConsumer(Consumer<String> consumer) {
+ this.consumer = consumer;
+ }
+
+ @Override
+ public void accept(String line) {
+ this.lineBuffer.offer(line);
+ this.allLines.add(line);
+
+ if (consumer != null) {
+ consumer.accept(line);
+ }
}
public ProcessStreamReader getStandardOutReader() {
@@ -347,9 +363,9 @@ public class ProcessWrapper {
logger.info("Starting " + commandString);
final ProcessStreamReader stdOut = new ProcessStreamReader(commandString,
- this.process.getInputStream(), this.lineBuffer, this.allLines);
+ this.process.getInputStream(), this);
final ProcessStreamReader stdErr = new ProcessStreamReader(commandString,
- this.process.getErrorStream(), this.lineBuffer, this.allLines);
+ this.process.getErrorStream(), this);
this.stdout = stdOut;
this.stderr = stdErr;
@@ -498,6 +514,7 @@ public class ProcessWrapper {
JarOutputStream jos = null;
try {
File jarFile = manifestJar.toFile();
+ jarFile.deleteOnExit();
OutputStream os = new FileOutputStream(jarFile);
jos = new JarOutputStream(os, manifest);
} catch (IOException e) {