Add a formatted row output to assertEmpty in CQL Tester

Patch by Alex Petrov; reviewed by Jason Brown for CASSANDRA-13238

Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/60d3292b
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/60d3292b
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/60d3292b

Branch: refs/heads/cassandra-3.11
Commit: 60d3292b04f35f4cd27801448b089110cc7b5b19
Parents: 1ae8419
Author: Alex Petrov <oleksandr.pet...@gmail.com>
Authored: Wed Mar 8 17:53:46 2017 +0100
Committer: Alex Petrov <oleksandr.pet...@gmail.com>
Committed: Wed Mar 8 17:58:46 2017 +0100

----------------------------------------------------------------------
 CHANGES.txt                                       |  1 +
 .../unit/org/apache/cassandra/cql3/CQLTester.java | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/60d3292b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 7551a7f..0979852 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.13
+ * Add formatted row output to assertEmpty in CQL Tester (CASSANDRA-13238)
 Merged from 2.2:
  * Fix GRANT/REVOKE when keyspace isn't specified (CASSANDRA-13053)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/60d3292b/test/unit/org/apache/cassandra/cql3/CQLTester.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java 
b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index 4732ed3..db3652b 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -957,6 +957,22 @@ public abstract class CQLTester
         assert ignoreExtra || expectedRows.size() == actualRows.size();
     }
 
+    private static List<String> makeRowStrings(UntypedResultSet resultSet)
+    {
+        List<List<ByteBuffer>> rows = new ArrayList<>();
+        for (UntypedResultSet.Row row : resultSet)
+        {
+            List<ByteBuffer> values = new ArrayList<>();
+            for (ColumnSpecification columnSpecification : 
resultSet.metadata())
+            {
+                values.add(row.getBytes(columnSpecification.name.toString()));
+            }
+            rows.add(values);
+        }
+
+        return makeRowStrings(rows, resultSet.metadata());
+    }
+
     private static List<String> makeRowStrings(Iterable<List<ByteBuffer>> 
rows, List<ColumnSpecification> meta)
     {
         List<String> strings = new ArrayList<>();
@@ -1065,7 +1081,7 @@ public abstract class CQLTester
     protected void assertEmpty(UntypedResultSet result) throws Throwable
     {
         if (result != null && !result.isEmpty())
-            throw new AssertionError(String.format("Expected empty result but 
got %d rows", result.size()));
+            throw new AssertionError(String.format("Expected empty result but 
got %d rows: %s \n", result.size(), makeRowStrings(result)));
     }
 
     protected void assertInvalid(String query, Object... values) throws 
Throwable

Reply via email to