HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestLogRoller.java
blob7892d4478f2a6b5af3b071f3cb3464e8478c404d
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 static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseClassTestRule;
26 import org.apache.hadoop.hbase.HBaseTestingUtility;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.regionserver.wal.FSHLog;
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.wal.AbstractFSWALProvider;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.ClassRule;
36 import org.junit.Test;
37 import org.junit.experimental.categories.Category;
39 @Category({RegionServerTests.class, MediumTests.class})
40 public class TestLogRoller {
42 @ClassRule
43 public static final HBaseClassTestRule CLASS_RULE =
44 HBaseClassTestRule.forClass(TestLogRoller.class);
46 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
48 private static final int logRollPeriod = 20 * 1000;
50 @Before
51 public void setup() throws Exception {
52 TEST_UTIL.getConfiguration().setInt("hbase.regionserver.logroll.period", logRollPeriod);
53 TEST_UTIL.startMiniCluster(1);
54 TableName name = TableName.valueOf("Test");
55 TEST_UTIL.createTable(name, Bytes.toBytes("cf"));
56 TEST_UTIL.waitTableAvailable(name);
59 @After
60 public void tearDown() throws Exception {
61 TEST_UTIL.shutdownMiniCluster();
64 @Test
65 public void testRemoveClosedWAL() throws Exception {
66 HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
67 Configuration conf = rs.getConfiguration();
68 LogRoller logRoller = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getWalRoller();
69 int originalSize = logRoller.getWalNeedsRoll().size();
70 FSHLog wal1 = new FSHLog(rs.getWALFileSystem(), rs.getWALRootDir(),
71 AbstractFSWALProvider.getWALDirectoryName(rs.getServerName().getServerName()), conf);
72 logRoller.addWAL(wal1);
73 FSHLog wal2 = new FSHLog(rs.getWALFileSystem(), rs.getWALRootDir(),
74 AbstractFSWALProvider.getWALDirectoryName(rs.getServerName().getServerName()), conf);
75 logRoller.addWAL(wal2);
76 FSHLog wal3 = new FSHLog(rs.getWALFileSystem(), rs.getWALRootDir(),
77 AbstractFSWALProvider.getWALDirectoryName(rs.getServerName().getServerName()), conf);
78 logRoller.addWAL(wal3);
80 assertEquals(originalSize + 3, logRoller.getWalNeedsRoll().size());
81 assertTrue(logRoller.getWalNeedsRoll().containsKey(wal1));
83 wal1.close();
84 Thread.sleep(2 * logRollPeriod);
86 assertEquals(originalSize + 2, logRoller.getWalNeedsRoll().size());
87 assertFalse(logRoller.getWalNeedsRoll().containsKey(wal1));
89 wal2.close();
90 wal3.close();
91 Thread.sleep(2 * logRollPeriod);
93 assertEquals(originalSize, logRoller.getWalNeedsRoll().size());