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