Search in sources :

Example 21 with ToolResult

use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.

the class StandaloneScrubberTest method testHeaderFixArg.

@Test
public void testHeaderFixArg() {
    Arrays.asList(Pair.of("-e", ""), Pair.of("-e", "wrong"), Pair.of("--header-fix", ""), Pair.of("--header-fix", "wrong")).forEach(arg -> {
        ToolResult tool = ToolRunner.invokeClass(StandaloneScrubber.class, arg.getLeft(), arg.getRight(), "system_schema", "tables");
        assertThat("Arg: [" + arg + "]", tool.getStdout(), CoreMatchers.containsStringIgnoringCase("usage:"));
        assertTrue("Arg: [" + arg + "]\n" + tool.getCleanedStderr(), tool.getCleanedStderr().contains("Invalid argument value"));
        assertEquals(1, tool.getExitCode());
    });
    Arrays.asList(Pair.of("-e", "validate-only"), Pair.of("-e", "validate"), Pair.of("-e", "fix-only"), Pair.of("-e", "fix"), Pair.of("-e", "off"), Pair.of("--header-fix", "validate-only"), Pair.of("--header-fix", "validate"), Pair.of("--header-fix", "fix-only"), Pair.of("--header-fix", "fix"), Pair.of("--header-fix", "off")).forEach(arg -> {
        ToolResult tool = ToolRunner.invokeClass(StandaloneScrubber.class, arg.getLeft(), arg.getRight(), "system_schema", "tables");
        assertThat("Arg: [" + arg + "]", tool.getStdout(), CoreMatchers.containsStringIgnoringCase("Pre-scrub sstables snapshotted into snapshot"));
        Assertions.assertThat(tool.getCleanedStderr()).as("Arg: [%s]", arg).isEmpty();
        tool.assertOnExitCode();
        assertCorrectEnvPostTest();
    });
}
Also used : ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test)

Example 22 with ToolResult

use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.

the class StandaloneScrubberTest method testMaybeChangeDocs.

@Test
public void testMaybeChangeDocs() {
    // If you added, modified options or help, please update docs if necessary
    ToolResult tool = ToolRunner.invokeClass(StandaloneScrubber.class, "-h");
    String help = "usage: sstablescrub [options] <keyspace> <column_family>\n" + "--\n" + "Scrub the sstable for the provided table.\n" + "--\n" + "Options are:\n" + "    --debug                     display stack traces\n" + " -e,--header-fix <arg>          Option whether and how to perform a check of the sstable serialization-headers and fix\n" + "                                known, fixable issues.\n" + "                                Possible argument values:\n" + "                                - validate-only: validate the serialization-headers, but do not fix those. Do not continue with scrub - i.e. only\n" + "                                validate the header (dry-run of fix-only).\n" + "                                - validate: (default) validate the serialization-headers, but do not fix those and only continue with scrub if no error\n" + "                                were detected.\n" + "                                - fix-only: validate and fix the serialization-headers, don't continue with scrub.\n" + "                                - fix: validate and fix the serialization-headers, do not fix and do not continue with scrub if the serialization-header\n" + "                                check encountered errors.\n" + "                                - off: don't perform the serialization-header checks.\n" + " -h,--help                      display this help message\n" + " -m,--manifest-check            only check and repair the leveled manifest, without actually scrubbing the sstables\n" + " -n,--no-validate               do not validate columns using column validator\n" + " -r,--reinsert-overflowed-ttl   Rewrites rows with overflowed expiration date affected by CASSANDRA-14092 with the\n" + "                                maximum supported expiration date of 2038-01-19T03:14:06+00:00. The rows are rewritten with the original timestamp\n" + "                                incremented by one millisecond to override/supersede any potential tombstone that may have been generated during\n" + "                                compaction of the affected rows.\n" + " -s,--skip-corrupted            skip corrupt rows in counter tables\n" + " -v,--verbose                   verbose output\n";
    Assertions.assertThat(tool.getStdout()).isEqualTo(help);
}
Also used : ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test)

Example 23 with ToolResult

use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.

the class StandaloneScrubberTest method testFlagArgs.

@Test
public void testFlagArgs() {
    Arrays.asList("--debug", "-m", "--manifest-check", "-n", "--no-validate", "-r", "--reinsert-overflowed-ttl", "-s", "--skip-corrupted", "-v", "--verbose").forEach(arg -> {
        ToolResult tool = ToolRunner.invokeClass(StandaloneScrubber.class, arg, "system_schema", "tables");
        assertThat("Arg: [" + arg + "]", tool.getStdout(), CoreMatchers.containsStringIgnoringCase("Pre-scrub sstables snapshotted into snapshot"));
        Assertions.assertThat(tool.getCleanedStderr()).as("Arg: [%s]", arg).isEmpty();
        tool.assertOnExitCode();
        assertCorrectEnvPostTest();
    });
}
Also used : ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test)

Example 24 with ToolResult

use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.

the class StandaloneSplitterWithCQLTesterTest method testSplittingSSTable.

@Test
public void testSplittingSSTable() throws Throwable {
    ToolResult tool = ToolRunner.invokeClass(StandaloneSplitter.class, "-s", "1", sstableFileName);
    List<File> splitFiles = Arrays.asList(sstablesDir.tryList());
    splitFiles.stream().forEach(f -> {
        if (f.name().endsWith("Data.db") && !origSstables.contains(f))
            assertTrue(f.name() + " is way bigger than 1MiB: [" + f.length() + "] bytes", // give a 20% margin on size check
            f.length() <= 1024 * 1024 * 1.2);
    });
    assertTrue(origSstables.size() < splitFiles.size());
    Assertions.assertThat(tool.getStdout()).contains("sstables snapshotted into");
    assertTrue(tool.getCleanedStderr(), tool.getCleanedStderr().isEmpty());
    assertEquals(0, tool.getExitCode());
}
Also used : File(org.apache.cassandra.io.util.File) ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test)

Example 25 with ToolResult

use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.

the class StandaloneUpgraderTest method testMaybeChangeDocs.

@Test
public void testMaybeChangeDocs() {
    // If you added, modified options or help, please update docs if necessary
    ToolResult tool = ToolRunner.invokeClass(StandaloneUpgrader.class, "-h");
    String help = "usage: sstableupgrade [options] <keyspace> <cf> [snapshot]\n" + "--\n" + "Upgrade the sstables in the given cf (or snapshot) to the current version\n" + "of Cassandra.This operation will rewrite the sstables in the specified cf\n" + "to match the currently installed version of Cassandra.\n" + "The snapshot option will only upgrade the specified snapshot. Upgrading\n" + "snapshots is required before attempting to restore a snapshot taken in a\n" + "major version older than the major version Cassandra is currently running.\n" + "This will replace the files in the given snapshot as well as break any\n" + "hard links to live sstables.\n" + "--\n" + "Options are:\n" + "    --debug         display stack traces\n" + " -h,--help          display this help message\n" + " -k,--keep-source   do not delete the source sstables\n";
    Assertions.assertThat(tool.getStdout()).isEqualTo(help);
}
Also used : ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test)

Aggregations

ToolResult (org.apache.cassandra.tools.ToolRunner.ToolResult)123 Test (org.junit.Test)102 File (org.apache.cassandra.io.util.File)4 NoHostAvailableException (com.datastax.driver.core.exceptions.NoHostAvailableException)3 RandomAccessFile (java.io.RandomAccessFile)3 LegacySSTableTest (org.apache.cassandra.io.sstable.LegacySSTableTest)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 Session (com.datastax.driver.core.Session)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Keyspace (org.apache.cassandra.db.Keyspace)1 Cluster (org.apache.cassandra.distributed.Cluster)1 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)1 Ignore (org.junit.Ignore)1