narendly commented on a change in pull request #589: Add CloudConfig operations URL: https://github.com/apache/helix/pull/589#discussion_r352752228
########## File path: helix-core/src/test/java/org/apache/helix/model/cloud/TestCloudConfig.java ########## @@ -0,0 +1,176 @@ +package org.apache.helix.model.cloud; + +/* + * 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. + */ + +import java.util.ArrayList; +import org.apache.helix.ConfigAccessor; +import org.apache.helix.HelixException; +import org.apache.helix.PropertyKey.Builder; +import org.apache.helix.TestHelper; +import org.apache.helix.ZkUnitTestBase; +import org.apache.helix.manager.zk.ZKHelixDataAccessor; +import org.apache.helix.manager.zk.ZkBaseDataAccessor; +import org.apache.helix.model.CloudConfig; +import java.util.List; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class TestCloudConfig extends ZkUnitTestBase { + + @Test(expectedExceptions = HelixException.class) + public void testCloudConfigNonExistentCluster() { + String className = getShortClassName(); + String clusterName = "CLUSTER_" + className; + // Read CloudConfig from Zookeeper and get exception since cluster in not setup yet + ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient); + CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName); + } + + @Test(dependsOnMethods = "testCloudConfigNonExistentCluster") + public void testCloudConfigNull() { + String className = getShortClassName(); + String clusterName = "CLUSTER_" + className; + TestHelper.setupEmptyCluster(_gZkClient, clusterName); + // Read CloudConfig from Zookeeper + ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient); + CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName); + // since CloudConfig is not written to ZooKeeper, the output should be null + Assert.assertNull(cloudConfigFromZk); + } + + @Test(dependsOnMethods = "testCloudConfigNull") + public void testCloudConfig() { + String className = getShortClassName(); + String clusterName = "CLUSTER_" + className; + TestHelper.setupEmptyCluster(_gZkClient, clusterName); + + // Create dummy CloudConfig object + CloudConfig cloudConfig = new CloudConfig(clusterName); + cloudConfig.setCloudEnabled(true); + cloudConfig.setCloudID("TestID"); + List<String> infoURL = new ArrayList<String>(); + infoURL.add("TestURL"); + cloudConfig.setCloudInfoURLs(infoURL); + cloudConfig.setCloudInfoFetcherClassName("TestFetcher"); + cloudConfig.setCloudInfoParserClassName("TestParser"); + + // Write the CloudConfig to Zookeeper + ZKHelixDataAccessor accessor = + new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient)); + Builder keyBuilder = accessor.keyBuilder(); + accessor.setProperty(keyBuilder.cloudConfig(), cloudConfig); + + // Read CloudConfig from Zookeeper and check the content + ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient); + CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName); + Assert.assertTrue(cloudConfigFromZk.isCloudEnabled()); + Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestID"); + Assert.assertEquals(cloudConfigFromZk.getCloudInfoURLs().size(), 1); + Assert.assertEquals(cloudConfigFromZk.getCloudInfoURLs().get(0), "TestURL"); + Assert.assertEquals(cloudConfigFromZk.getCloudInfoFetcherClassName(), "TestFetcher"); + Assert.assertEquals(cloudConfigFromZk.getCloudInfoParserClassName(), "TestParser"); + } + + @Test(expectedExceptions = HelixException.class) + public void testUnverifiedCloudConfigBuilder() { + String className = getShortClassName(); + String clusterName = "CLUSTER_" + className; + CloudConfig.Builder builder = new CloudConfig.Builder(clusterName); + builder.setCloudEnabled(true); + // Verify will fail because CloudID, CLOUD_INFO_URL and CLOUD_INFO_PARSE_CLASS_NAME have not + // been set yet + CloudConfig cloudConfig = builder.build(); + } + + + + @Test(expectedExceptions = HelixException.class) + public void testUnverifiedCloudConfigBuilderEmptyURL() { + String className = getShortClassName(); + String clusterName = "CLUSTER_" + className; + CloudConfig.Builder builder = new CloudConfig.Builder(clusterName); + builder.setCloudEnabled(true); + // Review comment: ? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
