|
| 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 | +package org.apache.hadoop.hbase.regionserver; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | + |
| 22 | +import org.apache.hadoop.conf.Configuration; |
| 23 | +import org.apache.hadoop.fs.FileStatus; |
| 24 | +import org.apache.hadoop.fs.FileSystem; |
| 25 | +import org.apache.hadoop.fs.Path; |
| 26 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 27 | +import org.apache.hadoop.hbase.HBaseConfiguration; |
| 28 | +import org.apache.hadoop.hbase.HBaseTestingUtility; |
| 29 | +import org.apache.hadoop.hbase.testclassification.MediumTests; |
| 30 | +import org.apache.hadoop.hbase.testclassification.RegionServerTests; |
| 31 | +import org.apache.hadoop.hbase.util.Bytes; |
| 32 | +import org.apache.hadoop.hbase.util.CommonFSUtils; |
| 33 | +import org.apache.hadoop.util.ToolRunner; |
| 34 | +import org.junit.Before; |
| 35 | +import org.junit.ClassRule; |
| 36 | +import org.junit.Test; |
| 37 | +import org.junit.experimental.categories.Category; |
| 38 | + |
| 39 | +/** |
| 40 | + * Test the issue of HBASE-28472 |
| 41 | + */ |
| 42 | +@Category({ MediumTests.class, RegionServerTests.class }) |
| 43 | +public class TestCompactionToolNpeFix extends TestCompactionTool { |
| 44 | + |
| 45 | + @ClassRule |
| 46 | + public static final HBaseClassTestRule CLASS_RULE = |
| 47 | + HBaseClassTestRule.forClass(TestCompactionToolNpeFix.class); |
| 48 | + |
| 49 | + @Before |
| 50 | + public void setUp() throws Exception { |
| 51 | + testUtil.getConfiguration().setBoolean(MemStoreLAB.USEMSLAB_KEY, false); |
| 52 | + super.setUp(); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testCompactedFilesArchivedMapRed() throws Exception { |
| 57 | + for (int i = 0; i < 10; i++) { |
| 58 | + this.putAndFlush(i); |
| 59 | + } |
| 60 | + HStore store = region.getStore(HBaseTestingUtility.fam1); |
| 61 | + assertEquals(10, store.getStorefilesCount()); |
| 62 | + Path tableDir = CommonFSUtils.getTableDir(rootDir, region.getRegionInfo().getTable()); |
| 63 | + FileSystem fs = store.getFileSystem(); |
| 64 | + String storePath = tableDir + "/" + region.getRegionInfo().getEncodedName() + "/" |
| 65 | + + Bytes.toString(HBaseTestingUtility.fam1); |
| 66 | + FileStatus[] regionDirFiles = fs.listStatus(new Path(storePath)); |
| 67 | + assertEquals(10, regionDirFiles.length); |
| 68 | + String defaultFS = testUtil.getMiniHBaseCluster().getConfiguration().get("fs.defaultFS"); |
| 69 | + testUtil.startMiniMapReduceCluster(); |
| 70 | + try { |
| 71 | + Configuration config = HBaseConfiguration.create(testUtil.getConfiguration()); |
| 72 | + config.setBoolean(MemStoreLAB.USEMSLAB_KEY, true); |
| 73 | + config.set("fs.defaultFS", defaultFS); |
| 74 | + int result = ToolRunner.run(config, new CompactionTool(), |
| 75 | + new String[] { "-compactOnce", "-mapred", "-major", storePath }); |
| 76 | + assertEquals(0, result); |
| 77 | + regionDirFiles = fs.listStatus(new Path(storePath)); |
| 78 | + assertEquals(1, regionDirFiles.length); |
| 79 | + } finally { |
| 80 | + testUtil.shutdownMiniMapReduceCluster(); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments