This is an automated email from the ASF dual-hosted git repository. brandonwilliams pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push: new e8d3743 sstablemetadata unit test, docs and params parsing hardening e8d3743 is described below commit e8d3743b1aa25a23f04726903d0cbf61f9824fe0 Author: Bereng <berenguerbl...@gmail.com> AuthorDate: Tue Oct 6 05:40:01 2020 +0200 sstablemetadata unit test, docs and params parsing hardening Patch by Bereguer Blasi, reviewed by brandonwilliams for CASSANDRA-16016 --- doc/source/tools/sstable/sstablemetadata.rst | 8 +- .../cassandra/tools/SSTableLevelResetterTest.java | 2 +- .../cassandra/tools/SSTableMetadataViewerTest.java | 94 ++++++++++++++++------ .../cassandra/tools/StandaloneSSTableUtilTest.java | 2 +- .../cassandra/tools/StandaloneScrubberTest.java | 2 +- .../cassandra/tools/StandaloneUpgraderTest.java | 4 +- .../cassandra/tools/StandaloneVerifierTest.java | 2 +- 7 files changed, 83 insertions(+), 31 deletions(-) diff --git a/doc/source/tools/sstable/sstablemetadata.rst b/doc/source/tools/sstable/sstablemetadata.rst index 0a7a422..48a1de5 100644 --- a/doc/source/tools/sstable/sstablemetadata.rst +++ b/doc/source/tools/sstable/sstablemetadata.rst @@ -29,7 +29,11 @@ Usage sstablemetadata <options> <sstable filename(s)> ========================= ================================================================================ ---gc_grace_seconds <arg> The gc_grace_seconds to use when calculating droppable tombstones +-c,--colors Use ANSI color sequences +-g,--gc_grace_seconds <arg> Time to use when calculating droppable tombstones +-s,--scan Full sstable scan for additional details. Only available in 3.0+ sstables. Defaults: false +-t,--timestamp_unit <arg> Time unit that cell timestamps are written with +-u,--unicode Use unicode to draw histograms and progress bars ========================= ================================================================================ Print all the metadata @@ -252,7 +256,7 @@ Example:: sstablemetadata --gc_grace_seconds 4700 /var/lib/cassandra/data/keyspace1/standard1-41b52700b4ed11e896476d2c86545d91/mc-12-big-Data.db | grep "Estimated droppable tombstones" Estimated droppable tombstones: 9.61111111111111E-6 - # if gc_grace_seconds was configured at 100, none of the tombstones would be currently droppable + # if gc_grace_seconds was configured at 5000, none of the tombstones would be currently droppable sstablemetadata --gc_grace_seconds 5000 /var/lib/cassandra/data/keyspace1/standard1-41b52700b4ed11e896476d2c86545d91/mc-12-big-Data.db | grep "Estimated droppable tombstones" Estimated droppable tombstones: 0.0 diff --git a/test/unit/org/apache/cassandra/tools/SSTableLevelResetterTest.java b/test/unit/org/apache/cassandra/tools/SSTableLevelResetterTest.java index e413b14..3f1c892 100644 --- a/test/unit/org/apache/cassandra/tools/SSTableLevelResetterTest.java +++ b/test/unit/org/apache/cassandra/tools/SSTableLevelResetterTest.java @@ -73,7 +73,7 @@ public class SSTableLevelResetterTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(SSTableLevelResetter.class, "--really-reset", "system_schema", "tables"); assertThat(tool.getStdout(), CoreMatchers.containsStringIgnoringCase("Found no sstables,")); Assertions.assertThat(tool.getCleanedStderr()).isEmpty(); - assertEquals(0,tool.getExitCode()); + assertEquals(0, tool.getExitCode()); assertCorrectEnvPostTest(); } diff --git a/test/unit/org/apache/cassandra/tools/SSTableMetadataViewerTest.java b/test/unit/org/apache/cassandra/tools/SSTableMetadataViewerTest.java index db0c958..7fd1353 100644 --- a/test/unit/org/apache/cassandra/tools/SSTableMetadataViewerTest.java +++ b/test/unit/org/apache/cassandra/tools/SSTableMetadataViewerTest.java @@ -18,11 +18,14 @@ package org.apache.cassandra.tools; +import java.io.IOException; import java.util.Arrays; -import org.apache.commons.codec.digest.DigestUtils; +import com.google.common.base.CharMatcher; + import org.apache.commons.lang3.tuple.Pair; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,11 +37,18 @@ import org.hamcrest.CoreMatchers; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; @RunWith(OrderedJUnit4ClassRunner.class) public class SSTableMetadataViewerTest extends OfflineToolUtils { + private static String sstable; + + @BeforeClass + public static void setupTest() throws IOException + { + sstable = findOneSSTable("legacy_sstables", "legacy_ma_simple"); + } + @Test public void testNoArgsPrintsHelp() { @@ -77,36 +87,63 @@ public class SSTableMetadataViewerTest extends OfflineToolUtils @Test public void testWrongArgFailsAndPrintsHelp() { - ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, "--debugwrong", "ks", "tab"); + ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, "--debugwrong", "sstableFile"); assertTrue(tool.getStdout(), tool.getStdout().isEmpty()); assertThat(tool.getCleanedStderr(), CoreMatchers.containsStringIgnoringCase("Options:")); assertEquals(1, tool.getExitCode()); } @Test - public void testDefaultCall() + public void testNAFileCall() { - ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, "ks", "tab"); + ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, "mockFile"); assertThat(tool.getStdout(), CoreMatchers.containsStringIgnoringCase("No such file")); Assertions.assertThat(tool.getCleanedStderr()).isEmpty(); - assertEquals(0,tool.getExitCode()); + assertEquals(0, tool.getExitCode()); + assertGoodEnvPostTest(); + } + + @Test + public void testOnlySstableArg() + { + ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, sstable); + Assertions.assertThat(tool.getStdout()).doesNotContain(Util.BLUE); + assertTrue(tool.getStdout(), CharMatcher.ascii().matchesAllOf(tool.getStdout())); + Assertions.assertThat(tool.getStdout()).doesNotContain("Widest Partitions"); + Assertions.assertThat(tool.getStdout()).contains(sstable.replaceAll("-Data\\.db$", "")); + assertTrue(tool.getStderr(), tool.getStderr().isEmpty()); + assertEquals(0, tool.getExitCode()); assertGoodEnvPostTest(); } @Test - public void testFlagArgs() + public void testColorArg() { Arrays.asList("-c", - "--colors", - "-s", - "--scan", - "-u", + "--colors") + .stream() + .forEach(arg -> { + ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, arg, sstable); + Assertions.assertThat(tool.getStdout()).contains(Util.BLUE); + Assertions.assertThat(tool.getStdout()).contains(sstable.replaceAll("-Data\\.db$", "")); + assertTrue("Arg: [" + arg + "]\n" + tool.getStderr(), tool.getStderr().isEmpty()); + assertEquals(0, tool.getExitCode()); + assertGoodEnvPostTest(); + }); + } + + @Test + public void testUnicodeArg() + { + Arrays.asList("-u", "--unicode") + .stream() .forEach(arg -> { - ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, arg, "ks", "tab"); - assertThat("Arg: [" + arg + "]", tool.getStdout(), CoreMatchers.containsStringIgnoringCase("No such file")); - Assertions.assertThat(tool.getCleanedStderr()).as("Arg: [%s]", arg).isEmpty(); - assertEquals(0,tool.getExitCode()); + ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, arg, sstable); + assertTrue(tool.getStdout(), !CharMatcher.ascii().matchesAllOf(tool.getStdout())); + Assertions.assertThat(tool.getStdout()).contains(sstable.replaceAll("-Data\\.db$", "")); + assertTrue("Arg: [" + arg + "]\n" + tool.getStderr(), tool.getStderr().isEmpty()); + assertEquals(0, tool.getExitCode()); assertGoodEnvPostTest(); }); } @@ -122,8 +159,7 @@ public class SSTableMetadataViewerTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, arg.getLeft(), arg.getRight(), - "ks", - "tab"); + "mockFile"); assertEquals(-1, tool.getExitCode()); Assertions.assertThat(tool.getStderr()).contains(NumberFormatException.class.getSimpleName()); }); @@ -132,8 +168,7 @@ public class SSTableMetadataViewerTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, arg.getLeft(), arg.getRight(), - "ks", - "tab"); + "mockFile"); assertThat("Arg: [" + arg + "]", tool.getStdout(), CoreMatchers.containsStringIgnoringCase("No such file")); Assertions.assertThat(tool.getCleanedStderr()).as("Arg: [%s]", arg).isEmpty(); tool.assertOnExitCode(); @@ -152,8 +187,7 @@ public class SSTableMetadataViewerTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, arg.getLeft(), arg.getRight(), - "ks", - "tab"); + "mockFile"); assertEquals(-1, tool.getExitCode()); Assertions.assertThat(tool.getStderr()).contains(IllegalArgumentException.class.getSimpleName()); }); @@ -162,8 +196,7 @@ public class SSTableMetadataViewerTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, arg.getLeft(), arg.getRight(), - "ks", - "tab"); + "mockFile"); assertThat("Arg: [" + arg + "]", tool.getStdout(), CoreMatchers.containsStringIgnoringCase("No such file")); Assertions.assertThat(tool.getCleanedStderr()).as("Arg: [%s]", arg).isEmpty(); tool.assertOnExitCode(); @@ -171,6 +204,21 @@ public class SSTableMetadataViewerTest extends OfflineToolUtils }); } + @Test + public void testScanArg() + { + Arrays.asList("-s", + "--scan") + .stream() + .forEach(arg -> { + ToolResult tool = ToolRunner.invokeClass(SSTableMetadataViewer.class, arg, sstable); + Assertions.assertThat(tool.getStdout()).contains("Widest Partitions"); + Assertions.assertThat(tool.getStdout()).contains(sstable.replaceAll("-Data\\.db$", "")); + assertTrue("Arg: [" + arg + "]\n" + tool.getStderr(), tool.getStderr().isEmpty()); + assertEquals(0, tool.getExitCode()); + }); + } + private void assertGoodEnvPostTest() { assertNoUnexpectedThreadsStarted(null, OPTIONAL_THREADS_WITH_SCHEMA); diff --git a/test/unit/org/apache/cassandra/tools/StandaloneSSTableUtilTest.java b/test/unit/org/apache/cassandra/tools/StandaloneSSTableUtilTest.java index 460fb10..efe7396 100644 --- a/test/unit/org/apache/cassandra/tools/StandaloneSSTableUtilTest.java +++ b/test/unit/org/apache/cassandra/tools/StandaloneSSTableUtilTest.java @@ -86,7 +86,7 @@ public class StandaloneSSTableUtilTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(StandaloneSSTableUtil.class, "system_schema", "tables"); assertThat(tool.getStdout(), CoreMatchers.containsStringIgnoringCase("Listing files...")); Assertions.assertThat(tool.getCleanedStderr()).isEmpty(); - assertEquals(0,tool.getExitCode()); + assertEquals(0, tool.getExitCode()); assertCorrectEnvPostTest(); } diff --git a/test/unit/org/apache/cassandra/tools/StandaloneScrubberTest.java b/test/unit/org/apache/cassandra/tools/StandaloneScrubberTest.java index 3593025..f0b996f 100644 --- a/test/unit/org/apache/cassandra/tools/StandaloneScrubberTest.java +++ b/test/unit/org/apache/cassandra/tools/StandaloneScrubberTest.java @@ -101,7 +101,7 @@ public class StandaloneScrubberTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(StandaloneScrubber.class, "system_schema", "tables"); assertThat(tool.getStdout(), CoreMatchers.containsStringIgnoringCase("Pre-scrub sstables snapshotted into snapshot")); Assertions.assertThat(tool.getCleanedStderr()).isEmpty(); - assertEquals(0,tool.getExitCode()); + assertEquals(0, tool.getExitCode()); assertCorrectEnvPostTest(); } diff --git a/test/unit/org/apache/cassandra/tools/StandaloneUpgraderTest.java b/test/unit/org/apache/cassandra/tools/StandaloneUpgraderTest.java index 3a4177b..0f0c6b3 100644 --- a/test/unit/org/apache/cassandra/tools/StandaloneUpgraderTest.java +++ b/test/unit/org/apache/cassandra/tools/StandaloneUpgraderTest.java @@ -87,7 +87,7 @@ public class StandaloneUpgraderTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(StandaloneUpgrader.class, "system_schema", "tables"); Assertions.assertThat(tool.getStdout()).isEqualTo("Found 0 sstables that need upgrading.\n"); Assertions.assertThat(tool.getCleanedStderr()).isEmpty(); - assertEquals(0,tool.getExitCode()); + assertEquals(0, tool.getExitCode()); assertCorrectEnvPostTest(); } @@ -101,7 +101,7 @@ public class StandaloneUpgraderTest extends OfflineToolUtils "tables"); Assertions.assertThat(tool.getStdout()).as("Arg: [%s]", arg).isEqualTo("Found 0 sstables that need upgrading.\n"); Assertions.assertThat(tool.getCleanedStderr()).as("Arg: [%s]", arg).isEmpty(); - assertEquals(0,tool.getExitCode()); + assertEquals(0, tool.getExitCode()); assertCorrectEnvPostTest(); }); } diff --git a/test/unit/org/apache/cassandra/tools/StandaloneVerifierTest.java b/test/unit/org/apache/cassandra/tools/StandaloneVerifierTest.java index f736edd..0494f1f 100644 --- a/test/unit/org/apache/cassandra/tools/StandaloneVerifierTest.java +++ b/test/unit/org/apache/cassandra/tools/StandaloneVerifierTest.java @@ -87,7 +87,7 @@ public class StandaloneVerifierTest extends OfflineToolUtils ToolResult tool = ToolRunner.invokeClass(StandaloneVerifier.class, "system_schema", "tables"); assertThat(tool.getStdout(), CoreMatchers.containsStringIgnoringCase("using the following options")); Assertions.assertThat(tool.getCleanedStderr()).isEmpty(); - assertEquals(0,tool.getExitCode()); + assertEquals(0, tool.getExitCode()); assertCorrectEnvPostTest(); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org