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
;
42 * Testcase for HBASE-21503.
44 @Category({ RegionServerTests
.class, SmallTests
.class })
45 public class TestRaceBetweenGetWALAndGetWALs
{
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
<?
>> {
56 protected AbstractFSWAL
<?
> createWAL() throws IOException
{
57 // just like what may do in the WALListeners, schedule an asynchronous task to call the
59 GET_WALS_FUTURE
= ForkJoinPool
.commonPool().submit(this::getWALs
);
60 // sleep a while to make the getWALs arrive before we return
62 return Mockito
.mock(AbstractFSWAL
.class);
66 protected void doInit(Configuration conf
) throws IOException
{
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
));