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
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 @@
{
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 @@
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);
}
}