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.Assert.assertEquals;
021import static org.junit.Assert.assertThrows;
022
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.net.Address;
026import org.apache.hadoop.hbase.testclassification.MediumTests;
027import org.apache.hadoop.hbase.util.JVMClusterUtil;
028import org.junit.After;
029import org.junit.AfterClass;
030import org.junit.Before;
031import org.junit.BeforeClass;
032import org.junit.ClassRule;
033import org.junit.Ignore;
034import org.junit.Test;
035import org.junit.experimental.categories.Category;
036import org.slf4j.Logger;
037import org.slf4j.LoggerFactory;
038
039import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
040
041@Category({ MediumTests.class })
042public class TestUpdateRSGroupConfiguration extends TestRSGroupsBase {
043  protected static final Logger LOG = LoggerFactory.getLogger(TestUpdateRSGroupConfiguration.class);
044
045  @ClassRule
046  public static final HBaseClassTestRule CLASS_RULE =
047    HBaseClassTestRule.forClass(TestUpdateRSGroupConfiguration.class);
048  private static final String TEST_GROUP = "test";
049  private static final String TEST2_GROUP = "test2";
050
051  @BeforeClass
052  public static void setUp() throws Exception {
053    setUpConfigurationFiles(TEST_UTIL);
054    setUpTestBeforeClass();
055    addResourceToRegionServerConfiguration(TEST_UTIL);
056  }
057
058  @AfterClass
059  public static void tearDown() throws Exception {
060    tearDownAfterClass();
061  }
062
063  @Before
064  public void beforeMethod() throws Exception {
065    setUpBeforeMethod();
066  }
067
068  @After
069  public void afterMethod() throws Exception {
070    tearDownAfterMethod();
071  }
072
073  @Test
074  public void testNonexistentRSGroup() throws Exception {
075    assertThrows(IllegalArgumentException.class,
076      () -> rsGroupAdmin.updateConfiguration(TEST2_GROUP));
077  }
078
079  // This test relies on a disallowed API change in RSGroupInfo and was also found to be
080  // flaky. REVERTED from branch-2.5 and branch-2.
081  @Test
082  @Ignore
083  public void testCustomOnlineConfigChangeInRSGroup() throws Exception {
084    RSGroupInfo testRSGroup = addGroup(TEST_GROUP, 1);
085    RSGroupInfo test2RSGroup = addGroup(TEST2_GROUP, 1);
086    // Check the default configuration of the RegionServers
087    TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().forEach(thread -> {
088      Configuration conf = thread.getRegionServer().getConfiguration();
089      assertEquals(0, conf.getInt("hbase.custom.config", 0));
090    });
091
092    replaceHBaseSiteXML();
093    try {
094      rsGroupAdmin.updateConfiguration(TEST_GROUP);
095
096      Address testServerAddr = Iterables.getOnlyElement(testRSGroup.getServers());
097      LOG.info("Check hbase.custom.config for " + testServerAddr);
098      Configuration testRsConf = TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads()
099        .stream().map(JVMClusterUtil.RegionServerThread::getRegionServer)
100        .filter(rs -> rs.getServerName().getAddress().equals(testServerAddr)).findFirst().get()
101        .getConfiguration();
102      assertEquals(1000, testRsConf.getInt("hbase.custom.config", 0));
103
104      Address test2ServerAddr = Iterables.getOnlyElement(test2RSGroup.getServers());
105      LOG.info("Check hbase.custom.config for " + test2ServerAddr);
106      // Check the configuration of the RegionServer in test2 rsgroup, should not be update
107      Configuration test2RsConf = TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads()
108        .stream().map(JVMClusterUtil.RegionServerThread::getRegionServer)
109        .filter(rs -> rs.getServerName().getAddress().equals(test2ServerAddr)).findFirst().get()
110        .getConfiguration();
111      assertEquals(0, test2RsConf.getInt("hbase.custom.config", 0));
112    } finally {
113      restoreHBaseSiteXML();
114    }
115  }
116}