dcapwell commented on a change in pull request #1437:
URL: https://github.com/apache/cassandra/pull/1437#discussion_r799088198



##########
File path: 
test/unit/org/apache/cassandra/cql3/validation/operations/UseTest.java
##########
@@ -19,13 +19,38 @@
 
 import org.junit.Test;
 
+import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.QueryProcessor;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 public class UseTest extends CQLTester
 {
     @Test
     public void testUseStatementWithBindVariable() throws Throwable
     {
+        DatabaseDescriptor.setUseStatementsEnabled(true);
         assertInvalidSyntaxMessage("Bind variables cannot be used for keyspace 
names", "USE ?");
     }
+
+    @Test
+    public void shouldRejectUseStatementWhenProhibited() throws Throwable
+    {
+        long useCountBefore = 
QueryProcessor.metrics.useStatementsExecuted.getCount();
+
+        try
+        {
+            DatabaseDescriptor.setUseStatementsEnabled(false);
+            execute("USE cql_test_keyspace");
+            fail("expected USE statement to fail with use_statements_enabled = 
false");
+        }
+        catch (InvalidRequestException e)
+        {
+            assertEquals(useCountBefore, 
QueryProcessor.metrics.useStatementsExecuted.getCount());
+            assertMessageContains("USE statements prohibited", e);

Review comment:
       nit: FYI, you can use 
`Assertions.assertThat(e).hasMessageContaining("USE statements prohibited");`, 
does the same thing, just without exposing the hidden method

##########
File path: src/java/org/apache/cassandra/config/DatabaseDescriptor.java
##########
@@ -3810,4 +3809,18 @@ public static void setMinimumKeyspaceRF(int value) 
throws ConfigurationException
 
         conf.minimum_keyspace_rf = value;
     }
+
+    public static boolean getUseStatementsEnabled()
+    {
+        return conf.use_statements_enabled;
+    }
+
+    public static void setUseStatementsEnabled(boolean enabled)
+    {
+        if (enabled != conf.use_statements_enabled)
+        {
+            logger.info("Setting use_statements_enabled to {}", enabled);

Review comment:
       heh... `StorageProxy` doesn't do the logging, but `StorageService` 
does... this patch is consistent with StorageProxy, which calls this...




-- 
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]

Reply via email to