You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by js...@apache.org on 2017/10/18 16:34:06 UTC

[geode] branch release/1.3.0 updated: GEODE-3859: Simplify API for reading output from a GfshScript

This is an automated email from the ASF dual-hosted git repository.

jstewart pushed a commit to branch release/1.3.0
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/release/1.3.0 by this push:
     new 59f2a73  GEODE-3859: Simplify API for reading output from a GfshScript
59f2a73 is described below

commit 59f2a73d108101744ed7b2d88e8d1c948d19781c
Author: Jared Stewart <js...@pivotal.io>
AuthorDate: Tue Oct 17 14:27:01 2017 -0700

    GEODE-3859: Simplify API for reading output from a GfshScript
    
    (cherry picked from commit 4dd26da)
---
 .../StopServerWithSecurityAcceptanceTest.java      |  8 ++--
 .../geode/test/junit/rules/gfsh/GfshExecution.java | 17 ++------
 .../test/junit/rules/gfsh/internal/OutputLine.java | 45 ++++++++++++++++++++++
 .../rules/gfsh/{ => internal}/ProcessLogger.java   | 40 +++++++++++++------
 .../rules/gfsh/{ => internal}/StreamGobbler.java   |  2 +-
 5 files changed, 81 insertions(+), 31 deletions(-)

diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StopServerWithSecurityAcceptanceTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StopServerWithSecurityAcceptanceTest.java
index 4588ee6..7d5405a 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StopServerWithSecurityAcceptanceTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StopServerWithSecurityAcceptanceTest.java
@@ -60,7 +60,7 @@ public class StopServerWithSecurityAcceptanceTest {
     startCluster();
 
     GfshExecution stopServer = dataReaderCannotStopServer(true);
-    assertThat(stopServer.getStdErrText()).contains("dataReader not authorized for CLUSTER:READ");
+    assertThat(stopServer.getOutputText()).contains("dataReader not authorized for CLUSTER:READ");
   }
 
   @Test
@@ -75,7 +75,7 @@ public class StopServerWithSecurityAcceptanceTest {
     startCluster();
 
     GfshExecution stopServer = dataReaderCannotStopServer(false);
-    assertThat(stopServer.getStdErrText()).contains("dataReader not authorized for CLUSTER:READ");
+    assertThat(stopServer.getOutputText()).contains("dataReader not authorized for CLUSTER:READ");
   }
 
   @Test
@@ -90,7 +90,7 @@ public class StopServerWithSecurityAcceptanceTest {
     startCluster();
 
     GfshExecution stopServer = clusterReaderCannotStopServer(false);
-    assertThat(stopServer.getStdErrText())
+    assertThat(stopServer.getOutputText())
         .contains("clusterRead not authorized for CLUSTER:MANAGE");
   }
 
@@ -99,7 +99,7 @@ public class StopServerWithSecurityAcceptanceTest {
     startCluster();
 
     GfshExecution stopServer = clusterReaderCannotStopServer(true);
-    assertThat(stopServer.getStdErrText())
+    assertThat(stopServer.getOutputText())
         .contains("clusterRead not authorized for CLUSTER:MANAGE");
   }
 
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshExecution.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshExecution.java
index 23d83e6..3c1e130 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshExecution.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshExecution.java
@@ -14,12 +14,9 @@
  */
 package org.apache.geode.test.junit.rules.gfsh;
 
-import static java.util.stream.Collectors.joining;
-
 import java.io.File;
-import java.util.List;
 
-import org.apache.commons.lang.SystemUtils;
+import org.apache.geode.test.junit.rules.gfsh.internal.ProcessLogger;
 
 public class GfshExecution {
   private final Process process;
@@ -32,16 +29,8 @@ public class GfshExecution {
     this.processLogger = new ProcessLogger(process, workingDir.getName());
   }
 
-  public List<String> getStdOutLines() {
-    return processLogger.getStdOutLines();
-  }
-
-  public List<String> getStdErrLines() {
-    return processLogger.getStdErrLines();
-  }
-
-  public String getStdErrText() {
-    return getStdErrLines().stream().collect(joining(SystemUtils.LINE_SEPARATOR));
+  public String getOutputText() {
+    return processLogger.getOutputText();
   }
 
   /**
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/OutputLine.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/OutputLine.java
new file mode 100644
index 0000000..ecf7ca3
--- /dev/null
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/OutputLine.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.test.junit.rules.gfsh.internal;
+
+public class OutputLine {
+  private final String line;
+  private final OutputSource source;
+
+  private OutputLine(String line, OutputSource source) {
+    this.line = line;
+    this.source = source;
+  }
+
+  public static OutputLine fromStdErr(String line) {
+    return new OutputLine(line, OutputSource.STD_ERR);
+  }
+
+  public static OutputLine fromStdOut(String line) {
+    return new OutputLine(line, OutputSource.STD_OUT);
+  }
+
+  public String getLine() {
+    return line;
+  }
+
+  public OutputSource getSource() {
+    return source;
+  }
+
+  public static enum OutputSource {
+    STD_ERR, STD_OUT;
+  }
+}
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/ProcessLogger.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/ProcessLogger.java
similarity index 72%
rename from geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/ProcessLogger.java
rename to geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/ProcessLogger.java
index 2fef0b3..34ae27d 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/ProcessLogger.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/ProcessLogger.java
@@ -12,13 +12,16 @@
  * or implied. See the License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.geode.test.junit.rules.gfsh;
+package org.apache.geode.test.junit.rules.gfsh.internal;
+
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.toList;
 
 import java.util.List;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
-import com.google.common.collect.Lists;
+import org.apache.commons.lang.SystemUtils;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.Filter;
@@ -34,16 +37,15 @@ public class ProcessLogger {
   private static final LoggerContext LOGGER_CONTEXT = createLoggerContext();
   private final Logger logger;
 
-  private final Queue<String> stdOutLines = new ConcurrentLinkedQueue<>();
-  private final Queue<String> stdErrorLines = new ConcurrentLinkedQueue<>();
-  private final StreamGobbler stdOutGobbler;
-  private final StreamGobbler stdErrGobbler;
+  private final Queue<OutputLine> outputLines = new ConcurrentLinkedQueue<>();
 
   public ProcessLogger(Process process, String name) {
     this.logger = LOGGER_CONTEXT.getLogger(name);
 
-    this.stdOutGobbler = new StreamGobbler(process.getInputStream(), this::consumeInfoMessage);
-    this.stdErrGobbler = new StreamGobbler(process.getErrorStream(), this::consumeErrorMessage);
+    StreamGobbler stdOutGobbler =
+        new StreamGobbler(process.getInputStream(), this::consumeInfoMessage);
+    StreamGobbler stdErrGobbler =
+        new StreamGobbler(process.getErrorStream(), this::consumeErrorMessage);
 
     stdOutGobbler.startInNewThread();
     stdErrGobbler.startInNewThread();
@@ -51,12 +53,12 @@ public class ProcessLogger {
 
   private void consumeInfoMessage(String message) {
     logger.info(message);
-    stdOutLines.add(message);
+    outputLines.add(OutputLine.fromStdOut(message));
   }
 
   private void consumeErrorMessage(String message) {
     logger.error(message);
-    stdErrorLines.add(message);
+    outputLines.add(OutputLine.fromStdErr(message));
   }
 
   private static LoggerContext createLoggerContext() {
@@ -80,10 +82,24 @@ public class ProcessLogger {
   }
 
   public List<String> getStdOutLines() {
-    return Lists.newArrayList(stdOutLines.iterator());
+    return getOutputLines(OutputLine.OutputSource.STD_OUT);
   }
 
   public List<String> getStdErrLines() {
-    return Lists.newArrayList(stdErrorLines.iterator());
+    return getOutputLines(OutputLine.OutputSource.STD_ERR);
+  }
+
+  public List<String> getOutputLines() {
+    return outputLines.stream().map(OutputLine::getLine).collect(toList());
+  }
+
+  public String getOutputText() {
+    return outputLines.stream().map(OutputLine::getLine)
+        .collect(joining(SystemUtils.LINE_SEPARATOR));
+  }
+
+  private List<String> getOutputLines(OutputLine.OutputSource source) {
+    return outputLines.stream().filter(line -> line.getSource().equals(source))
+        .map(OutputLine::getLine).collect(toList());
   }
 }
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/StreamGobbler.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/StreamGobbler.java
similarity index 96%
rename from geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/StreamGobbler.java
rename to geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/StreamGobbler.java
index dd6dd59..ce9a02f 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/StreamGobbler.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/internal/StreamGobbler.java
@@ -12,7 +12,7 @@
  * or implied. See the License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.geode.test.junit.rules.gfsh;
+package org.apache.geode.test.junit.rules.gfsh.internal;
 
 import java.io.BufferedReader;
 import java.io.InputStream;

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].