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.assertNotNull;
022import static org.junit.Assert.assertThrows;
023
024import java.io.IOException;
025import java.util.HashMap;
026import java.util.Map;
027
028import org.apache.hadoop.hbase.HBaseClassTestRule;
029import org.apache.hadoop.hbase.constraint.ConstraintException;
030import org.apache.hadoop.hbase.testclassification.MediumTests;
031import org.junit.AfterClass;
032import org.junit.BeforeClass;
033import org.junit.ClassRule;
034import org.junit.Rule;
035import org.junit.Test;
036import org.junit.experimental.categories.Category;
037import org.junit.rules.TestName;
038import org.slf4j.Logger;
039import org.slf4j.LoggerFactory;
040
041@Category(MediumTests.class)
042public class TestRSGroupConfig extends TestRSGroupsBase {
043
044  @ClassRule
045  public static final HBaseClassTestRule CLASS_RULE =
046      HBaseClassTestRule.forClass(TestRSGroupConfig.class);
047
048  @Rule
049  public TestName name = new TestName();
050
051  protected static final Logger LOG = LoggerFactory.getLogger(TestRSGroupConfig.class);
052
053  @BeforeClass
054  public static void setUpBeforeClass() throws Exception {
055    TestRSGroupsBase.setUpTestBeforeClass();
056  }
057
058  @AfterClass
059  public static void tearDownAfterClass() throws Exception {
060    TestRSGroupsBase.tearDownAfterClass();
061  }
062
063  @Test
064  public void testSetDefaultGroupConfiguration() {
065    assertThrows(ConstraintException.class, () -> testSetConfiguration(RSGroupInfo.DEFAULT_GROUP));
066  }
067
068  @Test
069  public void testSetNonDefaultGroupConfiguration() throws IOException {
070    String group = getGroupName(name.getMethodName());
071    rsGroupAdmin.addRSGroup(group);
072    testSetConfiguration(group);
073    rsGroupAdmin.removeRSGroup(group);
074  }
075
076  private void testSetConfiguration(String group) throws IOException {
077    Map<String, String> configuration = new HashMap<>();
078    configuration.put("aaa", "111");
079    configuration.put("bbb", "222");
080    rsGroupAdmin.updateRSGroupConfig(group, configuration);
081    RSGroupInfo rsGroup = rsGroupAdmin.getRSGroupInfo(group);
082    assertEquals(configuration, rsGroup.getConfiguration());
083    // unset configuration
084    rsGroupAdmin.updateRSGroupConfig(group, null);
085    rsGroup = rsGroupAdmin.getRSGroupInfo(group);
086    Map<String, String> configFromGroup = rsGroup.getConfiguration();
087    assertNotNull(configFromGroup);
088    assertEquals(0, configFromGroup.size());
089  }
090
091}