HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / wal / TestRaceBetweenGetWALAndGetWALs.java
blob26ff11836f052c43fe0121c2f9ad74374575d4f8
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.wal;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertSame;
23 import java.io.IOException;
24 import java.util.List;
25 import java.util.concurrent.ExecutionException;
26 import java.util.concurrent.ForkJoinPool;
27 import java.util.concurrent.Future;
28 import org.apache.hadoop.conf.Configuration;
29 import org.apache.hadoop.hbase.HBaseClassTestRule;
30 import org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL;
31 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
32 import org.apache.hadoop.hbase.testclassification.SmallTests;
33 import org.apache.hadoop.hbase.util.Threads;
34 import org.junit.ClassRule;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37 import org.mockito.Mockito;
39 import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
41 /**
42 * Testcase for HBASE-21503.
44 @Category({ RegionServerTests.class, SmallTests.class })
45 public class TestRaceBetweenGetWALAndGetWALs {
47 @ClassRule
48 public static final HBaseClassTestRule CLASS_RULE =
49 HBaseClassTestRule.forClass(TestRaceBetweenGetWALAndGetWALs.class);
51 private static Future<List<WAL>> GET_WALS_FUTURE;
53 private static final class FSWALProvider extends AbstractFSWALProvider<AbstractFSWAL<?>> {
55 @Override
56 protected AbstractFSWAL<?> createWAL() throws IOException {
57 // just like what may do in the WALListeners, schedule an asynchronous task to call the
58 // getWALs method.
59 GET_WALS_FUTURE = ForkJoinPool.commonPool().submit(this::getWALs);
60 // sleep a while to make the getWALs arrive before we return
61 Threads.sleep(2000);
62 return Mockito.mock(AbstractFSWAL.class);
65 @Override
66 protected void doInit(Configuration conf) throws IOException {
70 @Test
71 public void testRace() throws IOException, InterruptedException, ExecutionException {
72 FSWALProvider p = new FSWALProvider();
73 WAL wal = p.getWAL(null);
74 assertNotNull(GET_WALS_FUTURE);
75 List<WAL> wals = GET_WALS_FUTURE.get();
76 assertSame(wal, Iterables.getOnlyElement(wals));