HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestCleanupMetaWAL.java
bloba5c2987afbf6c136b159159eae9b94b1c5fe8cf7
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.
18 package org.apache.hadoop.hbase.regionserver;
20 import org.apache.hadoop.fs.FileStatus;
21 import org.apache.hadoop.fs.Path;
22 import org.apache.hadoop.hbase.HBaseClassTestRule;
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.HConstants;
25 import org.apache.hadoop.hbase.TableName;
26 import org.apache.hadoop.hbase.client.RegionInfoBuilder;
27 import org.apache.hadoop.hbase.master.MasterFileSystem;
28 import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure;
29 import org.apache.hadoop.hbase.testclassification.MediumTests;
30 import org.apache.hadoop.hbase.util.FSUtils;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.ClassRule;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 import static org.apache.hadoop.hbase.wal.AbstractFSWALProvider.SPLITTING_EXT;
40 import static org.junit.Assert.fail;
42 @Category(MediumTests.class)
43 public class TestCleanupMetaWAL {
44 private static final Logger LOG = LoggerFactory.getLogger(TestCleanupMetaWAL.class);
46 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
48 @ClassRule
49 public static final HBaseClassTestRule CLASS_RULE =
50 HBaseClassTestRule.forClass(TestCleanupMetaWAL.class);
52 @BeforeClass
53 public static void before() throws Exception {
54 TEST_UTIL.startMiniCluster(2);
57 @AfterClass
58 public static void after() throws Exception {
59 TEST_UTIL.shutdownMiniZKCluster();
62 @Test
63 public void testCleanupMetaWAL() throws Exception {
64 TEST_UTIL.createTable(TableName.valueOf("test"), "cf");
65 HRegionServer serverWithMeta = TEST_UTIL.getMiniHBaseCluster()
66 .getRegionServer(TEST_UTIL.getMiniHBaseCluster().getServerWithMeta());
67 TEST_UTIL.getAdmin()
68 .move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes());
69 LOG.info("KILL");
70 TEST_UTIL.getMiniHBaseCluster().killRegionServer(serverWithMeta.getServerName());
71 LOG.info("WAIT");
72 TEST_UTIL.waitFor(30000, () ->
73 TEST_UTIL.getMiniHBaseCluster().getMaster().getProcedures().stream()
74 .filter(p -> p instanceof ServerCrashProcedure && p.isFinished()).count() > 0);
75 LOG.info("DONE WAITING");
76 MasterFileSystem fs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
77 Path walPath = new Path(fs.getWALRootDir(), HConstants.HREGION_LOGDIR_NAME);
78 for (FileStatus status : FSUtils.listStatus(fs.getFileSystem(), walPath)) {
79 if (status.getPath().toString().contains(SPLITTING_EXT)) {
80 fail("Should not have splitting wal dir here:" + status);