adelapena commented on code in PR #2467: URL: https://github.com/apache/cassandra/pull/2467#discussion_r1259477767
########## test/unit/org/apache/cassandra/cql3/SystemKeyspaceTablesNamesTest.java: ########## @@ -0,0 +1,112 @@ +/* + * 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.cql3; + +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.auth.AuthKeyspace; +import org.apache.cassandra.db.SystemKeyspace; +import org.apache.cassandra.schema.Schema; +import org.apache.cassandra.schema.SchemaConstants; +import org.apache.cassandra.schema.SchemaKeyspaceTables; +import org.apache.cassandra.schema.SystemDistributedKeyspace; +import org.apache.cassandra.tracing.TraceKeyspace; + +import static org.junit.Assert.assertTrue; + +public class SystemKeyspaceTablesNamesTest extends CQLTester +{ + @BeforeClass + public static void setUp() + { + // Needed for distributed keyspaces + requireNetwork(); + } + + @Test + public void testSystemKeyspaceTableNames() + { + Set<String> tables = Schema.instance.getKeyspaceMetadata(SchemaConstants.SYSTEM_KEYSPACE_NAME).tables + .stream().map(t -> t.name).collect(Collectors.toSet()); Review Comment: This block is more or less repeated in all the tests, producing a warning about the chance of the `KeyspaceMetadata` being null. We could put it a utility method: ```java private static Set<String> tableNames(String keyspaceName) { KeyspaceMetadata keyspace = Schema.instance.getKeyspaceMetadata(keyspaceName); assertNotNull(keyspace); return keyspace.tables.stream().map(t -> t.name).collect(Collectors.toSet()); } ``` ########## src/java/org/apache/cassandra/service/StorageServiceMBean.java: ########## @@ -1124,16 +1124,6 @@ public void enableAuditLog(String loggerName, String includedKeyspaces, String e public boolean autoOptimisePreviewRepairStreams(); public void setAutoOptimisePreviewRepairStreams(boolean enabled); - // warning thresholds will be replaced by equivalent guardrails Review Comment: I think we should keep the JMX methods, since it's a public API. We could change their implementation in `StorageService` to use the getters and setters in `Guardrails.instance` instead of using `DatabaseDescriptor`. ########## src/java/org/apache/cassandra/schema/SchemaConstants.java: ########## @@ -126,4 +129,23 @@ public static Set<String> getSystemKeyspaces() { return Sets.union(Sets.union(LOCAL_SYSTEM_KEYSPACE_NAMES, REPLICATED_SYSTEM_KEYSPACE_NAMES), VIRTUAL_SYSTEM_KEYSPACE_NAMES); } + + /** + * Returns the set of local and replicated system keyspace names + * @return all local and replicated system keyspace names + */ + public static Set<String> getLocalAndReplicatedSystemKeyspaceNames() + { + return Sets.union(LOCAL_SYSTEM_KEYSPACE_NAMES, REPLICATED_SYSTEM_KEYSPACE_NAMES); + } + + /** + * Returns the set of all local and replicated system table names + * @return all local and replicated system table names + */ + public static Set<String> getLocalAndReplicatedSystemTableNames() + { + return Sets.union(Sets.union(SystemKeyspace.TABLE_NAMES, ImmutableSet.copyOf(SchemaKeyspaceTables.ALL)), Review Comment: Nit: The four nested usages of `Sets.union` aren't probably the easier thing to read. Perhaps we could use instead something like: ```java return ImmutableSet.<String>builder() .addAll(SystemKeyspace.TABLE_NAMES) .addAll(SchemaKeyspaceTables.ALL) .addAll(TraceKeyspace.TABLE_NAMES) .addAll(AuthKeyspace.TABLE_NAMES) .addAll(SystemDistributedKeyspace.TABLE_NAMES) .build(); ``` ########## test/unit/org/apache/cassandra/cql3/SystemKeyspaceTablesNamesTest.java: ########## @@ -0,0 +1,112 @@ +/* + * 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.cql3; + +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.auth.AuthKeyspace; +import org.apache.cassandra.db.SystemKeyspace; +import org.apache.cassandra.schema.Schema; +import org.apache.cassandra.schema.SchemaConstants; +import org.apache.cassandra.schema.SchemaKeyspaceTables; +import org.apache.cassandra.schema.SystemDistributedKeyspace; +import org.apache.cassandra.tracing.TraceKeyspace; + +import static org.junit.Assert.assertTrue; + +public class SystemKeyspaceTablesNamesTest extends CQLTester Review Comment: It's nice to have thins test :) -- 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]

