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