This is an automated email from the ASF dual-hosted git repository. dcapwell pushed a commit to branch cassandra-3.11 in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit efd6b608cf3b89aaba64dcb4401eae02e0dda58c Merge: 56f6cd9 d547f0d Author: David Capwell <dcapw...@apache.org> AuthorDate: Thu Oct 22 13:21:22 2020 -0700 Merge branch 'cassandra-3.0' into cassandra-3.11 .../cassandra/config/ParameterizedClass.java | 5 ++ .../cassandra/config/YamlConfigurationLoader.java | 30 ++++++- .../distributed/impl/AbstractCluster.java | 44 +++++++++-- .../cassandra/distributed/impl/Instance.java | 19 +++-- .../cassandra/distributed/impl/InstanceConfig.java | 49 +++--------- .../cassandra/distributed/test/JVMDTestTest.java | 92 +++++++++++++++++++++- .../config/YamlConfigurationLoaderTest.java | 54 +++++++++++++ 7 files changed, 229 insertions(+), 64 deletions(-) diff --cc src/java/org/apache/cassandra/config/YamlConfigurationLoader.java index ca5e41a,bd602df..be7b3fd --- a/src/java/org/apache/cassandra/config/YamlConfigurationLoader.java +++ b/src/java/org/apache/cassandra/config/YamlConfigurationLoader.java @@@ -117,11 -114,11 +120,11 @@@ public class YamlConfigurationLoader im throw new AssertionError(e); } -- Constructor constructor = new CustomConstructor(Config.class); - MissingPropertiesChecker propertiesChecker = new MissingPropertiesChecker(); ++ Constructor constructor = new CustomConstructor(Config.class, Config.class.getClassLoader()); + PropertiesChecker propertiesChecker = new PropertiesChecker(); constructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(constructor); - Config result = yaml.loadAs(new ByteArrayInputStream(configBytes), Config.class); + Config result = loadConfig(yaml, configBytes); propertiesChecker.check(); return result; } @@@ -132,11 -128,35 +135,30 @@@ } } - static class CustomConstructor extends Constructor + @SuppressWarnings("unchecked") //getSingleData returns Object, not T + public static <T> T fromMap(Map<String,Object> map, Class<T> klass) { - CustomConstructor(Class<?> theRoot) + Constructor constructor = new YamlConfigurationLoader.CustomConstructor(klass, klass.getClassLoader()); - YamlConfigurationLoader.MissingPropertiesChecker propertiesChecker = new YamlConfigurationLoader.MissingPropertiesChecker(); ++ YamlConfigurationLoader.PropertiesChecker propertiesChecker = new YamlConfigurationLoader.PropertiesChecker(); + constructor.setPropertyUtils(propertiesChecker); + Yaml yaml = new Yaml(constructor); + Node node = yaml.represent(map); + constructor.setComposer(new Composer(null, null) { - super(theRoot); + @Override + public Node getSingleNode() + { + return node; + } + }); + return (T) constructor.getSingleData(klass); + } + + static class CustomConstructor extends CustomClassLoaderConstructor + { - CustomConstructor(Class<?> theRoot) - { - this(theRoot, Yaml.class.getClassLoader()); - } - + CustomConstructor(Class<?> theRoot, ClassLoader classLoader) + { + super(theRoot, classLoader); TypeDescription seedDesc = new TypeDescription(ParameterizedClass.class); seedDesc.putMapPropertyType("parameters", String.class, String.class); diff --cc test/distributed/org/apache/cassandra/distributed/impl/Instance.java index 660679c,4f799ee..6ea2c9c --- a/test/distributed/org/apache/cassandra/distributed/impl/Instance.java +++ b/test/distributed/org/apache/cassandra/distributed/impl/Instance.java @@@ -51,7 -51,7 +51,8 @@@ import org.apache.cassandra.concurrent. import org.apache.cassandra.config.Config; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; + import org.apache.cassandra.config.YamlConfigurationLoader; import org.apache.cassandra.cql3.CQLStatement; import org.apache.cassandra.cql3.QueryOptions; import org.apache.cassandra.cql3.QueryProcessor; diff --cc test/distributed/org/apache/cassandra/distributed/test/JVMDTestTest.java index 3a1a0a8,13b314a..34b04f7 --- a/test/distributed/org/apache/cassandra/distributed/test/JVMDTestTest.java +++ b/test/distributed/org/apache/cassandra/distributed/test/JVMDTestTest.java @@@ -19,11 -19,15 +19,13 @@@ package org.apache.cassandra.distributed.test; import java.io.IOException; + import java.util.Collections; import java.util.List; + import java.util.Map; + import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; --import java.util.logging.Logger; --import org.junit.Assert; + import com.google.common.collect.ImmutableMap; import org.junit.Test; import org.slf4j.LoggerFactory; diff --cc test/unit/org/apache/cassandra/config/YamlConfigurationLoaderTest.java index 0000000,c132ffc..4811b4d mode 000000,100644..100644 --- a/test/unit/org/apache/cassandra/config/YamlConfigurationLoaderTest.java +++ b/test/unit/org/apache/cassandra/config/YamlConfigurationLoaderTest.java @@@ -1,0 -1,54 +1,54 @@@ + /* + * 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.config; + + import java.util.Collections; + import java.util.Map; + + import com.google.common.collect.ImmutableMap; + import org.junit.Test; + + import static org.junit.Assert.assertEquals; + import static org.junit.Assert.assertArrayEquals; + + + public class YamlConfigurationLoaderTest + { + @Test + public void fromMapTest() + { - Integer storagePort = 123; ++ int storagePort = 123; + Config.CommitLogSync commitLogSync = Config.CommitLogSync.batch; + ParameterizedClass seedProvider = new ParameterizedClass("org.apache.cassandra.locator.SimpleSeedProvider", Collections.emptyMap()); + EncryptionOptions encryptionOptions = new EncryptionOptions.ClientEncryptionOptions(); + encryptionOptions.keystore = "myNewKeystore"; + encryptionOptions.cipher_suites = new String[] {"SomeCipher"}; + + Map<String,Object> map = ImmutableMap.of("storage_port", storagePort, + "commitlog_sync", commitLogSync, + "seed_provider", seedProvider, + "client_encryption_options", encryptionOptions); + Config config = YamlConfigurationLoader.fromMap(map, Config.class); + assertEquals(storagePort, config.storage_port); // Check a simple integer + assertEquals(commitLogSync, config.commitlog_sync); // Check an enum + assertEquals(seedProvider, config.seed_provider); // Check a parameterized class + assertEquals(encryptionOptions.keystore, config.client_encryption_options.keystore); // Check a nested object + assertArrayEquals(encryptionOptions.cipher_suites, config.client_encryption_options.cipher_suites); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org