001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 003 * agreements. See the NOTICE file distributed with this work for additional information regarding 004 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 005 * "License"); you may not use this file except in compliance with the License. You may obtain a 006 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable 007 * law or agreed to in writing, software distributed under the License is distributed on an "AS IS" 008 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 009 * for the specific language governing permissions and limitations under the License. 010 */ 011package org.apache.hadoop.hbase.master.procedure; 012 013import java.io.IOException; 014import java.util.List; 015 016import org.apache.hadoop.hbase.HBaseClassTestRule; 017import org.apache.hadoop.hbase.HBaseTestingUtility; 018import org.apache.hadoop.hbase.TableName; 019import org.apache.hadoop.hbase.client.RegionInfo; 020import org.apache.hadoop.hbase.client.RegionReplicaUtil; 021import org.apache.hadoop.hbase.client.Table; 022import org.apache.hadoop.hbase.testclassification.LargeTests; 023import org.apache.hadoop.hbase.testclassification.MasterTests; 024import org.junit.ClassRule; 025import org.junit.experimental.categories.Category; 026import org.slf4j.Logger; 027import org.slf4j.LoggerFactory; 028 029@Category({ MasterTests.class, LargeTests.class }) 030public class TestServerCrashProcedureWithReplicas extends TestServerCrashProcedure { 031 032 @ClassRule 033 public static final HBaseClassTestRule CLASS_RULE = 034 HBaseClassTestRule.forClass(TestServerCrashProcedureWithReplicas.class); 035 private static final Logger LOG = 036 LoggerFactory.getLogger(TestServerCrashProcedureWithReplicas.class); 037 038 @Override 039 protected void startMiniCluster() throws Exception { 040 // Start a cluster with 4 nodes because we have 3 replicas. 041 // So on a crash of a server still we can ensure that the 042 // replicas are distributed. 043 this.util.startMiniCluster(4); 044 } 045 046 @Override 047 protected Table createTable(final TableName tableName) throws IOException { 048 final Table t = this.util.createTable(tableName, HBaseTestingUtility.COLUMNS, 049 HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE, 3); 050 return t; 051 } 052 053 private boolean contains(List<RegionInfo> regionInfos, RegionInfo regionInfo) { 054 for (RegionInfo info : regionInfos) { 055 if (RegionReplicaUtil.isReplicasForSameRegion(info, regionInfo)) { 056 return true; 057 } 058 } 059 return false; 060 } 061}