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.replication; 019 020import java.io.IOException; 021import org.apache.hadoop.hbase.HBaseClassTestRule; 022import org.apache.hadoop.hbase.HConstants; 023import org.apache.hadoop.hbase.TableName; 024import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; 025import org.apache.hadoop.hbase.client.Put; 026import org.apache.hadoop.hbase.client.Table; 027import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 028import org.apache.hadoop.hbase.testclassification.MediumTests; 029import org.apache.hadoop.hbase.testclassification.ReplicationTests; 030import org.apache.hadoop.hbase.util.Bytes; 031import org.apache.hadoop.hbase.util.CommonFSUtils.StreamLacksCapabilityException; 032import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; 033import org.junit.Before; 034import org.junit.ClassRule; 035import org.junit.Test; 036import org.junit.experimental.categories.Category; 037 038@Category({ ReplicationTests.class, MediumTests.class }) 039public class TestSerialReplicationFailover extends SerialReplicationTestBase { 040 041 @ClassRule 042 public static final HBaseClassTestRule CLASS_RULE = 043 HBaseClassTestRule.forClass(TestSerialReplicationFailover.class); 044 045 @Before 046 public void setUp() throws IOException, StreamLacksCapabilityException { 047 setupWALWriter(); 048 // add in disable state, so later when enabling it all sources will start push together. 049 addPeer(false); 050 } 051 052 @Test 053 public void testKillRS() throws Exception { 054 TableName tableName = TableName.valueOf(name.getMethodName()); 055 UTIL.getAdmin().createTable( 056 TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder 057 .newBuilder(CF).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).build()); 058 UTIL.waitTableAvailable(tableName); 059 try (Table table = UTIL.getConnection().getTable(tableName)) { 060 for (int i = 0; i < 100; i++) { 061 table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i))); 062 } 063 } 064 RegionServerThread thread = UTIL.getMiniHBaseCluster().getRegionServerThreads().stream() 065 .filter(t -> !t.getRegionServer().getRegions(tableName).isEmpty()).findFirst().get(); 066 thread.getRegionServer().abort("for testing"); 067 thread.join(); 068 try (Table table = UTIL.getConnection().getTable(tableName)) { 069 for (int i = 100; i < 200; i++) { 070 table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i))); 071 } 072 } 073 enablePeerAndWaitUntilReplicationDone(200); 074 checkOrder(200); 075 } 076}