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.Assert.assertSame; 021import static org.junit.Assert.assertThrows; 022import static org.mockito.ArgumentMatchers.any; 023import static org.mockito.Mockito.mock; 024import static org.mockito.Mockito.mockStatic; 025 026import org.apache.hadoop.hbase.ClientMetaTableAccessor; 027import org.apache.hadoop.hbase.HBaseClassTestRule; 028import org.apache.hadoop.hbase.HBaseConfiguration; 029import org.apache.hadoop.hbase.HBaseIOException; 030import org.apache.hadoop.hbase.TableName; 031import org.apache.hadoop.hbase.testclassification.ClientTests; 032import org.apache.hadoop.hbase.testclassification.SmallTests; 033import org.apache.hadoop.hbase.util.FutureUtils; 034import org.junit.After; 035import org.junit.Before; 036import org.junit.ClassRule; 037import org.junit.Test; 038import org.junit.experimental.categories.Category; 039import org.mockito.MockedStatic; 040 041@Category({ ClientTests.class, SmallTests.class }) 042public class TestTableEnableDisableError { 043 044 @ClassRule 045 public static final HBaseClassTestRule CLASS_RULE = 046 HBaseClassTestRule.forClass(TestTableEnableDisableError.class); 047 048 private MockedStatic<ClientMetaTableAccessor> mockedClientMetaTableAccessor; 049 050 private AsyncAdmin admin; 051 052 @Before 053 public void setUp() { 054 mockedClientMetaTableAccessor = mockStatic(ClientMetaTableAccessor.class); 055 AsyncConnectionImpl conn = mock(AsyncConnectionImpl.class); 056 AsyncAdminBuilderBase builder = 057 new AsyncAdminBuilderBase(new AsyncConnectionConfiguration(HBaseConfiguration.create())) { 058 059 @Override 060 public AsyncAdmin build() { 061 return new RawAsyncHBaseAdmin(conn, null, this); 062 } 063 }; 064 admin = builder.build(); 065 } 066 067 @After 068 public void tearDown() { 069 mockedClientMetaTableAccessor.closeOnDemand(); 070 } 071 072 @Test 073 public void testIsTableEnabledError() { 074 HBaseIOException expected = new HBaseIOException("expected"); 075 mockedClientMetaTableAccessor.when(() -> ClientMetaTableAccessor.getTableState(any(), any())) 076 .thenReturn(FutureUtils.failedFuture(expected)); 077 HBaseIOException actual = assertThrows(HBaseIOException.class, 078 () -> FutureUtils.get(admin.isTableEnabled(TableName.valueOf("whatever")))); 079 assertSame(expected, actual); 080 } 081 082 @Test 083 public void testIsTableDisabledError() { 084 HBaseIOException expected = new HBaseIOException("expected"); 085 mockedClientMetaTableAccessor.when(() -> ClientMetaTableAccessor.getTableState(any(), any())) 086 .thenReturn(FutureUtils.failedFuture(expected)); 087 HBaseIOException actual = assertThrows(HBaseIOException.class, 088 () -> FutureUtils.get(admin.isTableDisabled(TableName.valueOf("whatever")))); 089 assertSame(expected, actual); 090 } 091}