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.client; 019 020import static org.junit.jupiter.api.Assertions.assertNotEquals; 021 022import java.io.IOException; 023import java.util.concurrent.ExecutionException; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.HBaseTestingUtil; 026import org.apache.hadoop.hbase.HConstants; 027import org.apache.hadoop.hbase.ServerName; 028import org.apache.hadoop.hbase.TableName; 029import org.apache.hadoop.hbase.testclassification.ClientTests; 030import org.apache.hadoop.hbase.testclassification.LargeTests; 031import org.apache.hadoop.hbase.util.Bytes; 032import org.junit.jupiter.api.AfterAll; 033import org.junit.jupiter.api.BeforeAll; 034import org.junit.jupiter.api.Tag; 035import org.junit.jupiter.api.Test; 036 037// Categorized as a large test so not run as part of general 'test' suite (which is small 038// and mediums). This test fails if networking is odd -- say if you are connected to a 039// VPN... See HBASE-23850 040@Tag(LargeTests.TAG) 041@Tag(ClientTests.TAG) 042public class TestAsyncTableRSCrashPublish { 043 044 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 045 046 private static TableName TABLE_NAME = TableName.valueOf("Publish"); 047 048 private static byte[] FAMILY = Bytes.toBytes("family"); 049 050 @BeforeAll 051 public static void beforeClass() throws Exception { 052 UTIL.getConfiguration().setBoolean(HConstants.STATUS_PUBLISHED, true); 053 /* 054 * Below is code for choosing a NetworkInterface and then setting it into configs so can be 055 * picked up by the client and server. String niName = 056 * UTIL.getConfiguration().get(HConstants.STATUS_MULTICAST_NI_NAME); NetworkInterface ni; if 057 * (niName != null) { ni = NetworkInterface.getByName(niName); } else { String mcAddress = 058 * UTIL.getConfiguration().get(HConstants.STATUS_MULTICAST_ADDRESS, 059 * HConstants.DEFAULT_STATUS_MULTICAST_ADDRESS); InetAddress ina = 060 * InetAddress.getByName(mcAddress); boolean inet6Address = ina instanceof Inet6Address; ni = 061 * NetworkInterface.getByInetAddress(inet6Address? Addressing.getIp6Address(): 062 * Addressing.getIp4Address()); } 063 * UTIL.getConfiguration().set(HConstants.STATUS_MULTICAST_NI_NAME, ni.getName()); 064 */ 065 UTIL.startMiniCluster(2); 066 UTIL.createTable(TABLE_NAME, FAMILY); 067 UTIL.waitTableAvailable(TABLE_NAME); 068 } 069 070 @AfterAll 071 public static void afterClass() throws Exception { 072 UTIL.shutdownMiniCluster(); 073 } 074 075 @Test 076 public void test() throws IOException, ExecutionException, InterruptedException { 077 Configuration conf = UTIL.getHBaseCluster().getMaster().getConfiguration(); 078 try (AsyncConnection connection = ConnectionFactory.createAsyncConnection(conf).get()) { 079 AsyncNonMetaRegionLocator locator = 080 ((AsyncConnectionImpl) connection).getLocator().getNonMetaRegionLocator(); 081 connection.getTable(TABLE_NAME).get(new Get(Bytes.toBytes(0))).join(); 082 ServerName serverName = 083 locator.getRegionLocationInCache(TABLE_NAME, HConstants.EMPTY_START_ROW) 084 .getDefaultRegionLocation().getServerName(); 085 UTIL.getMiniHBaseCluster().stopRegionServer(serverName); 086 UTIL.waitFor(60000, 087 () -> locator.getRegionLocationInCache(TABLE_NAME, HConstants.EMPTY_START_ROW) == null); 088 connection.getTable(TABLE_NAME).get(new Get(Bytes.toBytes(0))).join(); 089 assertNotEquals(serverName, 090 locator.getRegionLocationInCache(TABLE_NAME, HConstants.EMPTY_START_ROW) 091 .getDefaultRegionLocation().getServerName()); 092 } 093 } 094}