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      // This test depends on namespace region open; therefore, we have to wait for namespace
54      // manager start before continue.
55      HTU.getConfiguration().setBoolean("hbase.master.start.wait.for.namespacemanager", true);
56      HTU.startMiniCluster(NB_SERVERS);
57      HTU.waitUntilAllSystemRegionsAssigned();
58    }
59  
60    @AfterClass
61    public static void afterClass() throws Exception {
62      HTU.shutdownMiniCluster();
63    }
64  
65    private static HRegionServer getRS() {
66      return HTU.getHBaseCluster().getLiveRegionServerThreads().get(0).getRegionServer();
67    }
68  
69    @Test(timeout = 60000)
70    public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception {
71      ThreadPoolExecutor exec = getRS().getExecutorService()
72          .getExecutorThreadPool(ExecutorType.RS_OPEN_PRIORITY_REGION);
73  
74      long taskCount = exec.getCompletedTaskCount(); // System table regions
75  
76      HTableDescriptor htd = new HTableDescriptor(tableName);
77      htd.setPriority(HConstants.HIGH_QOS);
78      htd.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
79      try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
80          Admin admin = connection.getAdmin()) {
81        admin.createTable(htd);
82      }
83  
84      assertEquals(taskCount+1, exec.getCompletedTaskCount());
85    }
86  }