You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "nvharikrishna (via GitHub)" <gi...@apache.org> on 2023/05/12 17:02:09 UTC
[GitHub] [cassandra] nvharikrishna opened a new pull request, #2331: Adding keyspace column to clients virtual table
nvharikrishna opened a new pull request, #2331:
URL: https://github.com/apache/cassandra/pull/2331
Added new column `keyspace_name` (used by the client) to clients virtual table.
[CASSANDRA-18525](https://issues.apache.org/jira/browse/CASSANDRA-18525)
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193023558
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
Review Comment:
@nvharikrishna could you please put this into the `for` loop instead of `rows`? Your very last `for` loop in this test class in the other test method is putting it directly into the loop while this does not (neither the first loop in `testChangingKeyspace` test). I would like to see it consistent everywhere.
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193023955
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
+ // No keyspace is specifed while connecting. 'keyspace' column should be null.
+ Assert.assertNull(r.getString("keyspace_name"));
+ }
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ for (Row r : rows)
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using keyspace != null as a hint to identify a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
Review Comment:
Is not it true that you can `break` from this loop once we enter this `if` and `poolConnection` and `port` are set?
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193197562
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ try
+ {
+ if (cluster != null)
+ cluster.close();
+ }
+ finally
+ {
+ if (cassandra != null)
+ cassandra.stop();
+ }
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ assertNull(r.getString("keyspace_name")); // No keyspace is specifed while connecting. It should be null.
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ for (Row r : session.execute("SELECT * from " + KS_NAME + ".clients").all())
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using r["keyspace_name"] == keyspace1 as a hint to identify a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
+ break;
+ }
+ }
+
+ Assert.assertNotEquals(-1, port);
Review Comment:
@nvharikrishna could you please import also these two? Otherwise I think we are done.
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193024197
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
+ // No keyspace is specifed while connecting. 'keyspace' column should be null.
+ Assert.assertNull(r.getString("keyspace_name"));
+ }
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ for (Row r : rows)
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using keyspace != null as a hint to identify a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
+ }
+ }
+
+ Assert.assertNotEquals(-1, port);
+ Assert.assertNotNull(poolConnection);
+
+ session.execute("USE " + keyspace2);
+
+ String actualKeyspace = null;
+ for (Row r : session.execute("SELECT * from " + KS_NAME + ".clients").all())
Review Comment:
for (Row r ...
if (pooConnection ....
{
actualKeyspace = ....
break;
}
Please correct me if I am wrong.
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193025274
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
+ // No keyspace is specifed while connecting. 'keyspace' column should be null.
+ Assert.assertNull(r.getString("keyspace_name"));
+ }
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ for (Row r : rows)
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using keyspace != null as a hint to identify a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
+ }
+ }
+
+ Assert.assertNotEquals(-1, port);
+ Assert.assertNotNull(poolConnection);
+
+ session.execute("USE " + keyspace2);
+
+ String actualKeyspace = null;
Review Comment:
I would rename this to `usedKeyspace`.
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193368125
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ try
+ {
+ if (cluster != null)
+ cluster.close();
+ }
+ finally
+ {
+ if (cassandra != null)
+ cassandra.stop();
+ }
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ assertNull(r.getString("keyspace_name")); // No keyspace is specifed while connecting. It should be null.
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ for (Row r : session.execute("SELECT * from " + KS_NAME + ".clients").all())
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using r["keyspace_name"] == keyspace1 as a hint to identify a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
+ break;
+ }
+ }
+
+ Assert.assertNotEquals(-1, port);
Review Comment:
Will be done on commit.
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193023730
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
Review Comment:
If you have just one statement in the body of the for loop, we tend to just omit the braces.
--
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
[GitHub] [cassandra] nvharikrishna commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "nvharikrishna (via GitHub)" <gi...@apache.org>.
nvharikrishna commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193037194
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
Review Comment:
I am asserting that at least one row is returned in the next statement so assigned the results to rows. Changed it at other places.
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
+ // No keyspace is specifed while connecting. 'keyspace' column should be null.
+ Assert.assertNull(r.getString("keyspace_name"));
+ }
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ for (Row r : rows)
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using keyspace != null as a hint to identify a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
Review Comment:
done
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
Review Comment:
done
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
Review Comment:
done
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
+ // No keyspace is specifed while connecting. 'keyspace' column should be null.
+ Assert.assertNull(r.getString("keyspace_name"));
+ }
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ for (Row r : rows)
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using keyspace != null as a hint to identify a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
+ }
+ }
+
+ Assert.assertNotEquals(-1, port);
+ Assert.assertNotNull(poolConnection);
+
+ session.execute("USE " + keyspace2);
+
+ String actualKeyspace = null;
+ for (Row r : session.execute("SELECT * from " + KS_NAME + ".clients").all())
Review Comment:
done
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
+ // No keyspace is specifed while connecting. 'keyspace' column should be null.
+ Assert.assertNull(r.getString("keyspace_name"));
+ }
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ for (Row r : rows)
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using keyspace != null as a hint to identify a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
+ }
+ }
+
+ Assert.assertNotEquals(-1, port);
+ Assert.assertNotNull(poolConnection);
+
+ session.execute("USE " + keyspace2);
+
+ String actualKeyspace = null;
Review Comment:
done
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
+ // No keyspace is specifed while connecting. 'keyspace' column should be null.
+ Assert.assertNull(r.getString("keyspace_name"));
+ }
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ for (Row r : rows)
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using keyspace != null as a hint to identify a pool connection as we can't identify
Review Comment:
Updated the comment
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
Review Comment:
done
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193024483
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
Review Comment:
what if `cluster.close()` throws? I think it can throw some runtime exception. That means that it will never get to actually close `cassandra`. I would rewrite it to
try
{
if (cluster != null)
cluster.close();
}
finally
{
if (cassandra != null)
cassandra.stop();
}
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193023638
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
Review Comment:
@nvharikrishna could you please import all these assertion methods statically?
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193024483
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
Review Comment:
what if `cluster.close()` throws? I think it can throw some runtime exception. That means that it will never get to actually stop `cassandra`. I would rewrite it to
try
{
if (cluster != null)
cluster.close();
}
finally
{
if (cassandra != null)
cassandra.stop();
}
--
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
[GitHub] [cassandra] smiklosovic closed pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic closed pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
URL: https://github.com/apache/cassandra/pull/2331
--
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
[GitHub] [cassandra] nvharikrishna commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "nvharikrishna (via GitHub)" <gi...@apache.org>.
nvharikrishna commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1192945100
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest extends CQLTester
Review Comment:
I wanted to control connection/session establishment so that keyspace_name can be verified just for that user. CQLTester doesn't have a public/protected method to get cluster and session instances. I did not find CQLTester using `cluster.connect(keyspace)`. So I created a separate test class with cluster and session instances explicitly constructed. It cannot be done with `ClientsTableTest` as everything done through CQLTester.setUpClass(). I realised that this test doesn't have to extend CQLTester. Thanks for pointing it out. Cleared it.
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: CASSANDRA-18525 Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1193023810
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ if (cluster != null)
+ cluster.close();
+ if (cassandra != null)
+ cassandra.stop();
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ Assert.assertTrue("At least one client should be returned.", rows.size() > 0);
+ for (Row r : rows)
+ {
+ // No keyspace is specifed while connecting. 'keyspace' column should be null.
+ Assert.assertNull(r.getString("keyspace_name"));
+ }
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME + ".clients").all();
+ for (Row r : rows)
+ {
+ // Keyspace is used for pool connection only (control connection is not using keyspace).
+ // Using keyspace != null as a hint to identify a pool connection as we can't identify
Review Comment:
I do not see actually using `keyspace != null` anywhere.
--
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
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2331: Adding keyspace column to clients virtual table
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2331:
URL: https://github.com/apache/cassandra/pull/2331#discussion_r1192760781
##########
test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+public class ClientsTableKeyspaceColTest extends CQLTester
Review Comment:
@nvharikrishna could you please add this to `ClientsTableTest` class in this package? Do we really need a new file for it? That one extends `CQLTester` too.
--
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