From b9fd2456ca92b27b4cc9a70f55bf16deafe56e00 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Tue, 13 Mar 2018 11:53:14 +0800 Subject: [PATCH] HBASE-20182 UT --- .../org/apache/hadoop/hbase/TestSplitMerge.java | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/TestSplitMerge.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSplitMerge.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSplitMerge.java new file mode 100644 index 0000000..95e0cb4 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSplitMerge.java @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.concurrent.TimeUnit; +import org.apache.hadoop.hbase.Waiter.ExplainingPredicate; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.apache.hadoop.hbase.testclassification.MiscTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category({ MiscTests.class, LargeTests.class }) +public class TestSplitMerge { + + private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + @BeforeClass + public static void setUp() throws Exception { + UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 1000); + UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); + UTIL.startMiniCluster(1); + } + + @AfterClass + public static void tearDown() throws Exception { + UTIL.shutdownMiniCluster(); + } + + @Test + public void test() throws Exception { + TableName tableName = TableName.valueOf("SplitMerge"); + byte[] family = Bytes.toBytes("CF"); + TableDescriptor td = TableDescriptorBuilder.newBuilder(tableName) + .addColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build(); + UTIL.getAdmin().createTable(td, new byte[][] { Bytes.toBytes(1) }); + UTIL.waitTableAvailable(tableName); + UTIL.getAdmin().split(tableName, Bytes.toBytes(2)); + UTIL.waitFor(30000, new ExplainingPredicate() { + + @Override + public boolean evaluate() throws Exception { + return UTIL.getMiniHBaseCluster().getRegions(tableName).size() == 3; + } + + @Override + public String explainFailure() throws Exception { + return "Split has not finished yet"; + } + }); + RegionInfo regionA = null; + RegionInfo regionB = null; + for (RegionInfo region : UTIL.getAdmin().getRegions(tableName)) { + if (region.getStartKey().length == 0) { + regionA = region; + } else if (Bytes.equals(region.getStartKey(), Bytes.toBytes(1))) { + regionB = region; + } + } + assertNotNull(regionA); + assertNotNull(regionB); + UTIL.getAdmin().mergeRegionsAsync(regionA.getRegionName(), regionB.getRegionName(), false) + .get(30, TimeUnit.SECONDS); + assertEquals(2, UTIL.getAdmin().getRegions(tableName).size()); + assertEquals(UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName(), UTIL.getConnection() + .getRegionLocator(tableName).getRegionLocation(Bytes.toBytes(1), true).getServerName()); + } +} -- 2.7.4