use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.
the class TTLTest method testRecoverOverflowedExpirationWithScrub.
public void testRecoverOverflowedExpirationWithScrub(boolean simple, boolean clustering, boolean runScrub, boolean runSStableScrub, boolean reinsertOverflowedTTL) throws Throwable {
if (reinsertOverflowedTTL) {
assert runScrub || runSStableScrub;
}
createTable(simple, clustering);
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(currentTable());
assertEquals(0, cfs.getLiveSSTables().size());
copySSTablesToTableDir(currentTable(), simple, clustering);
cfs.loadNewSSTables();
if (runScrub) {
cfs.scrub(true, false, true, reinsertOverflowedTTL, 1);
if (reinsertOverflowedTTL) {
if (simple)
assertRows(execute("SELECT * from %s"), row(1, 1, 1), row(2, 2, null));
else
assertRows(execute("SELECT * from %s"), row(1, 1, set("v11", "v12", "v13", "v14")), row(2, 2, set("v21", "v22", "v23", "v24")));
cfs.forceMajorCompaction();
if (simple)
assertRows(execute("SELECT * from %s"), row(1, 1, 1), row(2, 2, null));
else
assertRows(execute("SELECT * from %s"), row(1, 1, set("v11", "v12", "v13", "v14")), row(2, 2, set("v21", "v22", "v23", "v24")));
} else {
assertEmpty(execute("SELECT * from %s"));
}
}
if (runSStableScrub) {
// Necessary for testing
System.setProperty(org.apache.cassandra.tools.Util.ALLOW_TOOL_REINIT_FOR_TEST, "true");
try {
ToolResult tool;
if (reinsertOverflowedTTL)
tool = ToolRunner.invokeClass(StandaloneScrubber.class, "-r", KEYSPACE, cfs.name);
else
tool = ToolRunner.invokeClass(StandaloneScrubber.class, KEYSPACE, cfs.name);
tool.assertOnCleanExit();
Assertions.assertThat(tool.getStdout()).contains("Pre-scrub sstables snapshotted into");
if (reinsertOverflowedTTL)
Assertions.assertThat(tool.getStdout()).contains("Fixed 2 rows with overflowed local deletion time.");
else
Assertions.assertThat(tool.getStdout()).contains("No valid partitions found while scrubbing");
} finally {
System.clearProperty(org.apache.cassandra.tools.Util.ALLOW_TOOL_REINIT_FOR_TEST);
}
}
try {
cfs.truncateBlocking();
dropTable("DROP TABLE %s");
} catch (Throwable e) {
// StandaloneScrubber.class should be ran as a tool with a stable env. In a test env there are things moving
// under its feet such as the async CQLTester.afterTest() operations. We try to sync cleanup of tables here
// but we need to catch any exceptions we might run into bc of the hack. See CASSANDRA-16546
}
}
use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.
the class FqlReplayDDLExclusionTest method test.
@Ignore
@Test
public void test() throws Throwable {
try (final Cluster cluster = init(builder().withNodes(1).withConfig(updater -> updater.with(NETWORK, GOSSIP, NATIVE_PROTOCOL)).start())) {
final IInvokableInstance node = cluster.get(1);
// in Cassandra where events are propagated to logger
try (com.datastax.driver.core.Cluster c = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
Session s = c.connect()) {
s.execute("CREATE KEYSPACE fql_ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};");
node.nodetool("enablefullquerylog", "--path", temporaryFolder.getRoot().getAbsolutePath());
s.execute("CREATE TABLE fql_ks.fql_table (id int primary key);");
s.execute("INSERT INTO fql_ks.fql_table (id) VALUES (1)");
node.nodetool("disablefullquerylog");
// here we are dropping and we expect that ddl replay will reconstruct it
node.executeInternal("DROP TABLE fql_ks.fql_table;");
// without --replay-ddl-statements, the replay will fail on insert because underlying table is not there
final ToolResult negativeRunner = ToolRunner.invokeClass("org.apache.cassandra.fqltool.FullQueryLogTool", "replay", "--keyspace", "fql_ks", "--target", "127.0.0.1", "--", temporaryFolder.getRoot().getAbsolutePath());
assertEquals(0, negativeRunner.getExitCode());
try {
node.executeInternalWithResult("SELECT * from fql_ks.fql_table");
fail("This query should fail because we do not expect fql_ks.fql_table to be created!");
} catch (final Exception ex) {
assertTrue(ex.getMessage().contains("table fql_table does not exist"));
}
// here we replay with --replay-ddl-statements so table will be created and insert will succeed
final ToolResult positiveRunner = ToolRunner.invokeClass("org.apache.cassandra.fqltool.FullQueryLogTool", "replay", "--keyspace", "fql_ks", "--target", "127.0.0.1", // important
"--replay-ddl-statements", "--", temporaryFolder.getRoot().getAbsolutePath());
assertEquals(0, positiveRunner.getExitCode());
assertRows(node.executeInternalWithResult("SELECT * from fql_ks.fql_table"), QueryResults.builder().row(1).build());
}
}
}
use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.
the class SetGetColumnIndexSizeTest method assertSetInvalidColumnIndexSize.
private static void assertSetInvalidColumnIndexSize(String columnIndexSizeInKB, String expectedErrorMessage, int expectedErrorCode) {
ToolResult tool = columnIndexSizeInKB == null ? invokeNodetool("setcolumnindexsize") : invokeNodetool("setcolumnindexsize", columnIndexSizeInKB);
assertThat(tool.getExitCode()).isEqualTo(expectedErrorCode);
assertThat(expectedErrorCode == 1 ? tool.getStdout() : tool.getStderr()).contains(expectedErrorMessage);
}
use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.
the class SetGetColumnIndexSizeTest method assertSetGetValidColumnIndexSize.
private static void assertSetGetValidColumnIndexSize(int columnIndexSizeInKB) {
ToolResult tool = invokeNodetool("setcolumnindexsize", String.valueOf(columnIndexSizeInKB));
tool.assertOnCleanExit();
assertThat(tool.getStdout()).isEmpty();
assertGetThroughput(columnIndexSizeInKB);
assertThat(StorageService.instance.getColumnIndexSizeInKiB()).isEqualTo(columnIndexSizeInKB);
}
use of org.apache.cassandra.tools.ToolRunner.ToolResult in project cassandra by apache.
the class SetGetEntireSSTableStreamThroughputTest method assertGetThroughput.
private static void assertGetThroughput(int expected) {
ToolResult tool = invokeNodetool("getstreamthroughput", "-e");
tool.assertOnCleanExit();
if (expected > 0)
assertThat(tool.getStdout()).contains("Current entire SSTable stream throughput: " + expected + " MiB/s");
else
assertThat(tool.getStdout()).contains("Current entire SSTable stream throughput: unlimited");
}
Aggregations