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.jupiter.api.Assertions.assertTrue;
021
022import org.apache.hadoop.hbase.ServerName;
023import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.hadoop.hbase.testclassification.MediumTests;
026import org.apache.hadoop.hbase.testclassification.RSGroupTests;
027import org.junit.jupiter.api.AfterAll;
028import org.junit.jupiter.api.AfterEach;
029import org.junit.jupiter.api.BeforeAll;
030import org.junit.jupiter.api.BeforeEach;
031import org.junit.jupiter.api.Tag;
032import org.junit.jupiter.api.Test;
033import org.junit.jupiter.api.TestInfo;
034
035@Tag(RSGroupTests.TAG)
036@Tag(MediumTests.TAG)
037public class TestRSGroupsCPHookCalled extends TestRSGroupsBase {
038
039  @BeforeAll
040  public static void setUp() throws Exception {
041    setUpTestBeforeClass();
042  }
043
044  @AfterAll
045  public static void tearDown() throws Exception {
046    tearDownAfterClass();
047  }
048
049  @BeforeEach
050  public void beforeMethod(TestInfo testInfo) throws Exception {
051    setUpBeforeMethod(testInfo);
052  }
053
054  @AfterEach
055  public void afterMethod() throws Exception {
056    tearDownAfterMethod();
057  }
058
059  @Test
060  public void testGetRSGroupInfoCPHookCalled() throws Exception {
061    ADMIN.getRSGroup(RSGroupInfo.DEFAULT_GROUP);
062    assertTrue(OBSERVER.preGetRSGroupInfoCalled);
063    assertTrue(OBSERVER.postGetRSGroupInfoCalled);
064  }
065
066  @Test
067  public void testGetRSGroupInfoOfTableCPHookCalled() throws Exception {
068    ADMIN.getRSGroup(TableName.META_TABLE_NAME);
069    assertTrue(OBSERVER.preGetRSGroupInfoOfTableCalled);
070    assertTrue(OBSERVER.postGetRSGroupInfoOfTableCalled);
071  }
072
073  @Test
074  public void testListRSGroupsCPHookCalled() throws Exception {
075    ADMIN.listRSGroups();
076    assertTrue(OBSERVER.preListRSGroupsCalled);
077    assertTrue(OBSERVER.postListRSGroupsCalled);
078  }
079
080  @Test
081  public void testGetRSGroupInfoOfServerCPHookCalled() throws Exception {
082    ServerName masterServerName = ((SingleProcessHBaseCluster) CLUSTER).getMaster().getServerName();
083    ADMIN.getRSGroup(masterServerName.getAddress());
084    assertTrue(OBSERVER.preGetRSGroupInfoOfServerCalled);
085    assertTrue(OBSERVER.postGetRSGroupInfoOfServerCalled);
086  }
087}