Search in sources :

Example 61 with ToolResult

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

the class NodeToolEnableDisableBinaryTest method testEnableDisableBinary.

@Test
public void testEnableDisableBinary() throws Throwable {
    // We can connect
    assertTrue(canConnect());
    // We can't connect after disabling
    ToolResult tool = ToolRunner.invokeNodetoolJvmDtest(cluster.get(1), "disablebinary");
    Assertions.assertThat(tool.getStdout()).containsIgnoringCase("Stop listening for CQL clients");
    assertTrue(tool.getCleanedStderr().isEmpty());
    assertEquals(0, tool.getExitCode());
    assertFalse(canConnect());
    // We can connect after re-enabling
    tool = ToolRunner.invokeNodetoolJvmDtest(cluster.get(1), "enablebinary");
    Assertions.assertThat(tool.getStdout()).containsIgnoringCase("Starting listening for CQL clients");
    assertTrue(tool.getCleanedStderr().isEmpty());
    assertEquals(0, tool.getExitCode());
    assertTrue(canConnect());
}
Also used : ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test)

Example 62 with ToolResult

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

the class StandaloneUpgraderOnSStablesTest method testUpgradeKeepFiles.

@Test
public void testUpgradeKeepFiles() throws Throwable {
    LegacySSTableTest.truncateLegacyTables(legacyId);
    LegacySSTableTest.loadLegacyTables(legacyId);
    List<String> origFiles = getSStableFiles("legacy_tables", "legacy_" + legacyId + "_simple");
    ToolResult tool = ToolRunner.invokeClass(StandaloneUpgrader.class, "-k", "legacy_tables", "legacy_" + legacyId + "_simple");
    Assertions.assertThat(tool.getStdout()).contains("Found 1 sstables that need upgrading.");
    Assertions.assertThat(tool.getStdout()).contains("legacy_tables/legacy_" + legacyId + "_simple");
    Assertions.assertThat(tool.getStdout()).contains("-Data.db");
    tool.assertOnCleanExit();
    List<String> newFiles = getSStableFiles("legacy_tables", "legacy_" + legacyId + "_simple");
    origFiles.removeAll(newFiles);
    // check previous version files are kept
    assertEquals(0, origFiles.size());
    // need to make sure the new sstables are live, so that they get truncated later
    Keyspace.open("legacy_tables").getColumnFamilyStore("legacy_" + legacyId + "_simple").loadNewSSTables();
}
Also used : ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test) LegacySSTableTest(org.apache.cassandra.io.sstable.LegacySSTableTest)

Example 63 with ToolResult

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

the class StandaloneUpgraderOnSStablesTest method testUpgrade.

@Test
public void testUpgrade() throws Throwable {
    LegacySSTableTest.truncateLegacyTables(legacyId);
    LegacySSTableTest.loadLegacyTables(legacyId);
    List<String> origFiles = getSStableFiles("legacy_tables", "legacy_" + legacyId + "_simple");
    ToolResult tool = ToolRunner.invokeClass(StandaloneUpgrader.class, "legacy_tables", "legacy_" + legacyId + "_simple");
    Assertions.assertThat(tool.getStdout()).contains("Found 1 sstables that need upgrading.");
    Assertions.assertThat(tool.getStdout()).contains("legacy_tables/legacy_" + legacyId + "_simple");
    Assertions.assertThat(tool.getStdout()).contains("-Data.db");
    tool.assertOnCleanExit();
    List<String> newFiles = getSStableFiles("legacy_tables", "legacy_" + legacyId + "_simple");
    int origSize = origFiles.size();
    origFiles.removeAll(newFiles);
    // check previous version files are gone
    assertEquals(origSize, origFiles.size());
    // need to make sure the new sstables are live, so that they get truncated later
    Keyspace.open("legacy_tables").getColumnFamilyStore("legacy_" + legacyId + "_simple").loadNewSSTables();
}
Also used : ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test) LegacySSTableTest(org.apache.cassandra.io.sstable.LegacySSTableTest)

Example 64 with ToolResult

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

the class StandaloneVerifierOnSSTablesTest method testCheckVersionWithWrongVersion.

@Test
public void testCheckVersionWithWrongVersion() throws Exception {
    String keyspace = "StandaloneVerifierTestWrongVersions";
    String tableName = "legacy_ma_simple";
    createAndPopulateTable(keyspace, tableName, cfs -> {
        // let's just copy old version files from test data into the source dir
        File testDataDir = new File("test/data/legacy-sstables/ma/legacy_tables/legacy_ma_simple");
        for (org.apache.cassandra.io.util.File cfsDir : cfs.getDirectories().getCFDirectories()) {
            FileUtils.copyDirectory(testDataDir, cfsDir.toJavaIOFile());
        }
    });
    ToolResult tool = ToolRunner.invokeClass(StandaloneVerifier.class, keyspace, tableName, "-c");
    assertEquals(1, tool.getExitCode());
    Assertions.assertThat(tool.getStdout()).contains("is not the latest version, run upgradesstables");
}
Also used : RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test)

Example 65 with ToolResult

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

the class StandaloneVerifierOnSSTablesTest method testCorruptDataFile.

@Test
public void testCorruptDataFile() throws Exception {
    String keyspaceName = "StandaloneVerifierTestCorruptDataKs";
    String corruptDataTable = "corruptDataTable";
    createAndPopulateTable(keyspaceName, corruptDataTable, cfs -> {
        SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
        long row0Start = sstable.getPosition(PartitionPosition.ForKey.get(ByteBufferUtil.bytes("0"), cfs.getPartitioner()), SSTableReader.Operator.EQ).position;
        long row1Start = sstable.getPosition(PartitionPosition.ForKey.get(ByteBufferUtil.bytes("1"), cfs.getPartitioner()), SSTableReader.Operator.EQ).position;
        long startPosition = Math.min(row0Start, row1Start);
        try (RandomAccessFile file = new RandomAccessFile(sstable.getFilename(), "rw")) {
            file.seek(startPosition);
            file.writeBytes(StringUtils.repeat('z', 2));
        }
    });
    ToolResult tool = ToolRunner.invokeClass(StandaloneVerifier.class, keyspaceName, corruptDataTable);
    assertEquals(1, tool.getExitCode());
    Assertions.assertThat(tool.getStdout()).contains("Invalid SSTable", corruptDataTable);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) RandomAccessFile(java.io.RandomAccessFile) 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