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.client.Admin;
36  import org.apache.hadoop.hbase.client.Connection;
37  import org.junit.AfterClass;
38  import org.junit.BeforeClass;
39  import org.junit.Test;
40  import org.junit.experimental.categories.Category;
41  
42  @Category({MediumTests.class})
43  public class TestRegionOpen {
44    @SuppressWarnings("unused")
45    private static final Log LOG = LogFactory.getLog(TestRegionOpen.class);
46    private static final int NB_SERVERS = 1;
47  
48    private static final HBaseTestingUtility HTU = new HBaseTestingUtility();
49    final TableName tableName = TableName.valueOf(TestRegionOpen.class.getSimpleName());
50  
51    @BeforeClass
52    public static void before() throws Exception {
53      HTU.startMiniCluster(NB_SERVERS);
54      HTU.waitUntilAllSystemRegionsAssigned();
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      long taskCount = exec.getCompletedTaskCount(); // System table regions
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(taskCount+1, exec.getCompletedTaskCount());
82    }
83  }