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


##########
test/unit/org/apache/cassandra/db/virtual/UpdateSettingsTableTest.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.exceptions.InvalidQueryException;
+import org.apache.cassandra.config.Config;
+import org.apache.cassandra.config.DataRateSpec;
+import org.apache.cassandra.config.DataStorageSpec;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.config.DurationSpec;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.db.ConsistencyLevel;
+
+import static 
org.apache.cassandra.db.virtual.SettingsTable.propertyToStringConverter;
+import static org.apache.cassandra.db.virtual.SettingsTableTest.KS_NAME;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * The set of tests for {@link SettingsTable} for updating settings through 
virtual table. Since the Config class and
+ * the {@link DatabaseDescriptor} are static, we need to return back changes 
to the original state after each update.
+ */
+public class UpdateSettingsTableTest extends CQLTester
+{
+    private static final Set<String> updatableProperties = new HashSet<>();
+    private static final Map<String, Class<?>> propertyTypes = new HashMap<>();
+    private static final Map<Class<?>, Object[]> defaultTestValues = 
registerTestConfigurationValues();
+
+    @BeforeClass
+    public static void setUpClass()
+    {
+        CQLTester.setUpClass();
+        for (String key : DatabaseDescriptor.getAllProperties())
+        {
+            propertyTypes.put(key, DatabaseDescriptor.getPropertyType(key));
+            if (DatabaseDescriptor.isMutableProperty(key))
+                updatableProperties.add(key);
+        }
+    }
+
+    @Before
+    public void prepare()
+    {
+        // Creating a new instence will avoid calling listeners registered in 
the registry.
+        VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, 
ImmutableList.of(new SettingsTable(KS_NAME))));
+        disablePreparedReuseForTest();
+    }
+
+    @Test
+    public void testUpdateAllSettings() throws Throwable
+    {
+        for (String propertyName : updatableProperties)
+            doUpdateSettingAndRevertBack(String.format("UPDATE %s.settings SET 
value = ? WHERE name = ?;", KS_NAME), propertyName);
+    }
+
+    @Test(expected = InvalidQueryException.class)
+    public void testUpdateRepairSessionSpaceToNull() throws Throwable
+    {
+        assertRowsNet(executeNet(String.format("UPDATE %s.settings SET value = 
? WHERE name = ?;", KS_NAME),
+                                 null, Config.Names.REPAIR_SESSION_SPACE));
+    }
+
+    @Test
+    public void testUpdateSettingsValidationFail() throws Throwable
+    {
+        InvalidQueryException e = null;
+        try
+        {
+            updateConfigurationProperty(String.format("UPDATE %s.settings SET 
value = ? WHERE name = ?;", KS_NAME),
+                                        
Config.Names.STREAM_THROUGHPUT_OUTBOUND,
+                                        propertyToStringConverter()
+                                        // This is the value for the property 
that overflows property's limit in bytes bet second.
+                                        .apply(new 
DataRateSpec.LongBytesPerSecondBound(Integer.MAX_VALUE, 
DataRateSpec.DataRateUnit.MEBIBYTES_PER_SECOND)));
+        }
+        catch (InvalidQueryException ex)
+        {
+            e = ex;
+        }
+        assertNotNull(e);
+        assertEquals("Unexpected error: " + e.getMessage(),
+                     "Invalid update request 'stream_throughput_outbound'. 
Cause: Property 'stream_throughput_outbound' " +
+                     "validation failed: Invalid value: '2147483647MiB/s' is 
too large",
+                     e.getMessage());
+    }
+
+    @Test
+    public void testInsertSettingsNewValues() throws Throwable
+    {
+        for (String propertyName : updatableProperties)
+            doUpdateSettingAndRevertBack(String.format("INSERT INTO 
%s.settings (value, name) VALUES (?, ?);", KS_NAME), propertyName);
+    }
+
+    @Test
+    public void testBactchUpdateSettings() throws Throwable

Review Comment:
   `testBatch...`



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