View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  import java.util.concurrent.ThreadPoolExecutor;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.hadoop.hbase.HBaseTestingUtility;
28  import org.apache.hadoop.hbase.HColumnDescriptor;
29  import org.apache.hadoop.hbase.HConstants;
30  import org.apache.hadoop.hbase.HTableDescriptor;
31  import org.apache.hadoop.hbase.TableName;
32  import org.apache.hadoop.hbase.client.ConnectionFactory;
33  import org.apache.hadoop.hbase.executor.ExecutorType;
34  import org.apache.hadoop.hbase.testclassification.MediumTests;
35  import org.apache.hadoop.hbase.testclassification.RegionServerTests;
36  import org.apache.hadoop.hbase.client.Admin;
37  import org.apache.hadoop.hbase.client.Connection;
38  import org.junit.AfterClass;
39  import org.junit.BeforeClass;
40  import org.junit.Test;
41  import org.junit.experimental.categories.Category;
42  
43  @Category({MediumTests.class, RegionServerTests.class})
44  public class TestRegionOpen {
45    @SuppressWarnings("unused")
46    private static final Log LOG = LogFactory.getLog(TestRegionOpen.class);
47    private static final int NB_SERVERS = 1;
48  
49    private static final HBaseTestingUtility HTU = new HBaseTestingUtility();
50    final TableName tableName = TableName.valueOf(TestRegionOpen.class.getSimpleName());
51  
52    @BeforeClass
53    public static void before() throws Exception {
54      HTU.startMiniCluster(NB_SERVERS);
55    }
56  
57    @AfterClass
58    public static void afterClass() throws Exception {
59      HTU.shutdownMiniCluster();
60    }
61  
62    private static HRegionServer getRS() {
63      return HTU.getHBaseCluster().getLiveRegionServerThreads().get(0).getRegionServer();
64    }
65  
66    @Test(timeout = 60000)
67    public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception {
68      ThreadPoolExecutor exec = getRS().getExecutorService()
69          .getExecutorThreadPool(ExecutorType.RS_OPEN_PRIORITY_REGION);
70  
71      assertEquals(1, exec.getCompletedTaskCount()); // namespace region
72  
73      HTableDescriptor htd = new HTableDescriptor(tableName);
74      htd.setPriority(HConstants.HIGH_QOS);
75      htd.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
76      try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
77          Admin admin = connection.getAdmin()) {
78        admin.createTable(htd);
79      }
80  
81      assertEquals(2, exec.getCompletedTaskCount());
82    }
83  }