From b74c86404a0d131677286206562bb4bfa3e8e1a9 Mon Sep 17 00:00:00 2001 From: nvharikrishna Date: Sat, 4 Feb 2023 00:02:08 +0530 Subject: [PATCH] Fix the output of FQL dump tool to properly separate entries patch by N V Harikrishna; reviewed by Stefan Miklosovic and Brandon Williams for CASSANDRA-18215 --- CHANGES.txt | 1 + .../cassandra/fqltool/commands/Dump.java | 10 +--- .../cassandra/fqltool/commands/DumpTest.java | 53 +++++++++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ae1135b049..d9c80fb632 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.0.8 + * Fix the output of FQL dump tool to properly separate entries (CASSANDRA-18215) * Add cache type information for maximum memory usage warning message (CASSANDRA-18184) * Fix NPE in fqltool dump on null value (CASSANDRA-18113) * Improve unit tests performance (CASSANDRA-17427) diff --git a/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java b/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java index 8c05db1ed7..e954f81933 100644 --- a/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java +++ b/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java @@ -219,7 +219,6 @@ public class Dump implements Runnable private static void appendValuesToStringBuilder(List values, StringBuilder sb) { - boolean first = true; for (ByteBuffer value : values) { if (null == value) @@ -237,14 +236,7 @@ public class Dump implements Runnable } } - if (first) - { - first = false; - } - else - { - sb.append("-----").append(System.lineSeparator()); - } + sb.append("-----").append(System.lineSeparator()); } } diff --git a/tools/fqltool/test/unit/org/apache/cassandra/fqltool/commands/DumpTest.java b/tools/fqltool/test/unit/org/apache/cassandra/fqltool/commands/DumpTest.java index 77d7563787..c7e332a0c7 100644 --- a/tools/fqltool/test/unit/org/apache/cassandra/fqltool/commands/DumpTest.java +++ b/tools/fqltool/test/unit/org/apache/cassandra/fqltool/commands/DumpTest.java @@ -90,4 +90,57 @@ public class DumpTest Assert.assertEquals(values.stream().filter(Objects::isNull).count(), nullcount); } + + @Test + public void testDumpQueryValuesShouldHaveSeperator() + { + String keyspace = "ks1"; + int value = 1; + List values = Arrays.asList(ByteBuffer.wrap(new byte[]{ (byte) value }), + ByteBuffer.wrap(new byte[]{ (byte) value }), + ByteBuffer.wrap(new byte[]{ (byte) value })); + + QueryOptions queryOptions = QueryOptions.create( + ConsistencyLevel.LOCAL_QUORUM, + values, + true, + 1, + null, + null, + ProtocolVersion.CURRENT, + keyspace + ); + + ValueIn mockValueIn = Mockito.mock(ValueIn.class); + Mockito.when(mockValueIn.text()).thenReturn("INSERT INTO ks1.t1 (k, v1, v2) VALUES (?, ?, ?)"); + + WireIn mockWireIn = Mockito.mock(WireIn.class); + Mockito.when(mockWireIn.read(FullQueryLogger.QUERY)).thenReturn(mockValueIn); + + StringBuilder sb = new StringBuilder(); + Dump.dumpQuery(queryOptions, mockWireIn, sb); + + String[] lines = sb.toString().split(System.lineSeparator()); + boolean valuesStarted = false; + int valueCount = 0; + int separatorCount = 0; + for (String line : lines) + { + if (!valuesStarted && line.startsWith("Values:")) + { + valuesStarted = true; + continue; + } + if (valuesStarted) + { + valueCount++; + if (valueCount % 2 == 0) + { + Assert.assertEquals("-----", line); + separatorCount++; + } + } + } + Assert.assertEquals(values.size(), separatorCount); + } }