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/11/29 12:37:52 UTC

[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2027: CASSANDRA-18042 second approach DO NOT COMMIT

smiklosovic commented on code in PR #2027:
URL: https://github.com/apache/cassandra/pull/2027#discussion_r1034700603


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailZeroDefaultTTLOnTWCSTest.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.guardrails;
+
+import org.junit.Test;
+
+import org.apache.cassandra.db.compaction.TimeWindowCompactionStrategy;
+
+public class GuardrailZeroDefaultTTLOnTWCSTest extends GuardrailTester
+{
+    private static final String QUERY = "CREATE TABLE IF NOT EXISTS tb1 (k int PRIMARY KEY, a int, b int) " +
+                                        "WITH default_time_to_live = 0 " +
+                                        "AND compaction = {'class': 'TimeWindowCompactionStrategy', 'enabled': true }";
+
+    private static final String VALID_QUERY_1 = "CREATE TABLE IF NOT EXISTS tb2 (k int PRIMARY KEY, a int, b int) " +
+                                                "WITH default_time_to_live = 1 " +
+                                                "AND compaction = {'class': 'TimeWindowCompactionStrategy', 'enabled': true }";
+
+    private static final String VALID_QUERY_2 = "CREATE TABLE IF NOT EXISTS tb3 (k int PRIMARY KEY, a int, b int) " +
+                                                "WITH default_time_to_live = 0";
+
+    public GuardrailZeroDefaultTTLOnTWCSTest()
+    {
+        super(Guardrails.zeroTTLOnTWCSEnabled);
+    }
+
+    @Test
+    public void testGuardrailEnabled() throws Throwable
+    {
+        prepareTest(true, true);
+        assertFails(QUERY, "0 default_time_to_live on a table with " +
+                           TimeWindowCompactionStrategy.class.getSimpleName() +
+                           " compaction strategy is not allowed");
+    }
+
+    @Test
+    public void testGuardrailDisabledWarnEnabled() throws Throwable
+    {
+        prepareTest(false, true);
+        assertWarns(QUERY, "0 default_time_to_live on a table with " +
+                           TimeWindowCompactionStrategy.class.getSimpleName() +
+                           " compaction strategy is not recommended");
+    }
+
+    @Test
+    public void testGuardrailDisabledWarnDisabled() throws Throwable
+    {
+        prepareTest(false, false);
+        assertValid(QUERY);
+    }
+
+    @Test
+    public void testGuardrailNotTriggered() throws Throwable
+    {
+        prepareTest(true, true);
+        assertValid(VALID_QUERY_1);
+        assertValid(VALID_QUERY_2);
+    }
+
+    @Test
+    public void testExcludedUsers() throws Throwable
+    {
+        for (boolean disallowed : new boolean[] { false, true })
+            for (boolean warn : new boolean[] { false, true })
+                prepareTest(disallowed, warn);
+                testExcludedUsers(() -> QUERY,

Review Comment:
   hah right, good catch



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