HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / master / TestRegionPlansWithThrottle.java
blob96b419b3637254426ce8d8f0d377b8e8926307ec
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org.apache.hadoop.hbase.master;
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HBaseTestingUtil;
25 import org.apache.hadoop.hbase.StartTestingClusterOption;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
28 import org.apache.hadoop.hbase.client.Put;
29 import org.apache.hadoop.hbase.client.RegionInfo;
30 import org.apache.hadoop.hbase.client.Table;
31 import org.apache.hadoop.hbase.client.TableDescriptor;
32 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
33 import org.apache.hadoop.hbase.testclassification.MediumTests;
34 import org.apache.hadoop.hbase.testclassification.MiscTests;
35 import org.apache.hadoop.hbase.util.Bytes;
36 import org.junit.AfterClass;
37 import org.junit.Assert;
38 import org.junit.BeforeClass;
39 import org.junit.ClassRule;
40 import org.junit.Test;
41 import org.junit.experimental.categories.Category;
43 @Category({ MiscTests.class, MediumTests.class})
44 public class TestRegionPlansWithThrottle {
46 @ClassRule
47 public static final HBaseClassTestRule CLASS_RULE =
48 HBaseClassTestRule.forClass(TestRegionPlansWithThrottle.class);
50 private static HMaster hMaster;
52 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
54 @BeforeClass
55 public static void setUp() throws Exception {
56 UTIL.startMiniCluster(StartTestingClusterOption.builder().numRegionServers(2).build());
57 hMaster = UTIL.getMiniHBaseCluster().getMaster();
60 @AfterClass
61 public static void tearDown() throws Exception {
62 UTIL.shutdownMiniCluster();
65 @Test
66 public void testExecuteRegionPlansWithThrottling() throws Exception {
67 final TableName tableName = TableName.valueOf("testExecuteRegionPlansWithThrottling");
69 TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName)
70 .setColumnFamily(ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("cf"))).build();
72 UTIL.getAdmin().createTable(tableDescriptor);
73 Table table = UTIL.getConnection().getTable(tableName);
75 List<Put> puts = new ArrayList<>();
76 for (int i = 0; i < 100; i++) {
77 Put put = new Put(Bytes.toBytes("row" + i));
78 byte[] q = Bytes.toBytes("q1");
79 byte[] v = Bytes.toBytes("v" + i);
80 put.addColumn(Bytes.toBytes("cf"), q, v);
81 puts.add(put);
83 table.put(puts);
84 UTIL.getAdmin().flush(tableName);
85 UTIL.getAdmin().split(tableName, Bytes.toBytes("v5"));
87 List<RegionPlan> plans = new ArrayList<>();
88 List<RegionInfo> regionInfos = UTIL.getAdmin().getRegions(tableName);
89 for (RegionInfo regionInfo : regionInfos) {
90 plans.add(
91 new RegionPlan(regionInfo, UTIL.getHBaseCluster().getRegionServer(0).getServerName(),
92 UTIL.getHBaseCluster().getRegionServer(1).getServerName()));
94 List<RegionPlan> successPlans = hMaster.executeRegionPlansWithThrottling(plans);
95 Assert.assertEquals(regionInfos.size(), successPlans.size());