ekaterinadimitrova2 commented on a change in pull request #1372: URL: https://github.com/apache/cassandra/pull/1372#discussion_r784396457
########## File path: test/unit/org/apache/cassandra/db/virtual/BatchMetricsTableTest.java ########## @@ -0,0 +1,90 @@ +/* + * 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.concurrent.atomic.AtomicInteger; + +import com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.codahale.metrics.Histogram; Review comment: unused import ########## File path: test/unit/org/apache/cassandra/db/virtual/BatchMetricsTableTest.java ########## @@ -0,0 +1,90 @@ +/* + * 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.concurrent.atomic.AtomicInteger; + +import com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.codahale.metrics.Histogram; Review comment: ```suggestion ``` ########## File path: test/unit/org/apache/cassandra/db/virtual/BatchMetricsTableTest.java ########## @@ -0,0 +1,90 @@ +/* + * 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.concurrent.atomic.AtomicInteger; + +import com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.codahale.metrics.Histogram; +import com.codahale.metrics.Snapshot; +import com.datastax.driver.core.ResultSet; +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.cql3.statements.BatchStatement; +import org.apache.cassandra.metrics.BatchMetrics; + +import static java.lang.String.format; +import static org.junit.Assert.assertEquals; + +public class BatchMetricsTableTest extends CQLTester +{ + private static final String KS_NAME = "vts"; + private BatchMetricsTable table; + + @BeforeClass + public static void setUpClass() + { + CQLTester.setUpClass(); + } + + @Before + public void config() + { + table = new BatchMetricsTable(KS_NAME); + VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table))); + } + + @Test + void testSelectAll() throws Throwable Review comment: I suspect you accidentally deleted the public accessor, otherwise you can't run the test. I noticed It throws a class cast exception though. Can you, please check it? Thanks. Please let me know if you need help ########## File path: test/unit/org/apache/cassandra/db/virtual/BatchMetricsTableTest.java ########## @@ -0,0 +1,90 @@ +/* + * 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.concurrent.atomic.AtomicInteger; + +import com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.codahale.metrics.Histogram; +import com.codahale.metrics.Snapshot; +import com.datastax.driver.core.ResultSet; +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.cql3.statements.BatchStatement; +import org.apache.cassandra.metrics.BatchMetrics; + +import static java.lang.String.format; +import static org.junit.Assert.assertEquals; + +public class BatchMetricsTableTest extends CQLTester +{ + private static final String KS_NAME = "vts"; + private BatchMetricsTable table; + + @BeforeClass + public static void setUpClass() + { + CQLTester.setUpClass(); + } + + @Before + public void config() + { + table = new BatchMetricsTable(KS_NAME); + VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table))); + } + + @Test + void testSelectAll() throws Throwable + { + String ks = createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'SimpleStrategy', 'replication_factor' : 1 }"); + String tbl = createTable(ks, "CREATE TABLE %s (id int primary key, val int)"); + + String batch = format("BEGIN BATCH " + + "INSERT INTO %s.%s (id, val) VALUES (0, 0) USING TTL %d; " + + "INSERT INTO %s.%s (id, val) VALUES (1, 1) USING TTL %d; " + + "APPLY BATCH;", + ks, tbl, 1, + ks, tbl, 1); + execute(batch); + + BatchMetrics metrics = BatchStatement.metrics; + ResultSet result = executeNet("SELECT * FROM vts.batch_metrics"); + assertEquals(5, result.getColumnDefinitions().size()); + AtomicInteger rowCount = new AtomicInteger(0); + result.forEach(r -> { + Snapshot snapshot; + if(r.getString("name").equals("partitions_per_logged_batch")) { + snapshot = metrics.partitionsPerLoggedBatch.getSnapshot(); + } else if(r.getString("name").equals("partitions_per_unlogged_batch")) { + snapshot = metrics.partitionsPerUnloggedBatch.getSnapshot(); + } else { + snapshot = metrics.partitionsPerCounterBatch.getSnapshot(); + } Review comment: +1 on a new method. And I wanted to mention that the project follows some conventions you might want to get acquainted with - https://cassandra.apache.org/_/development/code_style.html (I noticed `{` are not on new lines) -- 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]

