This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new d8f71d019d7 HBASE-29189 NPE in RawAsyncTableAdmin.isTableDisabled
(#6798)
d8f71d019d7 is described below
commit d8f71d019d781063c7888f51de18827effb13516
Author: Duo Zhang <[email protected]>
AuthorDate: Sun Mar 16 22:33:58 2025 +0800
HBASE-29189 NPE in RawAsyncTableAdmin.isTableDisabled (#6798)
Signed-off-by: Nick Dimiduk <[email protected]>
---
.../hadoop/hbase/client/RawAsyncHBaseAdmin.java | 15 ++--
.../hbase/client/TestTableEnableDisableError.java | 91 ++++++++++++++++++++++
2 files changed, 96 insertions(+), 10 deletions(-)
diff --git
a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
index 24c71ccacb8..79adce33a13 100644
---
a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
+++
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
@@ -758,16 +758,13 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
* targetState).
*/
private static CompletableFuture<Boolean> completeCheckTableState(
- CompletableFuture<Boolean> future, TableState tableState, Throwable error,
+ CompletableFuture<Boolean> future, Optional<TableState> tableState,
Throwable error,
TableState.State targetState, TableName tableName) {
if (error != null) {
future.completeExceptionally(error);
} else {
- if (tableState != null) {
- future.complete(tableState.inStates(targetState));
- } else {
- future.completeExceptionally(new TableNotFoundException(tableName));
- }
+ tableState.ifPresentOrElse(t -> future.complete(t.inStates(targetState)),
+ () -> future.completeExceptionally(new
TableNotFoundException(tableName)));
}
return future;
}
@@ -780,8 +777,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
CompletableFuture<Boolean> future = new CompletableFuture<>();
addListener(ClientMetaTableAccessor.getTableState(metaTable, tableName),
(tableState, error) -> {
- completeCheckTableState(future, tableState.isPresent() ?
tableState.get() : null, error,
- TableState.State.ENABLED, tableName);
+ completeCheckTableState(future, tableState, error,
TableState.State.ENABLED, tableName);
});
return future;
}
@@ -794,8 +790,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
CompletableFuture<Boolean> future = new CompletableFuture<>();
addListener(ClientMetaTableAccessor.getTableState(metaTable, tableName),
(tableState, error) -> {
- completeCheckTableState(future, tableState.isPresent() ?
tableState.get() : null, error,
- TableState.State.DISABLED, tableName);
+ completeCheckTableState(future, tableState, error,
TableState.State.DISABLED, tableName);
});
return future;
}
diff --git
a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableEnableDisableError.java
b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableEnableDisableError.java
new file mode 100644
index 00000000000..6d5909e56a5
--- /dev/null
+++
b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableEnableDisableError.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.client;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+
+import org.apache.hadoop.hbase.ClientMetaTableAccessor;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseIOException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.testclassification.ClientTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.FutureUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.MockedStatic;
+
+@Category({ ClientTests.class, SmallTests.class })
+public class TestTableEnableDisableError {
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestTableEnableDisableError.class);
+
+ private MockedStatic<ClientMetaTableAccessor> mockedClientMetaTableAccessor;
+
+ private AsyncAdmin admin;
+
+ @Before
+ public void setUp() {
+ mockedClientMetaTableAccessor = mockStatic(ClientMetaTableAccessor.class);
+ AsyncConnectionImpl conn = mock(AsyncConnectionImpl.class);
+ AsyncAdminBuilderBase builder =
+ new AsyncAdminBuilderBase(new
AsyncConnectionConfiguration(HBaseConfiguration.create())) {
+
+ @Override
+ public AsyncAdmin build() {
+ return new RawAsyncHBaseAdmin(conn, null, this);
+ }
+ };
+ admin = builder.build();
+ }
+
+ @After
+ public void tearDown() {
+ mockedClientMetaTableAccessor.closeOnDemand();
+ }
+
+ @Test
+ public void testIsTableEnabledError() {
+ HBaseIOException expected = new HBaseIOException("expected");
+ mockedClientMetaTableAccessor.when(() ->
ClientMetaTableAccessor.getTableState(any(), any()))
+ .thenReturn(FutureUtils.failedFuture(expected));
+ HBaseIOException actual = assertThrows(HBaseIOException.class,
+ () ->
FutureUtils.get(admin.isTableEnabled(TableName.valueOf("whatever"))));
+ assertSame(expected, actual);
+ }
+
+ @Test
+ public void testIsTableDisabledError() {
+ HBaseIOException expected = new HBaseIOException("expected");
+ mockedClientMetaTableAccessor.when(() ->
ClientMetaTableAccessor.getTableState(any(), any()))
+ .thenReturn(FutureUtils.failedFuture(expected));
+ HBaseIOException actual = assertThrows(HBaseIOException.class,
+ () ->
FutureUtils.get(admin.isTableDisabled(TableName.valueOf("whatever"))));
+ assertSame(expected, actual);
+ }
+}