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