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

dcapwell pushed a commit to branch cassandra-2.2
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cassandra-2.2 by this push:
     new f15c6b8  Backport CASSANDRA-16057: Should update in-jvm dtest to 
expose stdout and stderr for nodetool
f15c6b8 is described below

commit f15c6b8c06c9588bd96615fabfc36b11857cd4bb
Author: Yifan Cai <[email protected]>
AuthorDate: Mon Oct 19 11:09:11 2020 -0700

    Backport CASSANDRA-16057: Should update in-jvm dtest to expose stdout and 
stderr for nodetool
    
    patch by Yifan Cai; reviewed by Alex Petrov, David Capwell for 
CASSANDRA-16057
---
 src/java/org/apache/cassandra/tools/NodeProbe.java | 15 ++++
 src/java/org/apache/cassandra/tools/NodeTool.java  | 52 ++++++++-----
 .../tools/{nodetool/Version.java => Output.java}   | 22 +++---
 .../cassandra/tools/nodetool/BootstrapResume.java  |  4 +-
 .../apache/cassandra/tools/nodetool/Cleanup.java   |  7 +-
 .../cassandra/tools/nodetool/ClearSnapshot.java    |  4 +-
 .../tools/nodetool/CompactionHistory.java          | 12 +--
 .../cassandra/tools/nodetool/CompactionStats.java  | 11 +--
 .../cassandra/tools/nodetool/DescribeCluster.java  | 16 ++--
 .../cassandra/tools/nodetool/DescribeRing.java     |  8 +-
 .../tools/nodetool/FailureDetectorInfo.java        |  4 +-
 .../apache/cassandra/tools/nodetool/GcStats.java   |  6 +-
 .../tools/nodetool/GetCompactionThreshold.java     |  8 +-
 .../tools/nodetool/GetCompactionThroughput.java    |  4 +-
 .../cassandra/tools/nodetool/GetEndpoints.java     |  4 +-
 .../tools/nodetool/GetInterDCStreamThroughput.java |  2 +-
 .../cassandra/tools/nodetool/GetLoggingLevels.java |  6 +-
 .../cassandra/tools/nodetool/GetSSTables.java      |  4 +-
 .../tools/nodetool/GetStreamThroughput.java        |  4 +-
 .../tools/nodetool/GetTraceProbability.java        |  2 +-
 .../cassandra/tools/nodetool/GossipInfo.java       |  4 +-
 .../org/apache/cassandra/tools/nodetool/Info.java  | 41 +++++-----
 .../cassandra/tools/nodetool/ListSnapshots.java    | 14 ++--
 .../apache/cassandra/tools/nodetool/NetStats.java  | 44 ++++++-----
 .../cassandra/tools/nodetool/ProxyHistograms.java  | 15 ++--
 .../cassandra/tools/nodetool/RangeKeySample.java   |  6 +-
 .../apache/cassandra/tools/nodetool/Refresh.java   |  2 +-
 .../cassandra/tools/nodetool/RemoveNode.java       |  6 +-
 .../apache/cassandra/tools/nodetool/Repair.java    |  2 +-
 .../org/apache/cassandra/tools/nodetool/Ring.java  | 29 +++----
 .../org/apache/cassandra/tools/nodetool/Scrub.java |  2 +-
 .../apache/cassandra/tools/nodetool/Snapshot.java  | 12 +--
 .../apache/cassandra/tools/nodetool/Status.java    | 34 ++++----
 .../cassandra/tools/nodetool/StatusBackup.java     |  4 +-
 .../cassandra/tools/nodetool/StatusBinary.java     |  4 +-
 .../cassandra/tools/nodetool/StatusGossip.java     |  4 +-
 .../cassandra/tools/nodetool/StatusHandoff.java    |  4 +-
 .../cassandra/tools/nodetool/StatusThrift.java     |  4 +-
 .../cassandra/tools/nodetool/StopDaemon.java       |  4 +-
 .../cassandra/tools/nodetool/TableHistograms.java  | 20 +++--
 .../cassandra/tools/nodetool/TableStats.java       | 90 +++++++++++-----------
 .../cassandra/tools/nodetool/TopPartitions.java    | 18 +++--
 .../apache/cassandra/tools/nodetool/TpStats.java   | 12 +--
 .../cassandra/tools/nodetool/UpgradeSSTable.java   |  2 +-
 .../apache/cassandra/tools/nodetool/Verify.java    |  4 +-
 .../apache/cassandra/tools/nodetool/Version.java   |  4 +-
 .../cassandra/distributed/impl/Instance.java       | 62 +++++++++++++--
 .../test/ClientNetworkStopStartTest.java           | 28 ++-----
 .../cassandra/distributed/test/NodeToolTest.java   | 16 +++-
 49 files changed, 398 insertions(+), 288 deletions(-)

diff --git a/src/java/org/apache/cassandra/tools/NodeProbe.java 
b/src/java/org/apache/cassandra/tools/NodeProbe.java
index 9798763..2ebef5d 100644
--- a/src/java/org/apache/cassandra/tools/NodeProbe.java
+++ b/src/java/org/apache/cassandra/tools/NodeProbe.java
@@ -115,6 +115,7 @@ public class NodeProbe implements AutoCloseable
     protected CacheServiceMBean cacheService;
     protected StorageProxyMBean spProxy;
     protected HintedHandOffManagerMBean hhProxy;
+    protected Output output;
     private boolean failed;
 
     /**
@@ -133,6 +134,7 @@ public class NodeProbe implements AutoCloseable
         this.port = port;
         this.username = username;
         this.password = password;
+        this.output = Output.CONSOLE;
         connect();
     }
 
@@ -147,6 +149,7 @@ public class NodeProbe implements AutoCloseable
     {
         this.host = host;
         this.port = port;
+        this.output = Output.CONSOLE;
         connect();
     }
 
@@ -160,6 +163,7 @@ public class NodeProbe implements AutoCloseable
     {
         this.host = host;
         this.port = defaultPort;
+        this.output = Output.CONSOLE;
         connect();
     }
 
@@ -168,6 +172,7 @@ public class NodeProbe implements AutoCloseable
         // this constructor is only used for extensions to rewrite their own 
connect method
         this.host = "";
         this.port = 0;
+        this.output = Output.CONSOLE;
     }
 
     /**
@@ -238,6 +243,16 @@ public class NodeProbe implements AutoCloseable
         jmxc.close();
     }
 
+    public void setOutput(Output output)
+    {
+        this.output = output;
+    }
+
+    public Output output()
+    {
+        return output;
+    }
+
     public int forceKeyspaceCleanup(int jobs, String keyspaceName, String... 
columnFamilies) throws IOException, ExecutionException, InterruptedException
     {
         return ssProxy.forceKeyspaceCleanup(jobs, keyspaceName, 
columnFamilies);
diff --git a/src/java/org/apache/cassandra/tools/NodeTool.java 
b/src/java/org/apache/cassandra/tools/NodeTool.java
index b6dadd6..400ba80 100644
--- a/src/java/org/apache/cassandra/tools/NodeTool.java
+++ b/src/java/org/apache/cassandra/tools/NodeTool.java
@@ -23,7 +23,8 @@ import java.net.UnknownHostException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.Map.Entry;
-import java.util.function.Consumer;
+import java.util.Scanner;
+import java.util.SortedMap;
 
 import com.google.common.base.Joiner;
 import com.google.common.base.Throwables;
@@ -48,20 +49,22 @@ public class NodeTool
     private static final String HISTORYFILE = "nodetool.history";
 
     private final INodeProbeFactory nodeProbeFactory;
+    private final Output output;
 
     public static void main(String... args)
     {
-        System.exit(new NodeTool(new NodeProbeFactory()).execute(args));
+        System.exit(new NodeTool(new NodeProbeFactory(), 
Output.CONSOLE).execute(args));
     }
 
-    public NodeTool(INodeProbeFactory nodeProbeFactory)
+    public NodeTool(INodeProbeFactory nodeProbeFactory, Output output)
     {
         this.nodeProbeFactory = nodeProbeFactory;
+        this.output = output;
     }
 
     public int execute(String... args)
     {
-        List<Class<? extends Consumer<INodeProbeFactory>>> commands = 
newArrayList(
+        List<Class<? extends NodeToolCmdRunnable>> commands = newArrayList(
                 CassHelp.class,
                 Info.class,
                 Ring.class,
@@ -149,7 +152,7 @@ public class NodeTool
                 RefreshSizeEstimates.class
         );
 
-        Cli.CliBuilder<Consumer<INodeProbeFactory>> builder = 
Cli.builder("nodetool");
+        Cli.CliBuilder<NodeToolCmdRunnable> builder = Cli.builder("nodetool");
 
         builder.withDescription("Manage your Cassandra cluster")
                  .withDefaultCommand(CassHelp.class)
@@ -161,14 +164,14 @@ public class NodeTool
                 .withDefaultCommand(CassHelp.class)
                 .withCommand(BootstrapResume.class);
 
-        Cli<Consumer<INodeProbeFactory>> parser = builder.build();
+        Cli<NodeToolCmdRunnable> parser = builder.build();
 
         int status = 0;
         try
         {
-            Consumer<INodeProbeFactory> parse = parser.parse(args);
+            NodeToolCmdRunnable parse = parser.parse(args);
             printHistory(args);
-            parse.accept(nodeProbeFactory);
+            parse.run(nodeProbeFactory, output);
         } catch (IllegalArgumentException |
                 IllegalStateException |
                 ParseArgumentsMissingException |
@@ -212,26 +215,31 @@ public class NodeTool
 
     protected void badUse(Exception e)
     {
-        System.out.println("nodetool: " + e.getMessage());
-        System.out.println("See 'nodetool help' or 'nodetool help 
<command>'.");
+        output.out.println("nodetool: " + e.getMessage());
+        output.out.println("See 'nodetool help' or 'nodetool help 
<command>'.");
     }
 
     protected void err(Throwable e)
     {
-        System.err.println("error: " + e.getMessage());
-        System.err.println("-- StackTrace --");
-        System.err.println(getStackTraceAsString(e));
+        output.err.println("error: " + e.getMessage());
+        output.err.println("-- StackTrace --");
+        output.err.println(getStackTraceAsString(e));
     }
 
-    public static class CassHelp extends Help implements 
Consumer<INodeProbeFactory>
+    public static class CassHelp extends Help implements NodeToolCmdRunnable
     {
-        public void accept(INodeProbeFactory nodeProbeFactory)
+        public void run(INodeProbeFactory nodeProbeFactory, Output output)
         {
             run();
         }
     }
 
-    public static abstract class NodeToolCmd implements 
Consumer<INodeProbeFactory>
+    interface NodeToolCmdRunnable
+    {
+        void run(INodeProbeFactory nodeProbeFactory, Output output);
+    }
+
+    public static abstract class NodeToolCmd implements NodeToolCmdRunnable
     {
 
         @Option(type = OptionType.GLOBAL, name = {"-h", "--host"}, description 
= "Node hostname or ip address")
@@ -250,14 +258,17 @@ public class NodeTool
         private String passwordFilePath = EMPTY;
 
         private INodeProbeFactory nodeProbeFactory;
+        protected Output output;
 
-        public void accept(INodeProbeFactory nodeProbeFactory)
+        @Override
+        public void run(INodeProbeFactory nodeProbeFactory, Output output)
         {
             this.nodeProbeFactory = nodeProbeFactory;
-            run();
+            this.output = output;
+            runInternal();
         }
 
-        public void run()
+        public void runInternal()
         {
             if (isNotEmpty(username)) {
                 if (isNotEmpty(passwordFilePath))
@@ -330,10 +341,11 @@ public class NodeTool
                     nodeClient = nodeProbeFactory.create(host, parseInt(port));
                 else
                     nodeClient = nodeProbeFactory.create(host, parseInt(port), 
username, password);
+                nodeClient.setOutput(output);
             } catch (IOException e)
             {
                 Throwable rootCause = Throwables.getRootCause(e);
-                System.err.println(format("nodetool: Failed to connect to 
'%s:%s' - %s: '%s'.", host, port, rootCause.getClass().getSimpleName(), 
rootCause.getMessage()));
+                output.err.println(format("nodetool: Failed to connect to 
'%s:%s' - %s: '%s'.", host, port, rootCause.getClass().getSimpleName(), 
rootCause.getMessage()));
                 System.exit(1);
             }
 
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Version.java 
b/src/java/org/apache/cassandra/tools/Output.java
similarity index 66%
copy from src/java/org/apache/cassandra/tools/nodetool/Version.java
copy to src/java/org/apache/cassandra/tools/Output.java
index 2495508..1d2fcb3 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Version.java
+++ b/src/java/org/apache/cassandra/tools/Output.java
@@ -15,19 +15,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cassandra.tools.nodetool;
 
-import io.airlift.command.Command;
+package org.apache.cassandra.tools;
 
-import org.apache.cassandra.tools.NodeProbe;
-import org.apache.cassandra.tools.NodeTool.NodeToolCmd;
+import java.io.PrintStream;
 
-@Command(name = "version", description = "Print cassandra version")
-public class Version extends NodeToolCmd
+public class Output
 {
-    @Override
-    public void execute(NodeProbe probe)
+    public final static Output CONSOLE = new Output(System.out, System.err);
+
+    public final PrintStream out;
+    public final PrintStream err;
+
+    public Output(PrintStream out, PrintStream err)
     {
-        System.out.println("ReleaseVersion: " + probe.getReleaseVersion());
+        this.out = out;
+        this.err = err;
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/BootstrapResume.java 
b/src/java/org/apache/cassandra/tools/nodetool/BootstrapResume.java
index bb47e10..3f12121 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/BootstrapResume.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/BootstrapResume.java
@@ -33,11 +33,11 @@ public class BootstrapResume extends NodeToolCmd
     {
         try
         {
-            probe.resumeBootstrap(System.out);
+            probe.resumeBootstrap(probe.output().out);
         }
         catch (IOException e)
         {
             throw new IOError(e);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Cleanup.java 
b/src/java/org/apache/cassandra/tools/nodetool/Cleanup.java
index 6c6676d..bc7bf32 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Cleanup.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Cleanup.java
@@ -52,11 +52,12 @@ public class Cleanup extends NodeToolCmd
 
             try
             {
-                probe.forceKeyspaceCleanup(System.out, jobs, keyspace, 
cfnames);
-            } catch (Exception e)
+                probe.forceKeyspaceCleanup(probe.output().out, jobs, keyspace, 
cfnames);
+            }
+            catch (Exception e)
             {
                 throw new RuntimeException("Error occurred during cleanup", e);
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java 
b/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java
index 7167bd9..3016716 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java
@@ -55,7 +55,7 @@ public class ClearSnapshot extends NodeToolCmd
         if (!snapshotName.isEmpty())
             sb.append(" with snapshot name 
[").append(snapshotName).append("]");
 
-        System.out.println(sb.toString());
+        probe.output().out.println(sb.toString());
 
         try
         {
@@ -65,4 +65,4 @@ public class ClearSnapshot extends NodeToolCmd
             throw new RuntimeException("Error during clearing snapshots", e);
         }
     }
-}
\ No newline at end of file
+}
diff --git 
a/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java 
b/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java
index cbb054a..55f7fc5 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.tools.nodetool;
 import static com.google.common.collect.Iterables.toArray;
 import io.airlift.command.Command;
 
+import java.io.PrintStream;
 import java.util.List;
 import java.util.Set;
 
@@ -34,24 +35,25 @@ public class CompactionHistory extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println("Compaction History: ");
+        PrintStream out = probe.output().out;
+        out.println("Compaction History: ");
 
         TabularData tabularData = probe.getCompactionHistory();
         if (tabularData.isEmpty())
         {
-            System.out.printf("There is no compaction history");
+            out.printf("There is no compaction history");
             return;
         }
 
         String format = "%-41s%-19s%-29s%-26s%-15s%-15s%s%n";
         List<String> indexNames = tabularData.getTabularType().getIndexNames();
-        System.out.printf(format, toArray(indexNames, Object.class));
+        out.printf(format, toArray(indexNames, Object.class));
 
         Set<?> values = tabularData.keySet();
         for (Object eachValue : values)
         {
             List<?> value = (List<?>) eachValue;
-            System.out.printf(format, toArray(value, Object.class));
+            out.printf(format, toArray(value, Object.class));
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java 
b/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java
index e57d2ee..f4b19bc 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java
@@ -21,6 +21,7 @@ import static java.lang.String.format;
 import io.airlift.command.Command;
 import io.airlift.command.Option;
 
+import java.io.PrintStream;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.List;
@@ -30,7 +31,6 @@ import 
org.apache.cassandra.db.compaction.CompactionManagerMBean;
 import org.apache.cassandra.db.compaction.OperationType;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.tools.NodeProbe;
-import org.apache.cassandra.tools.NodeTool;
 import org.apache.cassandra.tools.NodeTool.NodeToolCmd;
 
 @Command(name = "compactionstats", description = "Print statistics on 
compactions")
@@ -44,8 +44,9 @@ public class CompactionStats extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
+        PrintStream out = probe.output().out;
         CompactionManagerMBean cm = probe.getCompactionManagerProxy();
-        System.out.println("pending tasks: " + 
probe.getCompactionMetric("PendingTasks"));
+        out.println("pending tasks: " + 
probe.getCompactionMetric("PendingTasks"));
         long remainingBytes = 0;
         List<Map<String, String>> compactions = cm.getCompactions();
         if (!compactions.isEmpty())
@@ -83,7 +84,7 @@ public class CompactionStats extends NodeToolCmd
 
             for (String[] line : lines)
             {
-                System.out.printf(format, line[0], line[1], line[2], line[3], 
line[4], line[5], line[6], line[7]);
+                out.printf(format, line[0], line[1], line[2], line[3], 
line[4], line[5], line[6], line[7]);
             }
 
             String remainingTime = "n/a";
@@ -92,7 +93,7 @@ public class CompactionStats extends NodeToolCmd
                 long remainingTimeInSecs = remainingBytes / (1024L * 1024L * 
compactionThroughput);
                 remainingTime = format("%dh%02dm%02ds", remainingTimeInSecs / 
3600, (remainingTimeInSecs % 3600) / 60, (remainingTimeInSecs % 60));
             }
-            System.out.printf("%25s%10s%n", "Active compaction remaining time 
: ", remainingTime);
+            out.printf("%25s%10s%n", "Active compaction remaining time : ", 
remainingTime);
         }
     }
 
@@ -102,4 +103,4 @@ public class CompactionStats extends NodeToolCmd
             columnSizes[i] = Math.max(columnSizes[i], columns[i].length());
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/DescribeCluster.java 
b/src/java/org/apache/cassandra/tools/nodetool/DescribeCluster.java
index 81dee20..8cab62e 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/DescribeCluster.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/DescribeCluster.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.tools.nodetool;
 import static java.lang.String.format;
 import io.airlift.command.Command;
 
+import java.io.PrintStream;
 import java.util.List;
 import java.util.Map;
 
@@ -32,18 +33,19 @@ public class DescribeCluster extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
+        PrintStream out = probe.output().out;
         // display cluster name, snitch and partitioner
-        System.out.println("Cluster Information:");
-        System.out.println("\tName: " + probe.getClusterName());
-        System.out.println("\tSnitch: " + 
probe.getEndpointSnitchInfoProxy().getSnitchName());
-        System.out.println("\tPartitioner: " + probe.getPartitioner());
+        out.println("Cluster Information:");
+        out.println("\tName: " + probe.getClusterName());
+        out.println("\tSnitch: " + 
probe.getEndpointSnitchInfoProxy().getSnitchName());
+        out.println("\tPartitioner: " + probe.getPartitioner());
 
         // display schema version for each node
-        System.out.println("\tSchema versions:");
+        out.println("\tSchema versions:");
         Map<String, List<String>> schemaVersions = 
probe.getSpProxy().getSchemaVersions();
         for (String version : schemaVersions.keySet())
         {
-            System.out.println(format("\t\t%s: %s%n", version, 
schemaVersions.get(version)));
+            out.println(format("\t\t%s: %s%n", version, 
schemaVersions.get(version)));
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/DescribeRing.java 
b/src/java/org/apache/cassandra/tools/nodetool/DescribeRing.java
index a120ffe..30f488a 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/DescribeRing.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/DescribeRing.java
@@ -22,6 +22,7 @@ import io.airlift.command.Arguments;
 import io.airlift.command.Command;
 
 import java.io.IOException;
+import java.io.PrintStream;
 
 import org.apache.cassandra.tools.NodeProbe;
 import org.apache.cassandra.tools.NodeTool.NodeToolCmd;
@@ -35,13 +36,14 @@ public class DescribeRing extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println("Schema Version:" + probe.getSchemaVersion());
-        System.out.println("TokenRange: ");
+        PrintStream out = probe.output().out;
+        out.println("Schema Version:" + probe.getSchemaVersion());
+        out.println("TokenRange: ");
         try
         {
             for (String tokenRangeString : probe.describeRing(keyspace))
             {
-                System.out.println("\t" + tokenRangeString);
+                out.println("\t" + tokenRangeString);
             }
         } catch (IOException e)
         {
diff --git 
a/src/java/org/apache/cassandra/tools/nodetool/FailureDetectorInfo.java 
b/src/java/org/apache/cassandra/tools/nodetool/FailureDetectorInfo.java
index 3c0303d..d3153a7 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/FailureDetectorInfo.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/FailureDetectorInfo.java
@@ -34,12 +34,12 @@ public class FailureDetectorInfo extends NodeToolCmd
     public void execute(NodeProbe probe)
     {
         TabularData data = probe.getFailureDetectorPhilValues();
-        System.out.printf("%10s,%16s%n", "Endpoint", "Phi");
+        probe.output().out.printf("%10s,%16s%n", "Endpoint", "Phi");
         for (Object o : data.keySet())
         {
             @SuppressWarnings({ "rawtypes", "unchecked" })
             CompositeData datum = data.get(((List) o).toArray(new 
Object[((List) o).size()]));
-            System.out.printf("%10s,%16.8f%n",datum.get("Endpoint"), 
datum.get("PHI"));
+            probe.output().out.printf("%10s,%16.8f%n", datum.get("Endpoint"), 
datum.get("PHI"));
         }
     }
 }
diff --git a/src/java/org/apache/cassandra/tools/nodetool/GcStats.java 
b/src/java/org/apache/cassandra/tools/nodetool/GcStats.java
index dd38fe7..513f74c 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GcStats.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GcStats.java
@@ -31,7 +31,7 @@ public class GcStats extends NodeToolCmd
         double[] stats = probe.getAndResetGCStats();
         double mean = stats[2] / stats[5];
         double stdev = Math.sqrt((stats[3] / stats[5]) - (mean * mean));
-        System.out.printf("%20s%20s%20s%20s%20s%20s%25s%n", "Interval (ms)", 
"Max GC Elapsed (ms)", "Total GC Elapsed (ms)", "Stdev GC Elapsed (ms)", "GC 
Reclaimed (MB)", "Collections", "Direct Memory Bytes");
-        System.out.printf("%20.0f%20.0f%20.0f%20.0f%20.0f%20.0f%25d%n", 
stats[0], stats[1], stats[2], stdev, stats[4], stats[5], (long)stats[6]);
+        probe.output().out.printf("%20s%20s%20s%20s%20s%20s%25s%n", "Interval 
(ms)", "Max GC Elapsed (ms)", "Total GC Elapsed (ms)", "Stdev GC Elapsed (ms)", 
"GC Reclaimed (MB)", "Collections", "Direct Memory Bytes");
+        
probe.output().out.printf("%20.0f%20.0f%20.0f%20.0f%20.0f%20.0f%25d%n", 
stats[0], stats[1], stats[2], stdev, stats[4], stats[5], (long)stats[6]);
     }
-}
\ No newline at end of file
+}
diff --git 
a/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThreshold.java 
b/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThreshold.java
index 6c629de..1f1d3b4 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThreshold.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThreshold.java
@@ -42,8 +42,8 @@ public class GetCompactionThreshold extends NodeToolCmd
         String cf = args.get(1);
 
         ColumnFamilyStoreMBean cfsProxy = probe.getCfsProxy(ks, cf);
-        System.out.println("Current compaction thresholds for " + ks + "/" + 
cf + ": \n" +
-                " min = " + cfsProxy.getMinimumCompactionThreshold() + ", " +
-                " max = " + cfsProxy.getMaximumCompactionThreshold());
+        probe.output().out.println("Current compaction thresholds for " + ks + 
"/" + cf + ": \n" +
+                            " min = " + 
cfsProxy.getMinimumCompactionThreshold() + ", " +
+                            " max = " + 
cfsProxy.getMaximumCompactionThreshold());
     }
-}
\ No newline at end of file
+}
diff --git 
a/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThroughput.java 
b/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThroughput.java
index c3af184..90e9355 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThroughput.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThroughput.java
@@ -28,6 +28,6 @@ public class GetCompactionThroughput extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println("Current compaction throughput: " + 
probe.getCompactionThroughput() + " MB/s");
+        probe.output().out.println("Current compaction throughput: " + 
probe.getCompactionThroughput() + " MB/s");
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/GetEndpoints.java 
b/src/java/org/apache/cassandra/tools/nodetool/GetEndpoints.java
index 49d2148..8ad7c60 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GetEndpoints.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GetEndpoints.java
@@ -45,7 +45,7 @@ public class GetEndpoints extends NodeToolCmd
         List<InetAddress> endpoints = probe.getEndpoints(ks, table, key);
         for (InetAddress endpoint : endpoints)
         {
-            System.out.println(endpoint.getHostAddress());
+            probe.output().out.println(endpoint.getHostAddress());
         }
     }
-}
\ No newline at end of file
+}
diff --git 
a/src/java/org/apache/cassandra/tools/nodetool/GetInterDCStreamThroughput.java 
b/src/java/org/apache/cassandra/tools/nodetool/GetInterDCStreamThroughput.java
index 4c354c0..34c90c3 100644
--- 
a/src/java/org/apache/cassandra/tools/nodetool/GetInterDCStreamThroughput.java
+++ 
b/src/java/org/apache/cassandra/tools/nodetool/GetInterDCStreamThroughput.java
@@ -28,6 +28,6 @@ public class GetInterDCStreamThroughput extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println("Current inter-datacenter stream throughput: " + 
probe.getInterDCStreamThroughput() + " Mb/s");
+        probe.output().out.println("Current inter-datacenter stream 
throughput: " + probe.getInterDCStreamThroughput() + " Mb/s");
     }
 }
diff --git a/src/java/org/apache/cassandra/tools/nodetool/GetLoggingLevels.java 
b/src/java/org/apache/cassandra/tools/nodetool/GetLoggingLevels.java
index 7ce0017..0482bdc 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GetLoggingLevels.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GetLoggingLevels.java
@@ -31,8 +31,8 @@ public class GetLoggingLevels extends NodeToolCmd
     public void execute(NodeProbe probe)
     {
         // what if some one set a very long logger name? 50 space may not be 
enough...
-        System.out.printf("%n%-50s%10s%n", "Logger Name", "Log Level");
+        probe.output().out.printf("%n%-50s%10s%n", "Logger Name", "Log Level");
         for (Map.Entry<String, String> entry : 
probe.getLoggingLevels().entrySet())
-            System.out.printf("%-50s%10s%n", entry.getKey(), entry.getValue());
+            probe.output().out.printf("%-50s%10s%n", entry.getKey(), 
entry.getValue());
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/GetSSTables.java 
b/src/java/org/apache/cassandra/tools/nodetool/GetSSTables.java
index 2c5d46b..361909a 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GetSSTables.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GetSSTables.java
@@ -44,7 +44,7 @@ public class GetSSTables extends NodeToolCmd
         List<String> sstables = probe.getSSTables(ks, cf, key);
         for (String sstable : sstables)
         {
-            System.out.println(sstable);
+            probe.output().out.println(sstable);
         }
     }
-}
\ No newline at end of file
+}
diff --git 
a/src/java/org/apache/cassandra/tools/nodetool/GetStreamThroughput.java 
b/src/java/org/apache/cassandra/tools/nodetool/GetStreamThroughput.java
index 437eb54..149889d 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GetStreamThroughput.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GetStreamThroughput.java
@@ -28,6 +28,6 @@ public class GetStreamThroughput extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println("Current stream throughput: " + 
probe.getStreamThroughput() + " Mb/s");
+        probe.output().out.println("Current stream throughput: " + 
probe.getStreamThroughput() + " Mb/s");
     }
-}
\ No newline at end of file
+}
diff --git 
a/src/java/org/apache/cassandra/tools/nodetool/GetTraceProbability.java 
b/src/java/org/apache/cassandra/tools/nodetool/GetTraceProbability.java
index 3940790..7222da6 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GetTraceProbability.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GetTraceProbability.java
@@ -28,6 +28,6 @@ public class GetTraceProbability extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println("Current trace probability: " + 
probe.getTraceProbability());
+        probe.output().out.println("Current trace probability: " + 
probe.getTraceProbability());
     }
 }
diff --git a/src/java/org/apache/cassandra/tools/nodetool/GossipInfo.java 
b/src/java/org/apache/cassandra/tools/nodetool/GossipInfo.java
index 2acfcf1..cdc2cd8 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/GossipInfo.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/GossipInfo.java
@@ -28,6 +28,6 @@ public class GossipInfo extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println(probe.getGossipInfo());
+        probe.output().out.println(probe.getGossipInfo());
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Info.java 
b/src/java/org/apache/cassandra/tools/nodetool/Info.java
index 0d9bd73..c2e0ff9 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Info.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Info.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.tools.nodetool;
 import io.airlift.command.Command;
 import io.airlift.command.Option;
 
+import java.io.PrintStream;
 import java.lang.management.MemoryUsage;
 import java.util.Iterator;
 import java.util.List;
@@ -45,28 +46,30 @@ public class Info extends NodeToolCmd
     {
         boolean gossipInitialized = probe.isInitialized();
 
-        System.out.printf("%-23s: %s%n", "ID", probe.getLocalHostId());
-        System.out.printf("%-23s: %s%n", "Gossip active", gossipInitialized);
-        System.out.printf("%-23s: %s%n", "Thrift active", 
probe.isThriftServerRunning());
-        System.out.printf("%-23s: %s%n", "Native Transport active", 
probe.isNativeTransportRunning());
-        System.out.printf("%-23s: %s%n", "Load", probe.getLoadString());
+        PrintStream out = probe.output().out;
+        out.printf("%-23s: %s%n", "ID", probe.getLocalHostId());
+        out.printf("%-23s: %s%n", "Gossip active", gossipInitialized);
+        out.printf("%-23s: %s%n", "Thrift active", 
probe.isThriftServerRunning());
+        out.printf("%-23s: %s%n", "Native Transport active", 
probe.isNativeTransportRunning());
+        out.printf("%-23s: %s%n", "Load", probe.getLoadString());
+
         if (gossipInitialized)
-            System.out.printf("%-23s: %s%n", "Generation No", 
probe.getCurrentGenerationNumber());
+            out.printf("%-23s: %s%n", "Generation No", 
probe.getCurrentGenerationNumber());
         else
-            System.out.printf("%-23s: %s%n", "Generation No", 0);
+            out.printf("%-23s: %s%n", "Generation No", 0);
 
         // Uptime
         long secondsUp = probe.getUptime() / 1000;
-        System.out.printf("%-23s: %d%n", "Uptime (seconds)", secondsUp);
+        out.printf("%-23s: %d%n", "Uptime (seconds)", secondsUp);
 
         // Memory usage
         MemoryUsage heapUsage = probe.getHeapMemoryUsage();
         double memUsed = (double) heapUsage.getUsed() / (1024 * 1024);
         double memMax = (double) heapUsage.getMax() / (1024 * 1024);
-        System.out.printf("%-23s: %.2f / %.2f%n", "Heap Memory (MB)", memUsed, 
memMax);
+        out.printf("%-23s: %.2f / %.2f%n", "Heap Memory (MB)", memUsed, 
memMax);
         try
         {
-            System.out.printf("%-23s: %.2f%n", "Off Heap Memory (MB)", 
getOffHeapMemoryUsed(probe));
+            out.printf("%-23s: %.2f%n", "Off Heap Memory (MB)", 
getOffHeapMemoryUsed(probe));
         }
         catch (RuntimeException e)
         {
@@ -76,16 +79,16 @@ public class Info extends NodeToolCmd
         }
 
         // Data Center/Rack
-        System.out.printf("%-23s: %s%n", "Data Center", probe.getDataCenter());
-        System.out.printf("%-23s: %s%n", "Rack", probe.getRack());
+        out.printf("%-23s: %s%n", "Data Center", probe.getDataCenter());
+        out.printf("%-23s: %s%n", "Rack", probe.getRack());
 
         // Exceptions
-        System.out.printf("%-23s: %s%n", "Exceptions", 
probe.getStorageMetric("Exceptions"));
+        out.printf("%-23s: %s%n", "Exceptions", 
probe.getStorageMetric("Exceptions"));
 
         CacheServiceMBean cacheService = probe.getCacheServiceMBean();
 
         // Key Cache: Hits, Requests, RecentHitRate, SavePeriodInSeconds
-        System.out.printf("%-23s: entries %d, size %s, capacity %s, %d hits, 
%d requests, %.3f recent hit rate, %d save period in seconds%n",
+        out.printf("%-23s: entries %d, size %s, capacity %s, %d hits, %d 
requests, %.3f recent hit rate, %d save period in seconds%n",
                 "Key Cache",
                 probe.getCacheMetric("KeyCache", "Entries"),
                 FileUtils.stringifyFileSize((long) 
probe.getCacheMetric("KeyCache", "Size")),
@@ -96,7 +99,7 @@ public class Info extends NodeToolCmd
                 cacheService.getKeyCacheSavePeriodInSeconds());
 
         // Row Cache: Hits, Requests, RecentHitRate, SavePeriodInSeconds
-        System.out.printf("%-23s: entries %d, size %s, capacity %s, %d hits, 
%d requests, %.3f recent hit rate, %d save period in seconds%n",
+        out.printf("%-23s: entries %d, size %s, capacity %s, %d hits, %d 
requests, %.3f recent hit rate, %d save period in seconds%n",
                 "Row Cache",
                 probe.getCacheMetric("RowCache", "Entries"),
                 FileUtils.stringifyFileSize((long) 
probe.getCacheMetric("RowCache", "Size")),
@@ -107,7 +110,7 @@ public class Info extends NodeToolCmd
                 cacheService.getRowCacheSavePeriodInSeconds());
 
         // Counter Cache: Hits, Requests, RecentHitRate, SavePeriodInSeconds
-        System.out.printf("%-23s: entries %d, size %s, capacity %s, %d hits, 
%d requests, %.3f recent hit rate, %d save period in seconds%n",
+        out.printf("%-23s: entries %d, size %s, capacity %s, %d hits, %d 
requests, %.3f recent hit rate, %d save period in seconds%n",
                 "Counter Cache",
                 probe.getCacheMetric("CounterCache", "Entries"),
                 FileUtils.stringifyFileSize((long) 
probe.getCacheMetric("CounterCache", "Size")),
@@ -124,14 +127,14 @@ public class Info extends NodeToolCmd
             List<String> tokens = probe.getTokens();
             if (tokens.size() == 1 || this.tokens)
                 for (String token : tokens)
-                    System.out.printf("%-23s: %s%n", "Token", token);
+                    out.printf("%-23s: %s%n", "Token", token);
             else
-                System.out.printf("%-23s: (invoke with -T/--tokens to see all 
%d tokens)%n", "Token",
+                out.printf("%-23s: (invoke with -T/--tokens to see all %d 
tokens)%n", "Token",
                                   tokens.size());
         }
         else
         {
-            System.out.printf("%-23s: (node is not joined to the cluster)%n", 
"Token");
+            out.printf("%-23s: (node is not joined to the cluster)%n", 
"Token");
         }
     }
 
diff --git a/src/java/org/apache/cassandra/tools/nodetool/ListSnapshots.java 
b/src/java/org/apache/cassandra/tools/nodetool/ListSnapshots.java
index ee7bf34..029ec61 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/ListSnapshots.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/ListSnapshots.java
@@ -19,6 +19,7 @@ package org.apache.cassandra.tools.nodetool;
 
 import io.airlift.command.Command;
 
+import java.io.PrintStream;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -35,14 +36,15 @@ public class ListSnapshots extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
+        PrintStream out = probe.output().out;
         try
         {
-            System.out.println("Snapshot Details: ");
+            out.println("Snapshot Details: ");
 
             final Map<String,TabularData> snapshotDetails = 
probe.getSnapshotDetails();
             if (snapshotDetails.isEmpty())
             {
-                System.out.printf("There are no snapshots");
+                out.printf("There are no snapshots");
                 return;
             }
 
@@ -50,7 +52,7 @@ public class ListSnapshots extends NodeToolCmd
             final String format = "%-20s%-29s%-29s%-19s%-19s%n";
             // display column names only once
             final List<String> indexNames = 
snapshotDetails.entrySet().iterator().next().getValue().getTabularType().getIndexNames();
-            System.out.printf(format, (Object[]) indexNames.toArray(new 
String[indexNames.size()]));
+            out.printf(format, (Object[]) indexNames.toArray(new 
String[indexNames.size()]));
 
             for (final Map.Entry<String, TabularData> snapshotDetail : 
snapshotDetails.entrySet())
             {
@@ -58,15 +60,15 @@ public class ListSnapshots extends NodeToolCmd
                 for (Object eachValue : values)
                 {
                     final List<?> value = (List<?>) eachValue;
-                    System.out.printf(format, value.toArray(new 
Object[value.size()]));
+                    out.printf(format, value.toArray(new 
Object[value.size()]));
                 }
             }
 
-            System.out.println("\nTotal TrueDiskSpaceUsed: " + 
FileUtils.stringifyFileSize(trueSnapshotsSize) + "\n");
+            out.println("\nTotal TrueDiskSpaceUsed: " + 
FileUtils.stringifyFileSize(trueSnapshotsSize) + "\n");
         }
         catch (Exception e)
         {
             throw new RuntimeException("Error during list snapshot", e);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/NetStats.java 
b/src/java/org/apache/cassandra/tools/nodetool/NetStats.java
index 025d754..61db036 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/NetStats.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/NetStats.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.tools.nodetool;
 import io.airlift.command.Command;
 import io.airlift.command.Option;
 
+import java.io.PrintStream;
 import java.util.Set;
 
 import org.apache.cassandra.io.util.FileUtils;
@@ -41,42 +42,43 @@ public class NetStats extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.printf("Mode: %s%n", probe.getOperationMode());
+        PrintStream out = probe.output().out;
+        out.printf("Mode: %s%n", probe.getOperationMode());
         Set<StreamState> statuses = probe.getStreamStatus();
         if (statuses.isEmpty())
-            System.out.println("Not sending any streams.");
+            out.println("Not sending any streams.");
         for (StreamState status : statuses)
         {
-            System.out.printf("%s %s%n", status.description, 
status.planId.toString());
+            out.printf("%s %s%n", status.description, 
status.planId.toString());
             for (SessionInfo info : status.sessions)
             {
-                System.out.printf("    %s", info.peer.toString());
+                out.printf("    %s", info.peer.toString());
                 // print private IP when it is used
                 if (!info.peer.equals(info.connecting))
                 {
-                    System.out.printf(" (using %s)", 
info.connecting.toString());
+                    out.printf(" (using %s)", info.connecting.toString());
                 }
-                System.out.printf("%n");
+                out.printf("%n");
                 if (!info.receivingSummaries.isEmpty())
                 {
                     if (humanReadable)
-                        System.out.printf("        Receiving %d files, %s 
total. Already received %d files, %s total%n", info.getTotalFilesToReceive(), 
FileUtils.stringifyFileSize(info.getTotalSizeToReceive()), 
info.getTotalFilesReceived(), 
FileUtils.stringifyFileSize(info.getTotalSizeReceived()));
+                        out.printf("        Receiving %d files, %s total. 
Already received %d files, %s total%n", info.getTotalFilesToReceive(), 
FileUtils.stringifyFileSize(info.getTotalSizeToReceive()), 
info.getTotalFilesReceived(), 
FileUtils.stringifyFileSize(info.getTotalSizeReceived()));
                     else
-                        System.out.printf("        Receiving %d files, %d 
bytes total. Already received %d files, %d bytes total%n", 
info.getTotalFilesToReceive(), info.getTotalSizeToReceive(), 
info.getTotalFilesReceived(), info.getTotalSizeReceived());
+                        out.printf("        Receiving %d files, %d bytes 
total. Already received %d files, %d bytes total%n", 
info.getTotalFilesToReceive(), info.getTotalSizeToReceive(), 
info.getTotalFilesReceived(), info.getTotalSizeReceived());
                     for (ProgressInfo progress : info.getReceivingFiles())
                     {
-                        System.out.printf("            %s%n", 
progress.toString());
+                        out.printf("            %s%n", progress.toString());
                     }
                 }
                 if (!info.sendingSummaries.isEmpty())
                 {
                     if (humanReadable)
-                        System.out.printf("        Sending %d files, %s total. 
Already sent %d files, %s total%n", info.getTotalFilesToSend(), 
FileUtils.stringifyFileSize(info.getTotalSizeToSend()), 
info.getTotalFilesSent(), FileUtils.stringifyFileSize(info.getTotalSizeSent()));
+                        out.printf("        Sending %d files, %s total. 
Already sent %d files, %s total%n", info.getTotalFilesToSend(), 
FileUtils.stringifyFileSize(info.getTotalSizeToSend()), 
info.getTotalFilesSent(), FileUtils.stringifyFileSize(info.getTotalSizeSent()));
                     else
-                        System.out.printf("        Sending %d files, %d bytes 
total. Already sent %d files, %d bytes total%n", info.getTotalFilesToSend(), 
info.getTotalSizeToSend(), info.getTotalFilesSent(), info.getTotalSizeSent());
+                        out.printf("        Sending %d files, %d bytes total. 
Already sent %d files, %d bytes total%n", info.getTotalFilesToSend(), 
info.getTotalSizeToSend(), info.getTotalFilesSent(), info.getTotalSizeSent());
                     for (ProgressInfo progress : info.getSendingFiles())
                     {
-                        System.out.printf("            %s%n", 
progress.toString());
+                        out.printf("            %s%n", progress.toString());
                     }
                 }
             }
@@ -84,14 +86,14 @@ public class NetStats extends NodeToolCmd
 
         if (!probe.isStarting())
         {
-            System.out.printf("Read Repair Statistics:%nAttempted: 
%d%nMismatch (Blocking): %d%nMismatch (Background): %d%n", 
probe.getReadRepairAttempted(), probe.getReadRepairRepairedBlocking(), 
probe.getReadRepairRepairedBackground());
+            out.printf("Read Repair Statistics:%nAttempted: %d%nMismatch 
(Blocking): %d%nMismatch (Background): %d%n", probe.getReadRepairAttempted(), 
probe.getReadRepairRepairedBlocking(), probe.getReadRepairRepairedBackground());
 
             MessagingServiceMBean ms = probe.getMessagingServiceProxy();
-            System.out.printf("%-25s", "Pool Name");
-            System.out.printf("%10s", "Active");
-            System.out.printf("%10s", "Pending");
-            System.out.printf("%15s", "Completed");
-            System.out.printf("%10s%n", "Dropped");
+            out.printf("%-25s", "Pool Name");
+            out.printf("%10s", "Active");
+            out.printf("%10s", "Pending");
+            out.printf("%15s", "Completed");
+            out.printf("%10s%n", "Dropped");
 
             int pending;
             long completed;
@@ -106,7 +108,7 @@ public class NetStats extends NodeToolCmd
             dropped = 0;
             for (long n : ms.getLargeMessageDroppedTasks().values())
                 dropped += n;
-            System.out.printf("%-25s%10s%10s%15s%10s%n", "Large messages", 
"n/a", pending, completed, dropped);
+            out.printf("%-25s%10s%10s%15s%10s%n", "Large messages", "n/a", 
pending, completed, dropped);
 
             pending = 0;
             for (int n : ms.getSmallMessagePendingTasks().values())
@@ -117,7 +119,7 @@ public class NetStats extends NodeToolCmd
             dropped = 0;
             for (long n : ms.getSmallMessageDroppedTasks().values())
                 dropped += n;
-            System.out.printf("%-25s%10s%10s%15s%10s%n", "Small messages", 
"n/a", pending, completed, dropped);
+            out.printf("%-25s%10s%10s%15s%10s%n", "Small messages", "n/a", 
pending, completed, dropped);
 
             pending = 0;
             for (int n : ms.getGossipMessagePendingTasks().values())
@@ -128,7 +130,7 @@ public class NetStats extends NodeToolCmd
             dropped = 0;
             for (long n : ms.getGossipMessageDroppedTasks().values())
                 dropped += n;
-            System.out.printf("%-25s%10s%10s%15s%10s%n", "Gossip messages", 
"n/a", pending, completed, dropped);
+            out.printf("%-25s%10s%10s%15s%10s%n", "Gossip messages", "n/a", 
pending, completed, dropped);
         }
     }
 }
diff --git a/src/java/org/apache/cassandra/tools/nodetool/ProxyHistograms.java 
b/src/java/org/apache/cassandra/tools/nodetool/ProxyHistograms.java
index 2a2851d..1a3fc42 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/ProxyHistograms.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/ProxyHistograms.java
@@ -17,6 +17,8 @@
  */
 package org.apache.cassandra.tools.nodetool;
 
+import java.io.PrintStream;
+
 import static java.lang.String.format;
 import io.airlift.command.Command;
 
@@ -33,20 +35,21 @@ public class ProxyHistograms extends NodeToolCmd
         double[] readLatency = 
probe.metricPercentilesAsArray(probe.getProxyMetric("Read"));
         double[] writeLatency = 
probe.metricPercentilesAsArray(probe.getProxyMetric("Write"));
         double[] rangeLatency = 
probe.metricPercentilesAsArray(probe.getProxyMetric("RangeSlice"));
+        PrintStream out = probe.output().out;
 
-        System.out.println("proxy histograms");
-        System.out.println(format("%-10s%18s%18s%18s",
+        out.println("proxy histograms");
+        out.println(format("%-10s%18s%18s%18s",
                 "Percentile", "Read Latency", "Write Latency", "Range 
Latency"));
-        System.out.println(format("%-10s%18s%18s%18s",
+        out.println(format("%-10s%18s%18s%18s",
                 "", "(micros)", "(micros)", "(micros)"));
         for (int i = 0; i < percentiles.length; i++)
         {
-            System.out.println(format("%-10s%18.2f%18.2f%18.2f",
+            out.println(format("%-10s%18.2f%18.2f%18.2f",
                     percentiles[i],
                     readLatency[i],
                     writeLatency[i],
                     rangeLatency[i]));
         }
-        System.out.println();
+        out.println();
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/RangeKeySample.java 
b/src/java/org/apache/cassandra/tools/nodetool/RangeKeySample.java
index e079a4b..02a91b5 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/RangeKeySample.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/RangeKeySample.java
@@ -30,11 +30,11 @@ public class RangeKeySample extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println("RangeKeySample: ");
+        probe.output().out.println("RangeKeySample: ");
         List<String> tokenStrings = probe.sampleKeyRange();
         for (String tokenString : tokenStrings)
         {
-            System.out.println("\t" + tokenString);
+            probe.output().out.println("\t" + tokenString);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Refresh.java 
b/src/java/org/apache/cassandra/tools/nodetool/Refresh.java
index 153255c..d2fea93 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Refresh.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Refresh.java
@@ -39,4 +39,4 @@ public class Refresh extends NodeToolCmd
         checkArgument(args.size() == 2, "refresh requires ks and cf args");
         probe.loadNewSSTables(args.get(0), args.get(1));
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/RemoveNode.java 
b/src/java/org/apache/cassandra/tools/nodetool/RemoveNode.java
index 848049e..b257019 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/RemoveNode.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/RemoveNode.java
@@ -36,10 +36,10 @@ public class RemoveNode extends NodeToolCmd
         switch (removeOperation)
         {
             case "status":
-                System.out.println("RemovalStatus: " + 
probe.getRemovalStatus());
+                probe.output().out.println("RemovalStatus: " + 
probe.getRemovalStatus());
                 break;
             case "force":
-                System.out.println("RemovalStatus: " + 
probe.getRemovalStatus());
+                probe.output().out.println("RemovalStatus: " + 
probe.getRemovalStatus());
                 probe.forceRemoveCompletion();
                 break;
             default:
@@ -47,4 +47,4 @@ public class RemoveNode extends NodeToolCmd
                 break;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Repair.java 
b/src/java/org/apache/cassandra/tools/nodetool/Repair.java
index 7d0e207..0840036 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Repair.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Repair.java
@@ -123,7 +123,7 @@ public class Repair extends NodeToolCmd
             options.put(RepairOption.HOSTS_KEY, 
StringUtils.join(specificHosts, ","));
             try
             {
-                probe.repairAsync(System.out, keyspace, options);
+                probe.repairAsync(probe.output().out, keyspace, options);
             } catch (Exception e)
             {
                 throw new RuntimeException("Error occurred during repair", e);
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Ring.java 
b/src/java/org/apache/cassandra/tools/nodetool/Ring.java
index 5102029..f83a175 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Ring.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Ring.java
@@ -22,6 +22,7 @@ import io.airlift.command.Arguments;
 import io.airlift.command.Command;
 import io.airlift.command.Option;
 
+import java.io.PrintStream;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.text.DecimalFormat;
@@ -51,6 +52,7 @@ public class Ring extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
+        PrintStream out = probe.output().out;
         Map<String, String> tokensToEndpoints = probe.getTokenToEndpointMap();
         LinkedHashMultimap<String, String> endpointsToTokens = 
LinkedHashMultimap.create();
         boolean haveVnodes = false;
@@ -88,22 +90,22 @@ public class Ring extends NodeToolCmd
         }
         catch (IllegalArgumentException ex)
         {
-            System.out.printf("%nError: " + ex.getMessage() + "%n");
+            out.printf("%nError: " + ex.getMessage() + "%n");
             return;
         }
 
 
-        System.out.println();
+        out.println();
         for (Entry<String, SetHostStat> entry : 
NodeTool.getOwnershipByDc(probe, resolveIp, tokensToEndpoints, 
ownerships).entrySet())
             printDc(probe, format, entry.getKey(), endpointsToTokens, 
entry.getValue(),showEffectiveOwnership);
 
         if (haveVnodes)
         {
-            System.out.println("  Warning: \"nodetool ring\" is used to output 
all the tokens of a node.");
-            System.out.println("  To view status related info of a node use 
\"nodetool status\" instead.\n");
+            out.println("  Warning: \"nodetool ring\" is used to output all 
the tokens of a node.");
+            out.println("  To view status related info of a node use 
\"nodetool status\" instead.\n");
         }
 
-        System.out.printf("%n  " + errors.toString());
+        out.printf("%n  " + errors.toString());
     }
 
     private void printDc(NodeProbe probe, String format,
@@ -111,6 +113,7 @@ public class Ring extends NodeToolCmd
                          LinkedHashMultimap<String, String> endpointsToTokens,
                          SetHostStat hoststats,boolean showEffectiveOwnership)
     {
+        PrintStream out = probe.output().out;
         Collection<String> liveNodes = probe.getLiveNodes();
         Collection<String> deadNodes = probe.getUnreachableNodes();
         Collection<String> joiningNodes = probe.getJoiningNodes();
@@ -118,8 +121,8 @@ public class Ring extends NodeToolCmd
         Collection<String> movingNodes = probe.getMovingNodes();
         Map<String, String> loadMap = probe.getLoadMap();
 
-        System.out.println("Datacenter: " + dc);
-        System.out.println("==========");
+        out.println("Datacenter: " + dc);
+        out.println("==========");
 
         // get the total amount of replicas for this dc and the last token in 
this dc's ring
         List<String> tokens = new ArrayList<>();
@@ -131,12 +134,12 @@ public class Ring extends NodeToolCmd
             lastToken = tokens.get(tokens.size() - 1);
         }
 
-        System.out.printf(format, "Address", "Rack", "Status", "State", 
"Load", "Owns", "Token");
+        out.printf(format, "Address", "Rack", "Status", "State", "Load", 
"Owns", "Token");
 
         if (hoststats.size() > 1)
-            System.out.printf(format, "", "", "", "", "", "", lastToken);
+            out.printf(format, "", "", "", "", "", "", lastToken);
         else
-            System.out.println();
+            out.println();
 
         for (HostStat stat : hoststats)
         {
@@ -170,8 +173,8 @@ public class Ring extends NodeToolCmd
                     ? loadMap.get(endpoint)
                     : "?";
             String owns = stat.owns != null && showEffectiveOwnership? new 
DecimalFormat("##0.00%").format(stat.owns) : "?";
-            System.out.printf(format, stat.ipOrDns(), rack, status, state, 
load, owns, stat.token);
+            out.printf(format, stat.ipOrDns(), rack, status, state, load, 
owns, stat.token);
         }
-        System.out.println();
+        out.println();
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Scrub.java 
b/src/java/org/apache/cassandra/tools/nodetool/Scrub.java
index 3c726b9..0e17d33 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Scrub.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Scrub.java
@@ -69,7 +69,7 @@ public class Scrub extends NodeToolCmd
         {
             try
             {
-                probe.scrub(System.out, disableSnapshot, skipCorrupted, 
!noValidation, reinsertOverflowedTTL, jobs, keyspace, cfnames);
+                probe.scrub(probe.output().out, disableSnapshot, 
skipCorrupted, !noValidation, reinsertOverflowedTTL, jobs, keyspace, cfnames);
             } catch (IllegalArgumentException e)
             {
                 throw e;
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Snapshot.java 
b/src/java/org/apache/cassandra/tools/nodetool/Snapshot.java
index 2318620..275b947 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Snapshot.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Snapshot.java
@@ -24,6 +24,7 @@ import io.airlift.command.Command;
 import io.airlift.command.Option;
 
 import java.io.IOException;
+import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -48,6 +49,7 @@ public class Snapshot extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
+        PrintStream out = probe.output().out;
         try
         {
             StringBuilder sb = new StringBuilder();
@@ -67,9 +69,9 @@ public class Snapshot extends NodeToolCmd
                 }
                 if (!snapshotName.isEmpty())
                     sb.append(" with snapshot name 
[").append(snapshotName).append("]");
-                System.out.println(sb.toString());
+                out.println(sb.toString());
                 probe.takeMultipleColumnFamilySnapshot(snapshotName, 
ktList.split(","));
-                System.out.println("Snapshot directory: " + snapshotName);
+                out.println("Snapshot directory: " + snapshotName);
             }
             else
             {
@@ -81,10 +83,10 @@ public class Snapshot extends NodeToolCmd
                 if (!snapshotName.isEmpty())
                     sb.append(" with snapshot name 
[").append(snapshotName).append("]");
 
-                System.out.println(sb.toString());
+                out.println(sb.toString());
 
                 probe.takeSnapshot(snapshotName, table, toArray(keyspaces, 
String.class));
-                System.out.println("Snapshot directory: " + snapshotName);
+                out.println("Snapshot directory: " + snapshotName);
             }
         }
         catch (IOException e)
@@ -92,4 +94,4 @@ public class Snapshot extends NodeToolCmd
             throw new RuntimeException("Error during taking a snapshot", e);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Status.java 
b/src/java/org/apache/cassandra/tools/nodetool/Status.java
index 99f745d..2bfc991 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Status.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Status.java
@@ -21,6 +21,7 @@ import io.airlift.command.Arguments;
 import io.airlift.command.Command;
 import io.airlift.command.Option;
 
+import java.io.PrintStream;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.text.DecimalFormat;
@@ -55,6 +56,7 @@ public class Status extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
+        PrintStream out = probe.output().out;
         joiningNodes = probe.getJoiningNodes();
         leavingNodes = probe.getLeavingNodes();
         movingNodes = probe.getMovingNodes();
@@ -81,7 +83,7 @@ public class Status extends NodeToolCmd
         }
         catch (IllegalArgumentException ex)
         {
-            System.out.printf("%nError: " + ex.getMessage() + "%n");
+            out.printf("%nError: " + ex.getMessage() + "%n");
             System.exit(1);
         }
 
@@ -97,15 +99,15 @@ public class Status extends NodeToolCmd
         for (Map.Entry<String, SetHostStat> dc : dcs.entrySet())
         {
             String dcHeader = String.format("Datacenter: %s%n", dc.getKey());
-            System.out.printf(dcHeader);
-            for (int i = 0; i < (dcHeader.length() - 1); i++) 
System.out.print('=');
-            System.out.println();
+            out.printf(dcHeader);
+            for (int i = 0; i < (dcHeader.length() - 1); i++) out.print('=');
+            out.println();
 
             // Legend
-            System.out.println("Status=Up/Down");
-            System.out.println("|/ State=Normal/Leaving/Joining/Moving");
+            out.println("Status=Up/Down");
+            out.println("|/ State=Normal/Leaving/Joining/Moving");
 
-            printNodesHeader(hasEffectiveOwns, isTokenPerNode);
+            printNodesHeader(hasEffectiveOwns, isTokenPerNode, out);
 
             ArrayListMultimap<InetAddress, HostStat> hostToTokens = 
ArrayListMultimap.create();
             for (HostStat stat : dc.getValue())
@@ -115,11 +117,11 @@ public class Status extends NodeToolCmd
             {
                 Float owns = ownerships.get(endpoint);
                 List<HostStat> tokens = hostToTokens.get(endpoint);
-                printNode(endpoint.getHostAddress(), owns, tokens, 
hasEffectiveOwns, isTokenPerNode);
+                printNode(endpoint.getHostAddress(), owns, tokens, 
hasEffectiveOwns, isTokenPerNode, out);
             }
         }
 
-        System.out.printf("%n" + errors.toString());
+        out.printf("%n" + errors.toString());
 
     }
 
@@ -135,18 +137,18 @@ public class Status extends NodeToolCmd
         }
     }
 
-    private void printNodesHeader(boolean hasEffectiveOwns, boolean 
isTokenPerNode)
+    private void printNodesHeader(boolean hasEffectiveOwns, boolean 
isTokenPerNode, PrintStream out)
     {
         String fmt = getFormat(hasEffectiveOwns, isTokenPerNode);
         String owns = hasEffectiveOwns ? "Owns (effective)" : "Owns";
 
         if (isTokenPerNode)
-            System.out.printf(fmt, "-", "-", "Address", "Load", owns, "Host 
ID", "Token", "Rack");
+            out.printf(fmt, "-", "-", "Address", "Load", owns, "Host ID", 
"Token", "Rack");
         else
-            System.out.printf(fmt, "-", "-", "Address", "Load", "Tokens", 
owns, "Host ID", "Rack");
+            out.printf(fmt, "-", "-", "Address", "Load", "Tokens", owns, "Host 
ID", "Rack");
     }
 
-    private void printNode(String endpoint, Float owns, List<HostStat> tokens, 
boolean hasEffectiveOwns, boolean isTokenPerNode)
+    private void printNode(String endpoint, Float owns, List<HostStat> tokens, 
boolean hasEffectiveOwns, boolean isTokenPerNode, PrintStream out)
     {
         String status, state, load, strOwns, hostID, rack, fmt;
         fmt = getFormat(hasEffectiveOwns, isTokenPerNode);
@@ -172,9 +174,9 @@ public class Status extends NodeToolCmd
 
         String endpointDns = tokens.get(0).ipOrDns();
         if (isTokenPerNode)
-            System.out.printf(fmt, status, state, endpointDns, load, strOwns, 
hostID, tokens.get(0).token, rack);
+            out.printf(fmt, status, state, endpointDns, load, strOwns, hostID, 
tokens.get(0).token, rack);
         else
-            System.out.printf(fmt, status, state, endpointDns, load, 
tokens.size(), strOwns, hostID, rack);
+            out.printf(fmt, status, state, endpointDns, load, tokens.size(), 
strOwns, hostID, rack);
     }
 
     private String getFormat(
@@ -204,4 +206,4 @@ public class Status extends NodeToolCmd
 
         return format;
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/StatusBackup.java 
b/src/java/org/apache/cassandra/tools/nodetool/StatusBackup.java
index 49a6750..0ab3c3f 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/StatusBackup.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/StatusBackup.java
@@ -28,9 +28,9 @@ public class StatusBackup extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println(
+        probe.output().out.println(
                 probe.isIncrementalBackupsEnabled()
                 ? "running"
                 : "not running");
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/StatusBinary.java 
b/src/java/org/apache/cassandra/tools/nodetool/StatusBinary.java
index d4fae14..f373a74 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/StatusBinary.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/StatusBinary.java
@@ -28,9 +28,9 @@ public class StatusBinary extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println(
+        probe.output().out.println(
                 probe.isNativeTransportRunning()
                 ? "running"
                 : "not running");
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/StatusGossip.java 
b/src/java/org/apache/cassandra/tools/nodetool/StatusGossip.java
index e40df8d..9cddaa9 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/StatusGossip.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/StatusGossip.java
@@ -28,9 +28,9 @@ public class StatusGossip extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println(
+        probe.output().out.println(
                 probe.isGossipRunning()
                 ? "running"
                 : "not running");
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/StatusHandoff.java 
b/src/java/org/apache/cassandra/tools/nodetool/StatusHandoff.java
index 5a00069..738cbeb 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/StatusHandoff.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/StatusHandoff.java
@@ -28,9 +28,9 @@ public class StatusHandoff extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println(
+        probe.output().out.println(
                 probe.isHandoffEnabled()
                 ? "running"
                 : "not running");
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/StatusThrift.java 
b/src/java/org/apache/cassandra/tools/nodetool/StatusThrift.java
index 0cb17d2..272be1a 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/StatusThrift.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/StatusThrift.java
@@ -28,9 +28,9 @@ public class StatusThrift extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println(
+        probe.output().out.println(
                 probe.isThriftServerRunning()
                 ? "running"
                 : "not running");
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/StopDaemon.java 
b/src/java/org/apache/cassandra/tools/nodetool/StopDaemon.java
index a0af89f..f74d19c 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/StopDaemon.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/StopDaemon.java
@@ -37,6 +37,6 @@ public class StopDaemon extends NodeToolCmd
             JVMStabilityInspector.inspectThrowable(e);
             // ignored
         }
-        System.out.println("Cassandra has shutdown.");
+        probe.output().out.println("Cassandra has shutdown.");
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java 
b/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java
index 207a74e..d055209 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java
@@ -22,6 +22,7 @@ import static java.lang.String.format;
 import io.airlift.command.Arguments;
 import io.airlift.command.Command;
 
+import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -42,6 +43,9 @@ public class TableHistograms extends NodeToolCmd
     {
         checkArgument(args.size() == 2, "tablehistograms requires keyspace and 
table name arguments");
 
+        PrintStream out = probe.output().out;
+        PrintStream err = probe.output().err;
+
         String keyspace = args.get(0);
         String table = args.get(1);
 
@@ -56,7 +60,7 @@ public class TableHistograms extends NodeToolCmd
 
         if (ArrayUtils.isEmpty(estimatedRowSize) || 
ArrayUtils.isEmpty(estimatedColumnCount))
         {
-            System.err.println("No SSTables exists, unable to calculate 
'Partition Size' and 'Cell Count' percentiles");
+            err.println("No SSTables exists, unable to calculate 'Partition 
Size' and 'Cell Count' percentiles");
 
             for (int i = 0; i < 7; i++)
             {
@@ -71,7 +75,7 @@ public class TableHistograms extends NodeToolCmd
 
             if (rowSizeHist.isOverflowed())
             {
-                System.err.println(String.format("Row sizes are larger than 
%s, unable to calculate percentiles", rowSizeHist.getLargestBucketOffset()));
+                err.println(String.format("Row sizes are larger than %s, 
unable to calculate percentiles", rowSizeHist.getLargestBucketOffset()));
                 for (int i = 0; i < offsetPercentiles.length; i++)
                         estimatedRowSizePercentiles[i] = Double.NaN;
             }
@@ -83,7 +87,7 @@ public class TableHistograms extends NodeToolCmd
 
             if (columnCountHist.isOverflowed())
             {
-                System.err.println(String.format("Column counts are larger 
than %s, unable to calculate percentiles", 
columnCountHist.getLargestBucketOffset()));
+                err.println(String.format("Column counts are larger than %s, 
unable to calculate percentiles", columnCountHist.getLargestBucketOffset()));
                 for (int i = 0; i < estimatedColumnCountPercentiles.length; 
i++)
                     estimatedColumnCountPercentiles[i] = Double.NaN;
             }
@@ -106,15 +110,15 @@ public class TableHistograms extends NodeToolCmd
         double[] writeLatency = 
probe.metricPercentilesAsArray((CassandraMetricsRegistry.JmxTimerMBean) 
probe.getColumnFamilyMetric(keyspace, table, "WriteLatency"));
         double[] sstablesPerRead = 
probe.metricPercentilesAsArray((CassandraMetricsRegistry.JmxHistogramMBean) 
probe.getColumnFamilyMetric(keyspace, table, "SSTablesPerReadHistogram"));
 
-        System.out.println(format("%s/%s histograms", keyspace, table));
-        System.out.println(format("%-10s%10s%18s%18s%18s%18s",
+        out.println(format("%s/%s histograms", keyspace, table));
+        out.println(format("%-10s%10s%18s%18s%18s%18s",
                 "Percentile", "SSTables", "Write Latency", "Read Latency", 
"Partition Size", "Cell Count"));
-        System.out.println(format("%-10s%10s%18s%18s%18s%18s",
+        out.println(format("%-10s%10s%18s%18s%18s%18s",
                 "", "", "(micros)", "(micros)", "(bytes)", ""));
 
         for (int i = 0; i < percentiles.length; i++)
         {
-            System.out.println(format("%-10s%10.2f%18.2f%18.2f%18.0f%18.0f",
+            out.println(format("%-10s%10.2f%18.2f%18.2f%18.0f%18.0f",
                     percentiles[i],
                     sstablesPerRead[i],
                     writeLatency[i],
@@ -122,6 +126,6 @@ public class TableHistograms extends NodeToolCmd
                     estimatedRowSizePercentiles[i],
                     estimatedColumnCountPercentiles[i]));
         }
-        System.out.println();
+        out.println();
     }
 }
diff --git a/src/java/org/apache/cassandra/tools/nodetool/TableStats.java 
b/src/java/org/apache/cassandra/tools/nodetool/TableStats.java
index a1d2038..5df0a09 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/TableStats.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/TableStats.java
@@ -21,6 +21,7 @@ import io.airlift.command.Arguments;
 import io.airlift.command.Command;
 import io.airlift.command.Option;
 
+import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -52,6 +53,7 @@ public class TableStats extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
+        PrintStream out = probe.output().out;
         TableStats.OptionFilter filter = new OptionFilter(ignore, tableNames);
         Map<String, List<ColumnFamilyStoreMBean>> tableStoreMap = new 
HashMap<>();
 
@@ -90,7 +92,7 @@ public class TableStats extends NodeToolCmd
             double keyspaceTotalReadTime = 0.0f;
             double keyspaceTotalWriteTime = 0.0f;
 
-            System.out.println("Keyspace: " + keyspaceName);
+            out.println("Keyspace: " + keyspaceName);
             for (ColumnFamilyStoreMBean table : columnFamilies)
             {
                 String tableName = table.getColumnFamilyName();
@@ -117,42 +119,42 @@ public class TableStats extends NodeToolCmd
                                           ? keyspaceTotalWriteTime / 
keyspaceWriteCount / 1000
                                           : Double.NaN;
 
-            System.out.println("\tRead Count: " + keyspaceReadCount);
-            System.out.println("\tRead Latency: " + String.format("%s", 
keyspaceReadLatency) + " ms.");
-            System.out.println("\tWrite Count: " + keyspaceWriteCount);
-            System.out.println("\tWrite Latency: " + String.format("%s", 
keyspaceWriteLatency) + " ms.");
-            System.out.println("\tPending Flushes: " + keyspacePendingFlushes);
+            out.println("\tRead Count: " + keyspaceReadCount);
+            out.println("\tRead Latency: " + String.format("%s", 
keyspaceReadLatency) + " ms.");
+            out.println("\tWrite Count: " + keyspaceWriteCount);
+            out.println("\tWrite Latency: " + String.format("%s", 
keyspaceWriteLatency) + " ms.");
+            out.println("\tPending Flushes: " + keyspacePendingFlushes);
 
             // print out column family statistics for this keyspace
             for (ColumnFamilyStoreMBean table : columnFamilies)
             {
                 String tableName = table.getColumnFamilyName();
                 if (tableName.contains("."))
-                    System.out.println("\t\tTable (index): " + tableName);
+                    out.println("\t\tTable (index): " + tableName);
                 else
-                    System.out.println("\t\tTable: " + tableName);
+                    out.println("\t\tTable: " + tableName);
 
-                System.out.println("\t\tSSTable count: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "LiveSSTableCount"));
+                out.println("\t\tSSTable count: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "LiveSSTableCount"));
 
                 int[] leveledSStables = table.getSSTableCountPerLevel();
                 if (leveledSStables != null)
                 {
-                    System.out.print("\t\tSSTables in each level: [");
+                    out.print("\t\tSSTables in each level: [");
                     for (int level = 0; level < leveledSStables.length; 
level++)
                     {
                         int count = leveledSStables[level];
-                        System.out.print(count);
+                        out.print(count);
                         long maxCount = 4L; // for L0
                         if (level > 0)
                             maxCount = (long) Math.pow(10, level);
                         //  show max threshold for level when exceeded
                         if (count > maxCount)
-                            System.out.print("/" + maxCount);
+                            out.print("/" + maxCount);
 
                         if (level < leveledSStables.length - 1)
-                            System.out.print(", ");
+                            out.print(", ");
                         else
-                            System.out.println("]");
+                            out.println("]");
                     }
                 }
 
@@ -179,12 +181,12 @@ public class TableStats extends NodeToolCmd
                         throw e;
                 }
 
-                System.out.println("\t\tSpace used (live): " + format((Long) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "LiveDiskSpaceUsed"), 
humanReadable));
-                System.out.println("\t\tSpace used (total): " + format((Long) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "TotalDiskSpaceUsed"), 
humanReadable));
-                System.out.println("\t\tSpace used by snapshots (total): " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"SnapshotsSize"), humanReadable));
+                out.println("\t\tSpace used (live): " + format((Long) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "LiveDiskSpaceUsed"), 
humanReadable));
+                out.println("\t\tSpace used (total): " + format((Long) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "TotalDiskSpaceUsed"), 
humanReadable));
+                out.println("\t\tSpace used by snapshots (total): " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"SnapshotsSize"), humanReadable));
                 if (offHeapSize != null)
-                    System.out.println("\t\tOff heap memory used (total): " + 
format(offHeapSize, humanReadable));
-                System.out.println("\t\tSSTable Compression Ratio: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "CompressionRatio"));
+                    out.println("\t\tOff heap memory used (total): " + 
format(offHeapSize, humanReadable));
+                out.println("\t\tSSTable Compression Ratio: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "CompressionRatio"));
 
                 Object estimatedRowCount = 
probe.getColumnFamilyMetric(keyspaceName, tableName, "EstimatedRowCount");
                 if (Long.valueOf(-1L).equals(estimatedRowCount))
@@ -192,45 +194,45 @@ public class TableStats extends NodeToolCmd
                     estimatedRowCount = 0L;
                 }
 
-                System.out.println("\t\tNumber of keys (estimate): " + 
estimatedRowCount);
+                out.println("\t\tNumber of keys (estimate): " + 
estimatedRowCount);
 
-                System.out.println("\t\tMemtable cell count: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableColumnsCount"));
-                System.out.println("\t\tMemtable data size: " + format((Long) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableLiveDataSize"), 
humanReadable));
+                out.println("\t\tMemtable cell count: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableColumnsCount"));
+                out.println("\t\tMemtable data size: " + format((Long) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableLiveDataSize"), 
humanReadable));
                 if (memtableOffHeapSize != null)
-                    System.out.println("\t\tMemtable off heap memory used: " + 
format(memtableOffHeapSize, humanReadable));
-                System.out.println("\t\tMemtable switch count: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableSwitchCount"));
-                System.out.println("\t\tLocal read count: " + 
((CassandraMetricsRegistry.JmxTimerMBean) 
probe.getColumnFamilyMetric(keyspaceName, tableName, 
"ReadLatency")).getCount());
+                    out.println("\t\tMemtable off heap memory used: " + 
format(memtableOffHeapSize, humanReadable));
+                out.println("\t\tMemtable switch count: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableSwitchCount"));
+                out.println("\t\tLocal read count: " + 
((CassandraMetricsRegistry.JmxTimerMBean) 
probe.getColumnFamilyMetric(keyspaceName, tableName, 
"ReadLatency")).getCount());
                 double localReadLatency = 
((CassandraMetricsRegistry.JmxTimerMBean) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "ReadLatency")).getMean() 
/ 1000;
                 double localRLatency = localReadLatency > 0 ? localReadLatency 
: Double.NaN;
-                System.out.printf("\t\tLocal read latency: %01.3f ms%n", 
localRLatency);
-                System.out.println("\t\tLocal write count: " + 
((CassandraMetricsRegistry.JmxTimerMBean) 
probe.getColumnFamilyMetric(keyspaceName, tableName, 
"WriteLatency")).getCount());
+                out.printf("\t\tLocal read latency: %01.3f ms%n", 
localRLatency);
+                out.println("\t\tLocal write count: " + 
((CassandraMetricsRegistry.JmxTimerMBean) 
probe.getColumnFamilyMetric(keyspaceName, tableName, 
"WriteLatency")).getCount());
                 double localWriteLatency = 
((CassandraMetricsRegistry.JmxTimerMBean) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "WriteLatency")).getMean() 
/ 1000;
                 double localWLatency = localWriteLatency > 0 ? 
localWriteLatency : Double.NaN;
-                System.out.printf("\t\tLocal write latency: %01.3f ms%n", 
localWLatency);
-                System.out.println("\t\tPending flushes: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "PendingFlushes"));
-                System.out.println("\t\tBloom filter false positives: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, 
"BloomFilterFalsePositives"));
-                System.out.printf("\t\tBloom filter false ratio: %s%n", 
String.format("%01.5f", probe.getColumnFamilyMetric(keyspaceName, tableName, 
"RecentBloomFilterFalseRatio")));
-                System.out.println("\t\tBloom filter space used: " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"BloomFilterDiskSpaceUsed"), humanReadable));
+                out.printf("\t\tLocal write latency: %01.3f ms%n", 
localWLatency);
+                out.println("\t\tPending flushes: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, "PendingFlushes"));
+                out.println("\t\tBloom filter false positives: " + 
probe.getColumnFamilyMetric(keyspaceName, tableName, 
"BloomFilterFalsePositives"));
+                out.printf("\t\tBloom filter false ratio: %s%n", 
String.format("%01.5f", probe.getColumnFamilyMetric(keyspaceName, tableName, 
"RecentBloomFilterFalseRatio")));
+                out.println("\t\tBloom filter space used: " + format((Long) 
probe.getColumnFamilyMetric(keyspaceName, tableName, 
"BloomFilterDiskSpaceUsed"), humanReadable));
                 if (bloomFilterOffHeapSize != null)
-                    System.out.println("\t\tBloom filter off heap memory used: 
" + format(bloomFilterOffHeapSize, humanReadable));
+                    out.println("\t\tBloom filter off heap memory used: " + 
format(bloomFilterOffHeapSize, humanReadable));
                 if (indexSummaryOffHeapSize != null)
-                    System.out.println("\t\tIndex summary off heap memory 
used: " + format(indexSummaryOffHeapSize, humanReadable));
+                    out.println("\t\tIndex summary off heap memory used: " + 
format(indexSummaryOffHeapSize, humanReadable));
                 if (compressionMetadataOffHeapSize != null)
-                    System.out.println("\t\tCompression metadata off heap 
memory used: " + format(compressionMetadataOffHeapSize, humanReadable));
+                    out.println("\t\tCompression metadata off heap memory 
used: " + format(compressionMetadataOffHeapSize, humanReadable));
 
-                System.out.println("\t\tCompacted partition minimum bytes: " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"MinRowSize"), humanReadable));
-                System.out.println("\t\tCompacted partition maximum bytes: " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"MaxRowSize"), humanReadable));
-                System.out.println("\t\tCompacted partition mean bytes: " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"MeanRowSize"), humanReadable));
+                out.println("\t\tCompacted partition minimum bytes: " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"MinRowSize"), humanReadable));
+                out.println("\t\tCompacted partition maximum bytes: " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"MaxRowSize"), humanReadable));
+                out.println("\t\tCompacted partition mean bytes: " + 
format((Long) probe.getColumnFamilyMetric(keyspaceName, tableName, 
"MeanRowSize"), humanReadable));
                 CassandraMetricsRegistry.JmxHistogramMBean histogram = 
(CassandraMetricsRegistry.JmxHistogramMBean) 
probe.getColumnFamilyMetric(keyspaceName, tableName, "LiveScannedHistogram");
-                System.out.println("\t\tAverage live cells per slice (last 
five minutes): " + histogram.getMean());
-                System.out.println("\t\tMaximum live cells per slice (last 
five minutes): " + histogram.getMax());
+                out.println("\t\tAverage live cells per slice (last five 
minutes): " + histogram.getMean());
+                out.println("\t\tMaximum live cells per slice (last five 
minutes): " + histogram.getMax());
                 histogram = (CassandraMetricsRegistry.JmxHistogramMBean) 
probe.getColumnFamilyMetric(keyspaceName, tableName, 
"TombstoneScannedHistogram");
-                System.out.println("\t\tAverage tombstones per slice (last 
five minutes): " + histogram.getMean());
-                System.out.println("\t\tMaximum tombstones per slice (last 
five minutes): " + histogram.getMax());
+                out.println("\t\tAverage tombstones per slice (last five 
minutes): " + histogram.getMean());
+                out.println("\t\tMaximum tombstones per slice (last five 
minutes): " + histogram.getMax());
 
-                System.out.println("");
+                out.println("");
             }
-            System.out.println("----------------");
+            out.println("----------------");
         }
     }
 
diff --git a/src/java/org/apache/cassandra/tools/nodetool/TopPartitions.java 
b/src/java/org/apache/cassandra/tools/nodetool/TopPartitions.java
index 35e13ce..c656eec 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/TopPartitions.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/TopPartitions.java
@@ -23,6 +23,7 @@ import io.airlift.command.Arguments;
 import io.airlift.command.Command;
 import io.airlift.command.Option;
 
+import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -57,6 +58,7 @@ public class TopPartitions extends NodeToolCmd
     {
         checkArgument(args.size() == 3, "toppartitions requires keyspace, 
column family name, and duration");
         checkArgument(topCount < size, "TopK count (-k) option must be smaller 
then the summary capacity (-s)");
+        PrintStream out = probe.output().out;
         String keyspace = args.get(0);
         String cfname = args.get(1);
         Integer duration = Integer.parseInt(args.get(2));
@@ -95,23 +97,23 @@ public class TopPartitions extends NodeToolCmd
                 }
             });
             if(!first)
-                System.out.println();
-            System.out.println(result.getKey().toString()+ " Sampler:");
-            System.out.printf("  Cardinality: ~%d (%d capacity)%n", (long) 
sampling.get("cardinality"), size);
-            System.out.printf("  Top %d partitions:%n", topCount);
+                out.println();
+            out.println(result.getKey().toString()+ " Sampler:");
+            out.printf("  Cardinality: ~%d (%d capacity)%n", (long) 
sampling.get("cardinality"), size);
+            out.printf("  Top %d partitions:%n", topCount);
             if (topk.size() == 0)
             {
-                System.out.println("\tNothing recorded during sampling 
period...");
+                out.println("\tNothing recorded during sampling period...");
             } else
             {
                 int offset = 0;
                 for (CompositeData entry : topk)
                     offset = Math.max(offset, 
entry.get("string").toString().length());
-                System.out.printf("\t%-" + offset + "s%10s%10s%n", 
"Partition", "Count", "+/-");
+                out.printf("\t%-" + offset + "s%10s%10s%n", "Partition", 
"Count", "+/-");
                 for (CompositeData entry : topk)
-                    System.out.printf("\t%-" + offset + "s%10d%10d%n", 
entry.get("string").toString(), entry.get("count"), entry.get("error"));
+                    out.printf("\t%-" + offset + "s%10d%10d%n", 
entry.get("string").toString(), entry.get("count"), entry.get("error"));
             }
             first = false;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/TpStats.java 
b/src/java/org/apache/cassandra/tools/nodetool/TpStats.java
index f3448ab..abee213 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/TpStats.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/TpStats.java
@@ -19,6 +19,7 @@ package org.apache.cassandra.tools.nodetool;
 
 import io.airlift.command.Command;
 
+import java.io.PrintStream;
 import java.util.Map;
 
 import com.google.common.collect.Multimap;
@@ -32,13 +33,14 @@ public class TpStats extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.printf("%-25s%10s%10s%15s%10s%18s%n", "Pool Name", 
"Active", "Pending", "Completed", "Blocked", "All time blocked");
+        PrintStream out = probe.output().out;
+        out.printf("%-25s%10s%10s%15s%10s%18s%n", "Pool Name", "Active", 
"Pending", "Completed", "Blocked", "All time blocked");
 
         Multimap<String, String> threadPools = probe.getThreadPools();
 
         for (Map.Entry<String, String> tpool : threadPools.entries())
         {
-            System.out.printf("%-25s%10s%10s%15s%10s%18s%n",
+            out.printf("%-25s%10s%10s%15s%10s%18s%n",
                               tpool.getValue(),
                               probe.getThreadPoolMetric(tpool.getKey(), 
tpool.getValue(), "ActiveTasks"),
                               probe.getThreadPoolMetric(tpool.getKey(), 
tpool.getValue(), "PendingTasks"),
@@ -47,8 +49,8 @@ public class TpStats extends NodeToolCmd
                               probe.getThreadPoolMetric(tpool.getKey(), 
tpool.getValue(), "TotalBlockedTasks"));
         }
 
-        System.out.printf("%n%-20s%10s%n", "Message type", "Dropped");
+        out.printf("%n%-20s%10s%n", "Message type", "Dropped");
         for (Map.Entry<String, Integer> entry : 
probe.getDroppedMessages().entrySet())
-            System.out.printf("%-20s%10s%n", entry.getKey(), entry.getValue());
+            out.printf("%-20s%10s%n", entry.getKey(), entry.getValue());
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/UpgradeSSTable.java 
b/src/java/org/apache/cassandra/tools/nodetool/UpgradeSSTable.java
index fcb1ab2..5623793 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/UpgradeSSTable.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/UpgradeSSTable.java
@@ -51,7 +51,7 @@ public class UpgradeSSTable extends NodeToolCmd
         {
             try
             {
-                probe.upgradeSSTables(System.out, keyspace, !includeAll, jobs, 
cfnames);
+                probe.upgradeSSTables(probe.output().out, keyspace, 
!includeAll, jobs, cfnames);
             } catch (Exception e)
             {
                 throw new RuntimeException("Error occurred during enabling 
auto-compaction", e);
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Verify.java 
b/src/java/org/apache/cassandra/tools/nodetool/Verify.java
index 813b761..7a3ccd6 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Verify.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Verify.java
@@ -48,11 +48,11 @@ public class Verify extends NodeToolCmd
         {
             try
             {
-                probe.verify(System.out, extendedVerify, keyspace, cfnames);
+                probe.verify(probe.output().out, extendedVerify, keyspace, 
cfnames);
             } catch (Exception e)
             {
                 throw new RuntimeException("Error occurred during verifying", 
e);
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/java/org/apache/cassandra/tools/nodetool/Version.java 
b/src/java/org/apache/cassandra/tools/nodetool/Version.java
index 2495508..ffd4b06 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/Version.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/Version.java
@@ -28,6 +28,6 @@ public class Version extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        System.out.println("ReleaseVersion: " + probe.getReleaseVersion());
+        probe.output().out.println("ReleaseVersion: " + 
probe.getReleaseVersion());
     }
-}
\ No newline at end of file
+}
diff --git 
a/test/distributed/org/apache/cassandra/distributed/impl/Instance.java 
b/test/distributed/org/apache/cassandra/distributed/impl/Instance.java
index b87c2b8..2159e03 100644
--- a/test/distributed/org/apache/cassandra/distributed/impl/Instance.java
+++ b/test/distributed/org/apache/cassandra/distributed/impl/Instance.java
@@ -23,6 +23,9 @@ import java.io.DataInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.net.InetAddress;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.PrintStream;
 import java.net.InetSocketAddress;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
@@ -95,6 +98,7 @@ import org.apache.cassandra.service.QueryState;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.service.StorageServiceMBean;
 import org.apache.cassandra.streaming.StreamCoordinator;
+import org.apache.cassandra.tools.Output;
 import org.apache.cassandra.tools.NodeTool;
 import org.apache.cassandra.tracing.TraceState;
 import org.apache.cassandra.tracing.Tracing;
@@ -745,20 +749,66 @@ public class Instance extends IsolatedExecutor implements 
IInvokableInstance
     public NodeToolResult nodetoolResult(boolean withNotifications, String... 
commandAndArgs)
     {
         return sync(() -> {
-            DTestNodeTool nodetool = new DTestNodeTool(withNotifications);
-            int rc =  nodetool.execute(commandAndArgs);
-            return new NodeToolResult(commandAndArgs, rc, new 
ArrayList<>(nodetool.notifications.notifications), nodetool.latestError);
+            try (CapturingOutput output = new CapturingOutput())
+            {
+                DTestNodeTool nodetool = new DTestNodeTool(withNotifications, 
output.delegate);
+                int rc = nodetool.execute(commandAndArgs);
+                return new NodeToolResult(commandAndArgs, rc,
+                                          new 
ArrayList<>(nodetool.notifications.notifications),
+                                          nodetool.latestError,
+                                          output.getOutString(),
+                                          output.getErrString());
+            }
         }).call();
     }
 
-    private static class DTestNodeTool extends NodeTool {
+    private static class CapturingOutput implements Closeable
+    {
+        @SuppressWarnings("resource")
+        private final ByteArrayOutputStream outBase = new 
ByteArrayOutputStream();
+        @SuppressWarnings("resource")
+        private final ByteArrayOutputStream errBase = new 
ByteArrayOutputStream();
+
+        public final PrintStream out;
+        public final PrintStream err;
+        private final Output delegate;
+
+        public CapturingOutput()
+        {
+            PrintStream out = new PrintStream(outBase, true);
+            PrintStream err = new PrintStream(errBase, true);
+            this.delegate = new Output(out, err);
+            this.out = out;
+            this.err = err;
+        }
+
+        public String getOutString()
+        {
+            out.flush();
+            return outBase.toString();
+        }
+
+        public String getErrString()
+        {
+            err.flush();
+            return errBase.toString();
+        }
+
+        public void close()
+        {
+            out.close();
+            err.close();
+        }
+    }
+
+    public static class DTestNodeTool extends NodeTool {
         private final StorageServiceMBean storageProxy;
         private final CollectingNotificationListener notifications = new 
CollectingNotificationListener();
 
         private Throwable latestError;
 
-        DTestNodeTool(boolean withNotifications) {
-            super(new InternalNodeProbeFactory(withNotifications));
+        public DTestNodeTool(boolean withNotifications, Output output) {
+            super(new InternalNodeProbeFactory(withNotifications), output);
             storageProxy = new 
InternalNodeProbe(withNotifications).getStorageService();
             storageProxy.addNotificationListener(notifications, null, null);
         }
diff --git 
a/test/distributed/org/apache/cassandra/distributed/test/ClientNetworkStopStartTest.java
 
b/test/distributed/org/apache/cassandra/distributed/test/ClientNetworkStopStartTest.java
index 1d23ac7..da0731e 100644
--- 
a/test/distributed/org/apache/cassandra/distributed/test/ClientNetworkStopStartTest.java
+++ 
b/test/distributed/org/apache/cassandra/distributed/test/ClientNetworkStopStartTest.java
@@ -18,14 +18,11 @@
 
 package org.apache.cassandra.distributed.test;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.PrintStream;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Objects;
 
-import org.junit.Assert;
 import org.junit.Test;
 
 import com.datastax.driver.core.Session;
@@ -34,6 +31,7 @@ import org.apache.cassandra.distributed.Cluster;
 import org.apache.cassandra.distributed.api.ConsistencyLevel;
 import org.apache.cassandra.distributed.api.Feature;
 import org.apache.cassandra.distributed.api.IInvokableInstance;
+import org.apache.cassandra.distributed.api.NodeToolResult;
 import org.apache.cassandra.distributed.api.QueryResults;
 import org.apache.cassandra.distributed.api.SimpleQueryResult;
 import org.apache.cassandra.distributed.shared.AssertUtils;
@@ -128,26 +126,10 @@ public class ClientNetworkStopStartTest extends 
TestBaseImpl
 
     private static void assertNodetoolStdout(IInvokableInstance node, String 
expectedStatus, String notExpected, String... nodetool)
     {
-        // without CASSANDRA-16057 need this hack
-        PrintStream previousStdout = System.out;
-        try
-        {
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            PrintStream stdout = new PrintStream(out, true);
-            System.setOut(stdout);
-
-            node.nodetoolResult(nodetool).asserts().success();
-
-            stdout.flush();
-            String output = out.toString();
-            Assert.assertThat(output, new StringContains(expectedStatus));
-            if (notExpected != null)
-                Assert.assertThat(output, new StringNotContains(notExpected));
-        }
-        finally
-        {
-            System.setOut(previousStdout);
-        }
+        NodeToolResult.Asserts asserts = 
node.nodetoolResult(nodetool).asserts();
+        asserts.stdoutContains(expectedStatus);
+        if (notExpected != null)
+            asserts.stdoutNotContains(notExpected);
     }
 
     private static final class StringContains extends BaseMatcher<String>
diff --git 
a/test/distributed/org/apache/cassandra/distributed/test/NodeToolTest.java 
b/test/distributed/org/apache/cassandra/distributed/test/NodeToolTest.java
index 1d78152..d8b9ce7 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/NodeToolTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/NodeToolTest.java
@@ -21,13 +21,15 @@ package org.apache.cassandra.distributed.test;
 import org.junit.Test;
 
 import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ICluster;
+import org.apache.cassandra.distributed.api.NodeToolResult;
 
 import static org.junit.Assert.assertEquals;
 
 public class NodeToolTest extends TestBaseImpl
 {
     @Test
-    public void test() throws Throwable
+    public void testCommands() throws Throwable
     {
         try (Cluster cluster = init(Cluster.create(1)))
         {
@@ -36,4 +38,16 @@ public class NodeToolTest extends TestBaseImpl
             assertEquals(1, cluster.get(1).nodetool("not_a_legal_command"));
         }
     }
+
+    @Test
+    public void testCaptureConsoleOutput() throws Throwable
+    {
+        try (ICluster cluster = init(builder().withNodes(1).start()))
+        {
+            NodeToolResult ringResult = cluster.get(1).nodetoolResult("ring");
+            ringResult.asserts().stdoutContains("Datacenter: datacenter0");
+            ringResult.asserts().stdoutContains("127.0.0.1  rack0       Up     
Normal");
+            assertEquals("Non-empty error output", "", ringResult.getStderr());
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to