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