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.master; 019 020import java.util.ArrayList; 021import java.util.List; 022import org.apache.hadoop.hbase.HBaseClassTestRule; 023import org.apache.hadoop.hbase.HBaseTestingUtility; 024import org.apache.hadoop.hbase.StartMiniClusterOption; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; 027import org.apache.hadoop.hbase.client.Put; 028import org.apache.hadoop.hbase.client.RegionInfo; 029import org.apache.hadoop.hbase.client.Table; 030import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 031import org.apache.hadoop.hbase.testclassification.MediumTests; 032import org.apache.hadoop.hbase.testclassification.MiscTests; 033import org.apache.hadoop.hbase.util.Bytes; 034import org.junit.AfterClass; 035import org.junit.Assert; 036import org.junit.BeforeClass; 037import org.junit.ClassRule; 038import org.junit.Test; 039import org.junit.experimental.categories.Category; 040 041@Category({ MiscTests.class, MediumTests.class }) 042public class TestRegionPlansWithThrottle { 043 044 @ClassRule 045 public static final HBaseClassTestRule CLASS_RULE = 046 HBaseClassTestRule.forClass(TestRegionPlansWithThrottle.class); 047 048 private static HMaster hMaster; 049 050 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); 051 052 @BeforeClass 053 public static void setUp() throws Exception { 054 UTIL.startMiniCluster(StartMiniClusterOption.builder().numRegionServers(2).build()); 055 hMaster = UTIL.getMiniHBaseCluster().getMaster(); 056 } 057 058 @AfterClass 059 public static void tearDown() throws Exception { 060 UTIL.shutdownMiniCluster(); 061 } 062 063 @Test 064 public void testExecuteRegionPlansWithThrottling() throws Exception { 065 final TableName tableName = TableName.valueOf("testExecuteRegionPlansWithThrottling"); 066 067 TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor = 068 new TableDescriptorBuilder.ModifyableTableDescriptor(tableName).setColumnFamily( 069 new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(Bytes.toBytes("cf"))); 070 071 UTIL.getAdmin().createTable(tableDescriptor); 072 Table table = UTIL.getConnection().getTable(tableName); 073 074 List<Put> puts = new ArrayList<>(); 075 for (int i = 0; i < 100; i++) { 076 Put put = new Put(Bytes.toBytes("row" + i)); 077 byte[] q = Bytes.toBytes("q1"); 078 byte[] v = Bytes.toBytes("v" + i); 079 put.addColumn(Bytes.toBytes("cf"), q, v); 080 puts.add(put); 081 } 082 table.put(puts); 083 UTIL.getAdmin().flush(tableName); 084 UTIL.getAdmin().split(tableName, Bytes.toBytes("v5")); 085 086 List<RegionPlan> plans = new ArrayList<>(); 087 List<RegionInfo> regionInfos = UTIL.getAdmin().getRegions(tableName); 088 for (RegionInfo regionInfo : regionInfos) { 089 plans 090 .add(new RegionPlan(regionInfo, UTIL.getHBaseCluster().getRegionServer(0).getServerName(), 091 UTIL.getHBaseCluster().getRegionServer(1).getServerName())); 092 } 093 List<RegionPlan> successPlans = hMaster.executeRegionPlansWithThrottling(plans); 094 Assert.assertEquals(regionInfos.size(), successPlans.size()); 095 } 096 097}