You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/02/11 21:20:48 UTC

[GitHub] [cassandra] ekaterinadimitrova2 commented on a change in pull request #1362: [CASSANDRA-16378] Expose all client options via system_views.clients and nodetool clientstats

ekaterinadimitrova2 commented on a change in pull request #1362:
URL: https://github.com/apache/cassandra/pull/1362#discussion_r805012469



##########
File path: test/unit/org/apache/cassandra/db/virtual/ClientsTableTest.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.net.InetAddress;
+
+import com.google.common.collect.ImmutableList;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import org.apache.cassandra.cql3.CQLTester;
+import org.assertj.core.api.Assertions;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ClientsTableTest extends CQLTester
+{
+    private static final String KS_NAME = "vts";
+    
+    private ClientsTable table;
+    
+    @BeforeClass
+    public static void setUpClass()
+    {
+        CQLTester.setUpClass();
+    }
+
+    @Before
+    public void config()
+    {
+        table = new ClientsTable(KS_NAME);
+        VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+    }
+    
+    @Test
+    public void testSelectAll() throws Throwable
+    {
+        ResultSet result = executeNet("SELECT * FROM vts.clients");
+        
+        for (Row r : result)
+        {
+            Assert.assertEquals(InetAddress.getLoopbackAddress(), r.getInet("address"));
+            Assert.assertNotNull(r.getInt("port"));
+            Assert.assertTrue(r.getInt("port") > 0);
+            Assert.assertNotNull(r.getMap("client_options", String.class, String.class));
+            Assert.assertTrue(r.getLong("request_count") > 0 );
+            // the following are questionable if they belong here
+            Assert.assertEquals("localhost", r.getString("hostname"));
+            Assertions.assertThat(r.getMap("client_options", String.class, String.class))
+                    .hasEntrySatisfying("DRIVER_VERSION", value -> {
+                        assertThat(value.contains(r.getString("driver_name")));
+                    })
+                    .hasEntrySatisfying("DRIVER_VERSION", value -> {
+                        assertThat(value.contains(r.getString("driver_version")));
+                    });

Review comment:
       nit: I will probably write those as follows:
   ```suggestion
               Assertions.assertThat(r.getMap("client_options", String.class, String.class))
                       .hasEntrySatisfying("DRIVER_VERSION", value -> assertThat(value.contains(r.getString("driver_name"))))
                       .hasEntrySatisfying("DRIVER_VERSION", value -> assertThat(value.contains(r.getString("driver_version"))));
   ```




-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org