skoppu22 commented on a change in pull request #1421: URL: https://github.com/apache/cassandra/pull/1421#discussion_r791598972
########## File path: test/unit/org/apache/cassandra/db/virtual/CQLMetricsTableTest.java ########## @@ -0,0 +1,116 @@ +/* + * 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 com.datastax.driver.core.PreparedStatement; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Session; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.BeforeClass; + +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.cql3.QueryProcessor; +import org.apache.cassandra.metrics.CQLMetrics; + +public class CQLMetricsTableTest extends CQLTester +{ + private static final String KS_NAME = "vts"; + + @BeforeClass + public static void setUpClass() + { + CQLTester.setUpClass(); + } + + private void queryAndValidateMetrics(CQLMetrics expectedMetrics) throws Throwable + { + String getMetricsQuery = "SELECT * FROM " + KS_NAME + "." + CQLMetricsTable.TABLE_NAME; + ResultSet vtsRows = executeNet(getMetricsQuery); + + // validate - number of columns + assertEquals(6, vtsRows.getColumnDefinitions().size()); + + AtomicInteger rowCount = new AtomicInteger(0); + vtsRows.forEach(r -> { + assertEquals(expectedMetrics.preparedStatementsCount.getValue(), r.getDouble(CQLMetricsTable.PREPARED_STATEMENTS_COUNT_COL), 0); + assertEquals(expectedMetrics.preparedStatementsEvicted.getCount(), r.getDouble(CQLMetricsTable.PREPARED_STATEMENTS_EVICTED_COL), 0); + assertEquals(expectedMetrics.preparedStatementsExecuted.getCount(), r.getDouble(CQLMetricsTable.PREPARED_STATEMENTS_EXECUTED_COL), 0); + assertEquals(expectedMetrics.preparedStatementsRatio.getValue(), r.getDouble(CQLMetricsTable.PREPARED_STATEMENTS_RATIO_COL), 0.01); + assertEquals(expectedMetrics.regularStatementsExecuted.getCount(), r.getDouble(CQLMetricsTable.REGULAR_STATEMENTS_EXECUTED_COL), 0); + rowCount.getAndIncrement(); + }); + + // validate - number of rows + assertEquals(1, rowCount.get()); + } + + @Test + public void testUsingPrepareStmts() throws Throwable + { + CQLMetricsTable table = new CQLMetricsTable(KS_NAME); + VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table))); Review comment: This was my initial code. But as we want to inject our own cqlMetrics in other test case, this doesn't work for both test cases. -- 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]

