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.assertThrows; 021 022import java.io.IOException; 023import java.util.concurrent.CompletableFuture; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.DoNotRetryIOException; 026import org.apache.hadoop.hbase.HBaseConfiguration; 027import org.apache.hadoop.hbase.RegionLocations; 028import org.apache.hadoop.hbase.security.User; 029import org.apache.hadoop.hbase.security.UserProvider; 030import org.apache.hadoop.hbase.testclassification.ClientTests; 031import org.apache.hadoop.hbase.testclassification.SmallTests; 032import org.apache.hadoop.hbase.util.FutureUtils; 033import org.junit.jupiter.api.BeforeAll; 034import org.junit.jupiter.api.Tag; 035import org.junit.jupiter.api.Test; 036 037@Tag(ClientTests.TAG) 038@Tag(SmallTests.TAG) 039public class TestAsyncMetaRegionLocatorFailFast { 040 041 private static Configuration CONF = HBaseConfiguration.create(); 042 043 private static AsyncMetaRegionLocator LOCATOR; 044 045 private static final class FaultyConnectionRegistry extends DoNothingConnectionRegistry { 046 047 public FaultyConnectionRegistry(Configuration conf, User user) { 048 super(conf, user); 049 } 050 051 @Override 052 public CompletableFuture<RegionLocations> getMetaRegionLocations() { 053 return FutureUtils.failedFuture(new DoNotRetryRegionException("inject error")); 054 } 055 } 056 057 @BeforeAll 058 public static void setUp() throws IOException { 059 LOCATOR = new AsyncMetaRegionLocator( 060 new FaultyConnectionRegistry(CONF, UserProvider.instantiate(CONF).getCurrent())); 061 } 062 063 @Test 064 public void test() throws IOException { 065 assertThrows(DoNotRetryIOException.class, 066 () -> FutureUtils.get(LOCATOR.getRegionLocations(RegionInfo.DEFAULT_REPLICA_ID, false))); 067 } 068}