smiklosovic commented on a change in pull request #1228: URL: https://github.com/apache/cassandra/pull/1228#discussion_r727930694
########## File path: test/unit/org/apache/cassandra/db/virtual/SSTableTasksTableTest.java ########## @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.db.virtual; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.cql3.UntypedResultSet; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.compaction.CompactionInfo; +import org.apache.cassandra.db.compaction.CompactionManager; +import org.apache.cassandra.db.compaction.OperationType; +import org.apache.cassandra.io.sstable.format.SSTableReader; +import org.apache.cassandra.schema.MockSchema; + +public class SSTableTasksTableTest extends CQLTester +{ + private static final String KS_NAME = "vts"; + + @SuppressWarnings("FieldCanBeLocal") + private SSTableTasksTable table; + + @BeforeClass + public static void setUpClass() + { + CQLTester.setUpClass(); + CompactionManager.instance.disableAutoCompaction(); + } + + @Before + public void config() + { + table = new SSTableTasksTable(KS_NAME); + VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table))); + } + + @Test + public void testSelectAll() throws Throwable + { + createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))"); + ColumnFamilyStore cfs = getCurrentColumnFamilyStore(); + + long bytesCompacted = 123; + long bytesTotal = 123456; + UUID compactionId = UUID.randomUUID(); + List<SSTableReader> sstables = IntStream.range(0, 10) + .mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)) + .collect(Collectors.toList()); + CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() + { + public CompactionInfo getCompactionInfo() + { + return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables); + } + + public boolean isGlobal() + { + return false; + } + }; + + CompactionManager.instance.active.beginCompaction(compactionHolder); + UntypedResultSet result = execute("SELECT * FROM vts.sstable_tasks"); + assertRows(result, row(CQLTester.KEYSPACE, currentTable(), compactionId, 1.0 * bytesCompacted / bytesTotal, + OperationType.COMPACTION.toString().toLowerCase(), bytesCompacted, sstables.size(), + bytesTotal, CompactionInfo.Unit.BYTES.toString())); + + CompactionManager.instance.active.finishCompaction(compactionHolder); + result = execute("SELECT * FROM vts.sstable_tasks"); + assertEmpty(result); + } + + @Test + public void testUnsupportedOperations() throws Throwable Review comment: do we really need this test? I think it is given that this is not supported unless your virtual table uses stuff from CASSANDRA-16806. ########## File path: test/unit/org/apache/cassandra/tools/nodetool/CompactionStatsTest.java ########## @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.tools.nodetool; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.compaction.CompactionInfo; +import org.apache.cassandra.db.compaction.CompactionManager; +import org.apache.cassandra.db.compaction.OperationType; +import org.apache.cassandra.io.sstable.format.SSTableReader; +import org.apache.cassandra.schema.MockSchema; +import org.apache.cassandra.tools.ToolRunner; +import org.assertj.core.api.Assertions; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CompactionStatsTest extends CQLTester +{ + @BeforeClass + public static void setup() throws Exception + { + requireNetwork(); + startJMXServer(); + } + + @Test + @SuppressWarnings("SingleCharacterStringConcatenation") + public void testMaybeChangeDocs() + { + // If you added, modified options or help, please update docs if necessary + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("help", "compactionstats"); + tool.assertOnCleanExit(); + + String help = "NAME\n" + + " nodetool compactionstats - Print statistics on compactions\n" + + "\n" + + "SYNOPSIS\n" + + " nodetool [(-h <host> | --host <host>)] [(-p <port> | --port <port>)]\n" + + " [(-pp | --print-port)] [(-pw <password> | --password <password>)]\n" + + " [(-pwf <passwordFilePath> | --password-file <passwordFilePath>)]\n" + + " [(-u <username> | --username <username>)] compactionstats\n" + + " [(-H | --human-readable)]\n" + + "\n" + + "OPTIONS\n" + + " -h <host>, --host <host>\n" + + " Node hostname or ip address\n" + + "\n" + + " -H, --human-readable\n" + + " Display bytes in human readable form, i.e. KiB, MiB, GiB, TiB\n" + + "\n" + + " -p <port>, --port <port>\n" + + " Remote jmx agent port number\n" + + "\n" + + " -pp, --print-port\n" + + " Operate in 4.0 mode with hosts disambiguated by port number\n" + + "\n" + + " -pw <password>, --password <password>\n" + + " Remote jmx agent password\n" + + "\n" + + " -pwf <passwordFilePath>, --password-file <passwordFilePath>\n" + + " Path to the JMX password file\n" + + "\n" + + " -u <username>, --username <username>\n" + + " Remote jmx agent username\n" + + "\n" + + "\n"; + assertThat(tool.getStdout()).isEqualTo(help); + } + + @Test + public void testCompactionStats() + { + createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))"); + ColumnFamilyStore cfs = getCurrentColumnFamilyStore(); + + long bytesCompacted = 123; + long bytesTotal = 123456; + UUID compactionId = UUID.randomUUID(); + List<SSTableReader> sstables = IntStream.range(0, 10) + .mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)) + .collect(Collectors.toList()); + CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() + { + public CompactionInfo getCompactionInfo() + { + return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables); + } + + public boolean isGlobal() + { + return false; + } + }; + + CompactionManager.instance.active.beginCompaction(compactionHolder); + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("compactionstats"); + tool.assertOnCleanExit(); + String stdout = tool.getStdout(); + assertThat(stdout).containsPattern("pending tasks: 1"); Review comment: cant we use just ".contains()" here? The string your are matching is acutally not a regexp pattern ... ########## File path: test/unit/org/apache/cassandra/tools/nodetool/CompactionStatsTest.java ########## @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.tools.nodetool; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.compaction.CompactionInfo; +import org.apache.cassandra.db.compaction.CompactionManager; +import org.apache.cassandra.db.compaction.OperationType; +import org.apache.cassandra.io.sstable.format.SSTableReader; +import org.apache.cassandra.schema.MockSchema; +import org.apache.cassandra.tools.ToolRunner; +import org.assertj.core.api.Assertions; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CompactionStatsTest extends CQLTester +{ + @BeforeClass + public static void setup() throws Exception + { + requireNetwork(); + startJMXServer(); + } + + @Test + @SuppressWarnings("SingleCharacterStringConcatenation") + public void testMaybeChangeDocs() + { + // If you added, modified options or help, please update docs if necessary + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("help", "compactionstats"); + tool.assertOnCleanExit(); + + String help = "NAME\n" + + " nodetool compactionstats - Print statistics on compactions\n" + + "\n" + + "SYNOPSIS\n" + + " nodetool [(-h <host> | --host <host>)] [(-p <port> | --port <port>)]\n" + + " [(-pp | --print-port)] [(-pw <password> | --password <password>)]\n" + + " [(-pwf <passwordFilePath> | --password-file <passwordFilePath>)]\n" + + " [(-u <username> | --username <username>)] compactionstats\n" + + " [(-H | --human-readable)]\n" + + "\n" + + "OPTIONS\n" + + " -h <host>, --host <host>\n" + + " Node hostname or ip address\n" + + "\n" + + " -H, --human-readable\n" + + " Display bytes in human readable form, i.e. KiB, MiB, GiB, TiB\n" + + "\n" + + " -p <port>, --port <port>\n" + + " Remote jmx agent port number\n" + + "\n" + + " -pp, --print-port\n" + + " Operate in 4.0 mode with hosts disambiguated by port number\n" + + "\n" + + " -pw <password>, --password <password>\n" + + " Remote jmx agent password\n" + + "\n" + + " -pwf <passwordFilePath>, --password-file <passwordFilePath>\n" + + " Path to the JMX password file\n" + + "\n" + + " -u <username>, --username <username>\n" + + " Remote jmx agent username\n" + + "\n" + + "\n"; + assertThat(tool.getStdout()).isEqualTo(help); + } + + @Test + public void testCompactionStats() + { + createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))"); + ColumnFamilyStore cfs = getCurrentColumnFamilyStore(); + + long bytesCompacted = 123; + long bytesTotal = 123456; + UUID compactionId = UUID.randomUUID(); + List<SSTableReader> sstables = IntStream.range(0, 10) + .mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)) + .collect(Collectors.toList()); + CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() + { + public CompactionInfo getCompactionInfo() + { + return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables); + } + + public boolean isGlobal() + { + return false; + } + }; + + CompactionManager.instance.active.beginCompaction(compactionHolder); + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("compactionstats"); + tool.assertOnCleanExit(); + String stdout = tool.getStdout(); + assertThat(stdout).containsPattern("pending tasks: 1"); + Assertions.assertThat(stdout).containsPattern("keyspace\\s+table\\s+task id\\s+completion ratio\\s+kind\\s+progress\\s+sstables\\s+total\\s+unit"); + String expectedStatsPattern = String.format("%s\\s+%s\\s+%s\\s+%.2f%%\\s+%s\\s+%s\\s+%s\\s+%s\\s+%s", + CQLTester.KEYSPACE, currentTable(), compactionId, (double) bytesCompacted / bytesTotal * 100, + OperationType.COMPACTION, bytesCompacted, sstables.size(), bytesTotal, CompactionInfo.Unit.BYTES); + Assertions.assertThat(stdout).containsPattern(expectedStatsPattern); + + CompactionManager.instance.active.finishCompaction(compactionHolder); + tool = ToolRunner.invokeNodetool("compactionstats"); + tool.assertOnCleanExit(); + stdout = tool.getStdout(); + assertThat(stdout).containsPattern("pending tasks: 0"); + } + + @Test + public void testCompactionStatsHumanReadable() + { + createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))"); + ColumnFamilyStore cfs = getCurrentColumnFamilyStore(); + + long bytesCompacted = 123; + long bytesTotal = 123456; + UUID compactionId = UUID.randomUUID(); + List<SSTableReader> sstables = IntStream.range(0, 10) + .mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)) + .collect(Collectors.toList()); + CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() + { + public CompactionInfo getCompactionInfo() + { + return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables); + } + + public boolean isGlobal() + { + return false; + } + }; + + CompactionManager.instance.active.beginCompaction(compactionHolder); + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("compactionstats", "--human-readable"); + tool.assertOnCleanExit(); + String stdout = tool.getStdout(); + assertThat(stdout).containsPattern("pending tasks: 1"); Review comment: same, can we just use ".contains()" ? ########## File path: test/unit/org/apache/cassandra/tools/nodetool/CompactionStatsTest.java ########## @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.tools.nodetool; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.compaction.CompactionInfo; +import org.apache.cassandra.db.compaction.CompactionManager; +import org.apache.cassandra.db.compaction.OperationType; +import org.apache.cassandra.io.sstable.format.SSTableReader; +import org.apache.cassandra.schema.MockSchema; +import org.apache.cassandra.tools.ToolRunner; +import org.assertj.core.api.Assertions; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CompactionStatsTest extends CQLTester +{ + @BeforeClass + public static void setup() throws Exception + { + requireNetwork(); + startJMXServer(); + } + + @Test + @SuppressWarnings("SingleCharacterStringConcatenation") + public void testMaybeChangeDocs() + { + // If you added, modified options or help, please update docs if necessary + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("help", "compactionstats"); + tool.assertOnCleanExit(); + + String help = "NAME\n" + + " nodetool compactionstats - Print statistics on compactions\n" + + "\n" + + "SYNOPSIS\n" + + " nodetool [(-h <host> | --host <host>)] [(-p <port> | --port <port>)]\n" + + " [(-pp | --print-port)] [(-pw <password> | --password <password>)]\n" + + " [(-pwf <passwordFilePath> | --password-file <passwordFilePath>)]\n" + + " [(-u <username> | --username <username>)] compactionstats\n" + + " [(-H | --human-readable)]\n" + + "\n" + + "OPTIONS\n" + + " -h <host>, --host <host>\n" + + " Node hostname or ip address\n" + + "\n" + + " -H, --human-readable\n" + + " Display bytes in human readable form, i.e. KiB, MiB, GiB, TiB\n" + + "\n" + + " -p <port>, --port <port>\n" + + " Remote jmx agent port number\n" + + "\n" + + " -pp, --print-port\n" + + " Operate in 4.0 mode with hosts disambiguated by port number\n" + + "\n" + + " -pw <password>, --password <password>\n" + + " Remote jmx agent password\n" + + "\n" + + " -pwf <passwordFilePath>, --password-file <passwordFilePath>\n" + + " Path to the JMX password file\n" + + "\n" + + " -u <username>, --username <username>\n" + + " Remote jmx agent username\n" + + "\n" + + "\n"; + assertThat(tool.getStdout()).isEqualTo(help); + } + + @Test + public void testCompactionStats() + { + createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))"); + ColumnFamilyStore cfs = getCurrentColumnFamilyStore(); + + long bytesCompacted = 123; + long bytesTotal = 123456; + UUID compactionId = UUID.randomUUID(); + List<SSTableReader> sstables = IntStream.range(0, 10) + .mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)) + .collect(Collectors.toList()); + CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() + { + public CompactionInfo getCompactionInfo() + { + return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables); + } + + public boolean isGlobal() + { + return false; + } + }; + + CompactionManager.instance.active.beginCompaction(compactionHolder); + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("compactionstats"); + tool.assertOnCleanExit(); + String stdout = tool.getStdout(); + assertThat(stdout).containsPattern("pending tasks: 1"); + Assertions.assertThat(stdout).containsPattern("keyspace\\s+table\\s+task id\\s+completion ratio\\s+kind\\s+progress\\s+sstables\\s+total\\s+unit"); + String expectedStatsPattern = String.format("%s\\s+%s\\s+%s\\s+%.2f%%\\s+%s\\s+%s\\s+%s\\s+%s\\s+%s", + CQLTester.KEYSPACE, currentTable(), compactionId, (double) bytesCompacted / bytesTotal * 100, + OperationType.COMPACTION, bytesCompacted, sstables.size(), bytesTotal, CompactionInfo.Unit.BYTES); + Assertions.assertThat(stdout).containsPattern(expectedStatsPattern); + + CompactionManager.instance.active.finishCompaction(compactionHolder); + tool = ToolRunner.invokeNodetool("compactionstats"); + tool.assertOnCleanExit(); + stdout = tool.getStdout(); + assertThat(stdout).containsPattern("pending tasks: 0"); + } + + @Test + public void testCompactionStatsHumanReadable() + { + createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))"); + ColumnFamilyStore cfs = getCurrentColumnFamilyStore(); + + long bytesCompacted = 123; + long bytesTotal = 123456; + UUID compactionId = UUID.randomUUID(); + List<SSTableReader> sstables = IntStream.range(0, 10) + .mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)) + .collect(Collectors.toList()); + CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() + { + public CompactionInfo getCompactionInfo() + { + return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables); + } + + public boolean isGlobal() + { + return false; + } + }; + + CompactionManager.instance.active.beginCompaction(compactionHolder); Review comment: is this safe to do in such sense that if I begin compaction, the next call on nodetool will get output which will _always_ contain completion info above? I am just checking here if this gets executed immediately. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

