1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.hbase.zookeeper; 19 20 import java.util.Properties; 21 22 import junit.framework.Assert; 23 24 import org.apache.hadoop.conf.Configuration; 25 import org.apache.hadoop.hbase.HBaseConfiguration; 26 import org.apache.hadoop.hbase.HConstants; 27 import org.apache.hadoop.hbase.testclassification.SmallTests; 28 import org.junit.Test; 29 import org.junit.experimental.categories.Category; 30 31 @Category(SmallTests.class) 32 public class TestZKConfig { 33 @Test 34 public void testZKConfigLoading() throws Exception { 35 // Test depends on test resource 'zoo.cfg' at src/test/resources/zoo.cfg 36 Configuration conf = HBaseConfiguration.create(); 37 // Test that by default we do not pick up any property from the zoo.cfg 38 // since that feature is to be deprecated and removed. So we should read only 39 // from the config instance (i.e. via hbase-default.xml and hbase-site.xml) 40 conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, 2181); 41 Properties props = ZKConfig.makeZKProps(conf); 42 Assert.assertEquals( 43 "Property client port should have been default from the HBase config", 44 "2181", 45 props.getProperty("clientPort")); 46 // Test deprecated zoo.cfg read support by explicitly enabling it and 47 // thereby relying on our test resource zoo.cfg to be read. 48 // We may remove this test after a higher release (i.e. post-deprecation). 49 conf.setBoolean(HConstants.HBASE_CONFIG_READ_ZOOKEEPER_CONFIG, true); 50 props = ZKConfig.makeZKProps(conf); 51 Assert.assertEquals( 52 "Property client port should have been from zoo.cfg", 53 "9999", 54 props.getProperty("clientPort")); 55 } 56 }