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.rsgroup;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021import static org.junit.jupiter.api.Assertions.assertThrows;
022
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.net.Address;
025import org.apache.hadoop.hbase.testclassification.MediumTests;
026import org.apache.hadoop.hbase.util.JVMClusterUtil;
027import org.junit.jupiter.api.AfterAll;
028import org.junit.jupiter.api.AfterEach;
029import org.junit.jupiter.api.BeforeAll;
030import org.junit.jupiter.api.BeforeEach;
031import org.junit.jupiter.api.Tag;
032import org.junit.jupiter.api.Test;
033import org.junit.jupiter.api.TestInfo;
034import org.slf4j.Logger;
035import org.slf4j.LoggerFactory;
036
037import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
038
039@Tag(MediumTests.TAG)
040public class TestUpdateRSGroupConfiguration extends TestRSGroupsBase {
041  protected static final Logger LOG = LoggerFactory.getLogger(TestUpdateRSGroupConfiguration.class);
042  private static final String TEST_GROUP = "test";
043  private static final String TEST2_GROUP = "test2";
044
045  @BeforeAll
046  public static void setUp() throws Exception {
047    setUpConfigurationFiles(TEST_UTIL);
048    setUpTestBeforeClass();
049    addResourceToRegionServerConfiguration(TEST_UTIL);
050  }
051
052  @AfterAll
053  public static void tearDown() throws Exception {
054    tearDownAfterClass();
055  }
056
057  @BeforeEach
058  public void beforeMethod(TestInfo testInfo) throws Exception {
059    setUpBeforeMethod(testInfo);
060  }
061
062  @AfterEach
063  public void afterMethod() throws Exception {
064    tearDownAfterMethod();
065  }
066
067  @Test
068  public void testNonexistentRSGroup() throws Exception {
069    assertThrows(IllegalArgumentException.class, () -> ADMIN.updateConfiguration(TEST2_GROUP));
070  }
071
072  @Test
073  public void testCustomOnlineConfigChangeInRSGroup() throws Exception {
074    RSGroupInfo testRSGroup = addGroup(TEST_GROUP, 1);
075    RSGroupInfo test2RSGroup = addGroup(TEST2_GROUP, 1);
076    // Check the default configuration of the RegionServers
077    TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().forEach(thread -> {
078      Configuration conf = thread.getRegionServer().getConfiguration();
079      assertEquals(0, conf.getInt("hbase.custom.config", 0));
080    });
081
082    replaceHBaseSiteXML();
083    try {
084      ADMIN.updateConfiguration(TEST_GROUP);
085
086      Address testServerAddr = Iterables.getOnlyElement(testRSGroup.getServers());
087      LOG.info("Check hbase.custom.config for " + testServerAddr);
088      Configuration testRsConf = TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads()
089        .stream().map(JVMClusterUtil.RegionServerThread::getRegionServer)
090        .filter(rs -> rs.getServerName().getAddress().equals(testServerAddr)).findFirst().get()
091        .getConfiguration();
092      assertEquals(1000, testRsConf.getInt("hbase.custom.config", 0));
093
094      Address test2ServerAddr = Iterables.getOnlyElement(test2RSGroup.getServers());
095      LOG.info("Check hbase.custom.config for " + test2ServerAddr);
096      // Check the configuration of the RegionServer in test2 rsgroup, should not be update
097      Configuration test2RsConf = TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads()
098        .stream().map(JVMClusterUtil.RegionServerThread::getRegionServer)
099        .filter(rs -> rs.getServerName().getAddress().equals(test2ServerAddr)).findFirst().get()
100        .getConfiguration();
101      assertEquals(0, test2RsConf.getInt("hbase.custom.config", 0));
102    } finally {
103      restoreHBaseSiteXML();
104    }
105  }
106}