001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master; 019 020import java.io.IOException; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.fs.FileSystem; 023import org.apache.hadoop.fs.Path; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.HConstants; 026import org.apache.hadoop.hbase.SingleProcessHBaseCluster; 027import org.apache.hadoop.hbase.StartTestingClusterOption; 028import org.apache.hadoop.hbase.client.Mutation; 029import org.apache.hadoop.hbase.client.RegionInfo; 030import org.apache.hadoop.hbase.client.TableDescriptor; 031import org.apache.hadoop.hbase.master.region.MasterRegionFactory; 032import org.apache.hadoop.hbase.regionserver.HRegion; 033import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; 034import org.apache.hadoop.hbase.regionserver.OperationStatus; 035import org.apache.hadoop.hbase.regionserver.RegionServerServices; 036import org.apache.hadoop.hbase.testclassification.LargeTests; 037import org.apache.hadoop.hbase.testclassification.MasterTests; 038import org.apache.hadoop.hbase.wal.WAL; 039import org.junit.AfterClass; 040import org.junit.Before; 041import org.junit.BeforeClass; 042import org.junit.ClassRule; 043import org.junit.Test; 044import org.junit.experimental.categories.Category; 045 046/** 047 * MasterRegion related test that ensures the operations continue even when Procedure state update 048 * encounters non-retriable IO errors. 049 */ 050@Category({ MasterTests.class, LargeTests.class }) 051public class TestMasterRegionMutation2 extends TestMasterRegionMutation1 { 052 053 @ClassRule 054 public static final HBaseClassTestRule CLASS_RULE = 055 HBaseClassTestRule.forClass(TestMasterRegionMutation2.class); 056 057 @BeforeClass 058 public static void setUpBeforeClass() throws Exception { 059 TEST_UTIL.getConfiguration().setClass(HConstants.REGION_IMPL, TestRegion.class, HRegion.class); 060 StartTestingClusterOption.Builder builder = StartTestingClusterOption.builder(); 061 // 2 masters are expected to be aborted with this test 062 builder.numMasters(3).numRegionServers(3); 063 TEST_UTIL.startMiniCluster(builder.build()); 064 SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); 065 rs0 = cluster.getRegionServer(0).getServerName(); 066 TEST_UTIL.getAdmin().balancerSwitch(false, true); 067 } 068 069 @AfterClass 070 public static void tearDownAfterClass() throws Exception { 071 TEST_UTIL.shutdownMiniCluster(); 072 } 073 074 @Before 075 public void setUp() throws Exception { 076 super.setUp(); 077 } 078 079 @Test 080 public void testMasterRegionMutations() throws Exception { 081 super.testMasterRegionMutations(); 082 } 083 084 public static class TestRegion extends HRegion { 085 086 public TestRegion(Path tableDir, WAL wal, FileSystem fs, Configuration confParam, 087 RegionInfo regionInfo, TableDescriptor htd, RegionServerServices rsServices) { 088 super(tableDir, wal, fs, confParam, regionInfo, htd, rsServices); 089 } 090 091 public TestRegion(HRegionFileSystem fs, WAL wal, Configuration confParam, TableDescriptor htd, 092 RegionServerServices rsServices) { 093 super(fs, wal, confParam, htd, rsServices); 094 } 095 096 @Override 097 public OperationStatus[] batchMutate(Mutation[] mutations, boolean atomic, long nonceGroup, 098 long nonce) throws IOException { 099 if ( 100 MasterRegionFactory.TABLE_NAME.equals(getTableDescriptor().getTableName()) 101 && ERROR_OUT.get() 102 ) { 103 ERROR_OUT.set(false); 104 throw new IOException("test error"); 105 } 106 return super.batchMutate(mutations, atomic, nonceGroup, nonce); 107 } 108 } 109 110}