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.jupiter.api.Assertions.assertEquals;
021
022import java.io.IOException;
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.HBaseTestingUtil;
025import org.apache.hadoop.hbase.ServerName;
026import org.apache.hadoop.hbase.StartTestingClusterOption;
027import org.apache.hadoop.hbase.testclassification.MediumTests;
028import org.junit.jupiter.api.BeforeAll;
029import org.junit.jupiter.api.BeforeEach;
030import org.junit.jupiter.api.Tag;
031import org.junit.jupiter.api.Test;
032import org.junit.jupiter.api.TestInfo;
033import org.slf4j.Logger;
034import org.slf4j.LoggerFactory;
035
036@Tag(MediumTests.TAG)
037public class TestUpdateConfiguration extends AbstractTestUpdateConfiguration {
038
039  private static final Logger LOG = LoggerFactory.getLogger(TestUpdateConfiguration.class);
040  private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
041
042  @BeforeAll
043  public static void setup() throws Exception {
044    setUpConfigurationFiles(TEST_UTIL);
045    StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(2).build();
046    TEST_UTIL.startMiniCluster(option);
047    addResourceToRegionServerConfiguration(TEST_UTIL);
048  }
049
050  private String methodName;
051
052  @BeforeEach
053  public void setUpMethodName(TestInfo testInfo) {
054    this.methodName = testInfo.getTestMethod().get().getName();
055  }
056
057  @Test
058  public void testOnlineConfigChange() throws IOException {
059    LOG.debug("Starting the test {}", methodName);
060    Admin admin = TEST_UTIL.getAdmin();
061    ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
062    admin.updateConfiguration(server);
063  }
064
065  @Test
066  public void testMasterOnlineConfigChange() throws IOException {
067    LOG.debug("Starting the test {}", methodName);
068    replaceHBaseSiteXML();
069    Admin admin = TEST_UTIL.getAdmin();
070    ServerName server = TEST_UTIL.getHBaseCluster().getMaster().getServerName();
071    admin.updateConfiguration(server);
072    Configuration conf = TEST_UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
073    int custom = conf.getInt("hbase.custom.config", 0);
074    assertEquals(1000, custom);
075    restoreHBaseSiteXML();
076  }
077
078  @Test
079  public void testAllOnlineConfigChange() throws IOException {
080    LOG.debug("Starting the test {} ", methodName);
081    Admin admin = TEST_UTIL.getAdmin();
082    admin.updateConfiguration();
083  }
084
085  @Test
086  public void testAllCustomOnlineConfigChange() throws IOException {
087    LOG.debug("Starting the test {}", methodName);
088    replaceHBaseSiteXML();
089
090    Admin admin = TEST_UTIL.getAdmin();
091    admin.updateConfiguration();
092
093    // Check the configuration of the Masters
094    Configuration masterConfiguration =
095      TEST_UTIL.getMiniHBaseCluster().getMaster(0).getConfiguration();
096    int custom = masterConfiguration.getInt("hbase.custom.config", 0);
097    assertEquals(1000, custom);
098    Configuration backupMasterConfiguration =
099      TEST_UTIL.getMiniHBaseCluster().getMaster(1).getConfiguration();
100    custom = backupMasterConfiguration.getInt("hbase.custom.config", 0);
101    assertEquals(1000, custom);
102
103    // Check the configuration of the RegionServer
104    Configuration regionServerConfiguration =
105      TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getConfiguration();
106    custom = regionServerConfiguration.getInt("hbase.custom.config", 0);
107    assertEquals(1000, custom);
108
109    restoreHBaseSiteXML();
110  }
111}