001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import static org.junit.Assert.assertEquals;
021
022import java.io.IOException;
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.HBaseTestingUtility;
026import org.apache.hadoop.hbase.ServerName;
027import org.apache.hadoop.hbase.StartMiniClusterOption;
028import org.apache.hadoop.hbase.testclassification.MediumTests;
029import org.junit.BeforeClass;
030import org.junit.ClassRule;
031import org.junit.Rule;
032import org.junit.Test;
033import org.junit.experimental.categories.Category;
034import org.junit.rules.TestName;
035import org.slf4j.Logger;
036import org.slf4j.LoggerFactory;
037
038@Category({MediumTests.class})
039public class TestUpdateConfiguration extends AbstractTestUpdateConfiguration {
040
041  @ClassRule
042  public static final HBaseClassTestRule CLASS_RULE =
043      HBaseClassTestRule.forClass(TestUpdateConfiguration.class);
044
045  private static final Logger LOG = LoggerFactory.getLogger(TestUpdateConfiguration.class);
046  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
047
048  @BeforeClass
049  public static void setup() throws Exception {
050    setUpConfigurationFiles(TEST_UTIL);
051    StartMiniClusterOption option = StartMiniClusterOption.builder().numMasters(2).build();
052    TEST_UTIL.startMiniCluster(option);
053    addResourceToRegionServerConfiguration(TEST_UTIL);
054  }
055
056  @Rule
057  public TestName name = new TestName();
058
059  @Test
060  public void testOnlineConfigChange() throws IOException {
061    LOG.debug("Starting the test {}", name.getMethodName());
062    Admin admin = TEST_UTIL.getAdmin();
063    ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
064    admin.updateConfiguration(server);
065  }
066
067  @Test
068  public void testMasterOnlineConfigChange() throws IOException {
069    LOG.debug("Starting the test {}", name.getMethodName());
070    replaceHBaseSiteXML();
071    Admin admin = TEST_UTIL.getAdmin();
072    ServerName server = TEST_UTIL.getHBaseCluster().getMaster().getServerName();
073    admin.updateConfiguration(server);
074    Configuration conf = TEST_UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
075    int custom = conf.getInt("hbase.custom.config", 0);
076    assertEquals(1000, custom);
077    restoreHBaseSiteXML();
078  }
079
080  @Test
081  public void testAllOnlineConfigChange() throws IOException {
082    LOG.debug("Starting the test {} ", name.getMethodName());
083    Admin admin = TEST_UTIL.getAdmin();
084    admin.updateConfiguration();
085  }
086
087  @Test
088  public void testAllCustomOnlineConfigChange() throws IOException {
089    LOG.debug("Starting the test {}", name.getMethodName());
090    replaceHBaseSiteXML();
091
092    Admin admin = TEST_UTIL.getAdmin();
093    admin.updateConfiguration();
094
095    // Check the configuration of the Masters
096    Configuration masterConfiguration =
097        TEST_UTIL.getMiniHBaseCluster().getMaster(0).getConfiguration();
098    int custom = masterConfiguration.getInt("hbase.custom.config", 0);
099    assertEquals(1000, custom);
100    Configuration backupMasterConfiguration =
101        TEST_UTIL.getMiniHBaseCluster().getMaster(1).getConfiguration();
102    custom = backupMasterConfiguration.getInt("hbase.custom.config", 0);
103    assertEquals(1000, custom);
104
105    // Check the configuration of the RegionServer
106    Configuration regionServerConfiguration =
107        TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getConfiguration();
108    custom = regionServerConfiguration.getInt("hbase.custom.config", 0);
109    assertEquals(1000, custom);
110
111    restoreHBaseSiteXML();
112  }
113}