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
;
22 import java
.io
.IOException
;
23 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
24 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
25 import org
.apache
.hadoop
.hbase
.TableName
;
26 import org
.apache
.hadoop
.hbase
.client
.Get
;
27 import org
.apache
.hadoop
.hbase
.client
.Put
;
28 import org
.apache
.hadoop
.hbase
.client
.Table
;
29 import org
.apache
.hadoop
.hbase
.master
.HMaster
;
30 import org
.apache
.hadoop
.hbase
.master
.ServerManager
;
31 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
32 import org
.apache
.hadoop
.hbase
.testclassification
.RegionServerTests
;
33 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
34 import org
.apache
.hadoop
.hbase
.util
.JVMClusterUtil
.RegionServerThread
;
35 import org
.apache
.hadoop
.hbase
.wal
.WALFactory
;
36 import org
.junit
.AfterClass
;
37 import org
.junit
.BeforeClass
;
38 import org
.junit
.ClassRule
;
39 import org
.junit
.Test
;
40 import org
.junit
.experimental
.categories
.Category
;
43 * Testcase for HBASE-20742
45 @Category({ RegionServerTests
.class, MediumTests
.class })
46 public class TestRegionServerCrashDisableWAL
{
49 public static final HBaseClassTestRule CLASS_RULE
=
50 HBaseClassTestRule
.forClass(TestRegionServerCrashDisableWAL
.class);
52 private static final HBaseTestingUtil UTIL
= new HBaseTestingUtil();
54 private static TableName TABLE_NAME
= TableName
.valueOf("test");
56 private static byte[] CF
= Bytes
.toBytes("cf");
58 private static byte[] CQ
= Bytes
.toBytes("cq");
61 public static void setUp() throws Exception
{
62 UTIL
.getConfiguration().setInt(ServerManager
.WAIT_ON_REGIONSERVERS_MINTOSTART
, 1);
63 UTIL
.getConfiguration().setBoolean(WALFactory
.WAL_ENABLED
, false);
64 UTIL
.startMiniCluster(2);
65 UTIL
.createTable(TABLE_NAME
, CF
);
66 UTIL
.waitTableAvailable(TABLE_NAME
);
67 HRegionServer rs
= UTIL
.getRSForFirstRegionInTable(TABLE_NAME
);
68 if (!rs
.getRegions(TableName
.META_TABLE_NAME
).isEmpty()) {
69 HRegionServer rs1
= UTIL
.getOtherRegionServer(rs
);
70 UTIL
.moveRegionAndWait(
71 UTIL
.getMiniHBaseCluster().getRegions(TABLE_NAME
).get(0).getRegionInfo(),
74 UTIL
.getAdmin().balancerSwitch(false, true);
78 public static void tearDown() throws Exception
{
79 UTIL
.shutdownMiniCluster();
83 public void test() throws InterruptedException
, IOException
{
84 HMaster master
= UTIL
.getMiniHBaseCluster().stopMaster(0).getMaster();
85 // Shutdown master before shutting down rs
86 UTIL
.waitFor(30000, () -> !master
.isAlive());
87 RegionServerThread thread
= null;
88 for (RegionServerThread t
: UTIL
.getMiniHBaseCluster().getRegionServerThreads()) {
89 if (!t
.getRegionServer().getRegions(TABLE_NAME
).isEmpty()) {
95 thread
.getRegionServer().abort("For testing");
98 UTIL
.getMiniHBaseCluster().startMaster();
99 // make sure that we can schedule a SCP for the crashed server which WAL is disabled and bring
100 // the region online.
102 UTIL
.getConnection().getTableBuilder(TABLE_NAME
, null).setOperationTimeout(30000).build()) {
103 table
.put(new Put(Bytes
.toBytes(1)).addColumn(CF
, CQ
, Bytes
.toBytes(1)));
104 assertEquals(1, Bytes
.toInt(table
.get(new Get(Bytes
.toBytes(1))).getValue(CF
, CQ
)));