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

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


The following commit(s) were added to refs/heads/trunk by this push:
     new 3d36cd1  nodetool assert apis do not include the new stdout and stderr 
in the failure message (#25)
3d36cd1 is described below

commit 3d36cd1890dea0429297e70c1d6dd3813b682b4b
Author: dcapwell <dcapw...@gmail.com>
AuthorDate: Tue Nov 17 10:07:44 2020 -0800

    nodetool assert apis do not include the new stdout and stderr in the 
failure message (#25)
    
    patch by David Capwell; reviewed by Alex Petrov for CASSANDRA-16272
---
 .../cassandra/distributed/api/NodeToolResult.java  |  4 ++
 .../distributed/api/NodeToolOutputTest.java        | 48 +++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/cassandra/distributed/api/NodeToolResult.java 
b/src/main/java/org/apache/cassandra/distributed/api/NodeToolResult.java
index 6cfe4e5..12be426 100644
--- a/src/main/java/org/apache/cassandra/distributed/api/NodeToolResult.java
+++ b/src/main/java/org/apache/cassandra/distributed/api/NodeToolResult.java
@@ -202,6 +202,10 @@ public class NodeToolResult
         {
             StringBuilder sb = new StringBuilder();
             sb.append("nodetool command 
").append(Arrays.toString(commandAndArgs)).append(" 
").append(message).append("\n");
+            if (stdout != null)
+                sb.append("stdout:\n").append(stdout).append("\n");
+            if (stderr != null)
+                sb.append("stderr:\n").append(stderr).append("\n");
             sb.append("Notifications:\n");
             for (Notification n : notifications)
                 sb.append(NodeToolResult.toString(n)).append("\n");
diff --git 
a/src/test/java/org/apache/cassandra/distributed/api/NodeToolOutputTest.java 
b/src/test/java/org/apache/cassandra/distributed/api/NodeToolOutputTest.java
index 4420485..4fb9210 100644
--- a/src/test/java/org/apache/cassandra/distributed/api/NodeToolOutputTest.java
+++ b/src/test/java/org/apache/cassandra/distributed/api/NodeToolOutputTest.java
@@ -18,11 +18,13 @@
 
 package org.apache.cassandra.distributed.api;
 
+import java.util.Arrays;
 import java.util.Collections;
 
 import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.catchThrowableOfType;
 
 public class NodeToolOutputTest
@@ -67,8 +69,52 @@ public class NodeToolOutputTest
         assertThat(exception.getMessage()).contains("Found unexpected 
substring");
     }
 
+    @Test
+    public void testFailContainsLogs()
+    {
+        for (int rc : Arrays.asList(0, 42))
+        {
+            assertThatThrownBy(() -> fail(create(rc, null, null)))
+                    .isInstanceOf(AssertionError.class)
+                    .hasMessageNotContaining("stdout:")
+                    .hasMessageNotContaining("stderr:");
+
+            assertThatThrownBy(() -> fail(create(rc, "this is stdout", null)))
+                    .isInstanceOf(AssertionError.class)
+                    .hasMessageContaining("stdout:\nthis is stdout")
+                    .hasMessageNotContaining("stderr:");
+
+            assertThatThrownBy(() -> fail(create(rc, null, "this is stderr")))
+                    .isInstanceOf(AssertionError.class)
+                    .hasMessageNotContaining("stdout:")
+                    .hasMessageContaining("stderr:\nthis is stderr");
+
+            assertThatThrownBy(() -> fail(create(rc, "this is stdout", "this 
is stderr")))
+                    .isInstanceOf(AssertionError.class)
+                    .hasMessageContaining("stdout:\nthis is stdout")
+                    .hasMessageContaining("stderr:\nthis is stderr");
+        }
+    }
+
+    private static void fail(NodeToolResult result)
+    {
+        if (result.getRc() == 0)
+        {
+            result.asserts().failure();
+        }
+        else
+        {
+            result.asserts().success();
+        }
+    }
+
     private NodeToolResult create(String stdout, String stderr)
     {
-        return new NodeToolResult(null, 0, Collections.emptyList(), null, 
stdout, stderr);
+        return create(0, stdout, stderr);
+    }
+
+    private NodeToolResult create(int rc, String stdout, String stderr)
+    {
+        return new NodeToolResult(null, rc, Collections.emptyList(), null, 
stdout, stderr);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to