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