diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/WriteAttemptedOnReadOnlyClusterException.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/WriteAttemptedOnReadOnlyClusterException.java new file mode 100644 index 000000000000..6cfe55f1028a --- /dev/null +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/WriteAttemptedOnReadOnlyClusterException.java @@ -0,0 +1,55 @@ +/* + * 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; + +import org.apache.yetus.audience.InterfaceAudience; + +/** + * Thrown when a write is attempted on a read-only HBase cluster. + */ +@InterfaceAudience.Public +public class WriteAttemptedOnReadOnlyClusterException extends DoNotRetryIOException { + + private static final long serialVersionUID = 1L; + + public WriteAttemptedOnReadOnlyClusterException() { + super(); + } + + /** + * @param message the message for this exception + */ + public WriteAttemptedOnReadOnlyClusterException(String message) { + super(message); + } + + /** + * @param message the message for this exception + * @param throwable the {@link Throwable} to use for this exception + */ + public WriteAttemptedOnReadOnlyClusterException(String message, Throwable throwable) { + super(message, throwable); + } + + /** + * @param throwable the {@link Throwable} to use for this exception + */ + public WriteAttemptedOnReadOnlyClusterException(Throwable throwable) { + super(throwable); + } +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AbstractReadOnlyController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AbstractReadOnlyController.java index c82f0b10aa11..d13c84779196 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AbstractReadOnlyController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AbstractReadOnlyController.java @@ -26,10 +26,10 @@ import org.apache.hadoop.hbase.ActiveClusterSuffix; import org.apache.hadoop.hbase.Coprocessor; import org.apache.hadoop.hbase.CoprocessorEnvironment; -import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; import org.apache.hadoop.hbase.exceptions.DeserializationException; @@ -56,8 +56,8 @@ public static boolean isWritableInReadOnlyMode(final TableName tableName) { return writableTables.contains(tableName); } - protected void internalReadOnlyGuard() throws DoNotRetryIOException { - throw new DoNotRetryIOException("Operation not allowed in Read-Only Mode"); + protected void internalReadOnlyGuard() throws WriteAttemptedOnReadOnlyClusterException { + throw new WriteAttemptedOnReadOnlyClusterException("Operation not allowed in Read-Only Mode"); } @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerBulkLoadObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerBulkLoadObserver.java index 9ac008fdaf8e..b7b2cf2af333 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerBulkLoadObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerBulkLoadObserver.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.security.access; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; -import java.io.IOException; -import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; import org.apache.hadoop.hbase.testclassification.SecurityTests; @@ -58,13 +58,17 @@ public void tearDown() throws Exception { } - @Test(expected = DoNotRetryIOException.class) - public void testPrePrepareBulkLoadReadOnlyException() throws IOException { - bulkLoadReadOnlyController.prePrepareBulkLoad(ctx); + @Test + public void testPrePrepareBulkLoadReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + bulkLoadReadOnlyController.prePrepareBulkLoad(ctx); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCleanupBulkLoadReadOnlyException() throws IOException { - bulkLoadReadOnlyController.preCleanupBulkLoad(ctx); + @Test + public void testPreCleanupBulkLoadReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + bulkLoadReadOnlyController.preCleanupBulkLoad(ctx); + }); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerEndpointObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerEndpointObserver.java index 460d1fd2aae5..337ab2bcecba 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerEndpointObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerEndpointObserver.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.security.access; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; -import java.io.IOException; -import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; import org.apache.hadoop.hbase.testclassification.SecurityTests; @@ -68,8 +68,10 @@ public void tearDown() throws Exception { } - @Test(expected = DoNotRetryIOException.class) - public void testPreEndpointInvocationReadOnlyException() throws IOException { - endpointReadOnlyController.preEndpointInvocation(ctx, service, methodName, request); + @Test + public void testPreEndpointInvocationReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + endpointReadOnlyController.preEndpointInvocation(ctx, service, methodName, request); + }); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerMasterObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerMasterObserver.java index 215edb493177..f6f68074b8e0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerMasterObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerMasterObserver.java @@ -17,16 +17,16 @@ */ package org.apache.hadoop.hbase.security.access; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; -import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException; import org.apache.hadoop.hbase.client.BalanceRequest; import org.apache.hadoop.hbase.client.Mutation; import org.apache.hadoop.hbase.client.RegionInfo; @@ -145,249 +145,348 @@ public void tearDown() throws Exception { } - @Test(expected = DoNotRetryIOException.class) - public void testPreCreateTableRegionsInfosReadOnlyException() throws IOException { - MasterReadOnlyController.preCreateTableRegionsInfos(ctx, desc); + @Test + public void testPreCreateTableRegionsInfosReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preCreateTableRegionsInfos(ctx, desc); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCreateTableReadOnlyException() throws IOException { - MasterReadOnlyController.preCreateTable(ctx, desc, regions); + @Test + public void testPreCreateTableReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preCreateTable(ctx, desc, regions); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCreateTableActionReadOnlyException() throws IOException { - MasterReadOnlyController.preCreateTableAction(ctx, desc, regions); + @Test + public void testPreCreateTableActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preCreateTableAction(ctx, desc, regions); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreDeleteTableReadOnlyException() throws IOException { - MasterReadOnlyController.preDeleteTable(ctx, tableName); + @Test + public void testPreDeleteTableReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preDeleteTable(ctx, tableName); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreDeleteTableActionReadOnlyException() throws IOException { - MasterReadOnlyController.preDeleteTableAction(ctx, tableName); + @Test + public void testPreDeleteTableActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preDeleteTableAction(ctx, tableName); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreTruncateTableReadOnlyException() throws IOException { - MasterReadOnlyController.preTruncateTable(ctx, tableName); + @Test + public void testPreTruncateTableReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preTruncateTable(ctx, tableName); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreTruncateTableActionReadOnlyException() throws IOException { - MasterReadOnlyController.preTruncateTableAction(ctx, tableName); + @Test + public void testPreTruncateTableActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preTruncateTableAction(ctx, tableName); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreModifyTableReadOnlyException() throws IOException { - MasterReadOnlyController.preModifyTable(ctx, tableName, currentDescriptor, newDescriptor); + @Test + public void testPreModifyTableReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preModifyTable(ctx, tableName, currentDescriptor, newDescriptor); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreModifyTableStoreFileTrackerReadOnlyException() throws IOException { - MasterReadOnlyController.preModifyTableStoreFileTracker(ctx, tableName, dstSFT); + @Test + public void testPreModifyTableStoreFileTrackerReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preModifyTableStoreFileTracker(ctx, tableName, dstSFT); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreModifyColumnFamilyStoreFileTrackerReadOnlyException() throws IOException { - MasterReadOnlyController.preModifyColumnFamilyStoreFileTracker(ctx, tableName, family, dstSFT); + @Test + public void testPreModifyColumnFamilyStoreFileTrackerReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preModifyColumnFamilyStoreFileTracker(ctx, tableName, family, + dstSFT); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreModifyTableActionReadOnlyException() throws IOException { - MasterReadOnlyController.preModifyTableAction(ctx, tableName, currentDescriptor, newDescriptor); + @Test + public void testPreModifyTableActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preModifyTableAction(ctx, tableName, currentDescriptor, + newDescriptor); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSplitRegionReadOnlyException() throws IOException { - MasterReadOnlyController.preSplitRegion(c, tableName, splitRow); + @Test + public void testPreSplitRegionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSplitRegion(c, tableName, splitRow); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSplitRegionActionReadOnlyException() throws IOException { - MasterReadOnlyController.preSplitRegionAction(c, tableName, splitRow); + @Test + public void testPreSplitRegionActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSplitRegionAction(c, tableName, splitRow); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSplitRegionBeforeMETAActionReadOnlyException() throws IOException { - MasterReadOnlyController.preSplitRegionBeforeMETAAction(ctx, splitKey, metaEntries); + @Test + public void testPreSplitRegionBeforeMETAActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSplitRegionBeforeMETAAction(ctx, splitKey, metaEntries); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSplitRegionAfterMETAActionReadOnlyException() throws IOException { - MasterReadOnlyController.preSplitRegionAfterMETAAction(ctx); + @Test + public void testPreSplitRegionAfterMETAActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSplitRegionAfterMETAAction(ctx); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMergeRegionsActionReadOnlyException() throws IOException { - MasterReadOnlyController.preMergeRegionsAction(ctx, regionsToMerge); + @Test + public void testPreMergeRegionsActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preMergeRegionsAction(ctx, regionsToMerge); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMergeRegionsCommitActionReadOnlyException() throws IOException { - MasterReadOnlyController.preMergeRegionsCommitAction(ctx, regionsToMerge, metaEntries); + @Test + public void testPreMergeRegionsCommitActionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preMergeRegionsCommitAction(ctx, regionsToMerge, metaEntries); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSnapshotReadOnlyException() throws IOException { - MasterReadOnlyController.preSnapshot(ctx, snapshot, tableDescriptor); + @Test + public void testPreSnapshotReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSnapshot(ctx, snapshot, tableDescriptor); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCloneSnapshotReadOnlyException() throws IOException { - MasterReadOnlyController.preCloneSnapshot(ctx, snapshot, tableDescriptor); + @Test + public void testPreCloneSnapshotReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preCloneSnapshot(ctx, snapshot, tableDescriptor); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreRestoreSnapshotReadOnlyException() throws IOException { - MasterReadOnlyController.preRestoreSnapshot(ctx, snapshot, tableDescriptor); + @Test + public void testPreRestoreSnapshotReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preRestoreSnapshot(ctx, snapshot, tableDescriptor); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreDeleteSnapshotReadOnlyException() throws IOException { - MasterReadOnlyController.preDeleteSnapshot(ctx, snapshot); + @Test + public void testPreDeleteSnapshotReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preDeleteSnapshot(ctx, snapshot); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCreateNamespaceReadOnlyException() throws IOException { - MasterReadOnlyController.preCreateNamespace(ctx, ns); + @Test + public void testPreCreateNamespaceReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preCreateNamespace(ctx, ns); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreModifyNamespaceReadOnlyException() throws IOException { - MasterReadOnlyController.preModifyNamespace(ctx, currentNsDescriptor, newNsDescriptor); + @Test + public void testPreModifyNamespaceReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preModifyNamespace(ctx, currentNsDescriptor, newNsDescriptor); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreDeleteNamespaceReadOnlyException() throws IOException { - MasterReadOnlyController.preDeleteNamespace(ctx, namespace); + @Test + public void testPreDeleteNamespaceReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preDeleteNamespace(ctx, namespace); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMasterStoreFlushReadOnlyException() throws IOException { - MasterReadOnlyController.preMasterStoreFlush(ctx); + @Test + public void testPreMasterStoreFlushReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preMasterStoreFlush(ctx); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSetUserQuotaReadOnlyException() throws IOException { - MasterReadOnlyController.preSetUserQuota(ctx, userName, quotas); + @Test + public void testPreSetUserQuotaReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSetUserQuota(ctx, userName, quotas); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSetUserQuotaOnTableReadOnlyException() throws IOException { - MasterReadOnlyController.preSetUserQuota(ctx, userName, tableName, quotas); + @Test + public void testPreSetUserQuotaOnTableReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSetUserQuota(ctx, userName, tableName, quotas); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSetUserQuotaOnNamespaceReadOnlyException() throws IOException { - MasterReadOnlyController.preSetUserQuota(ctx, userName, namespace, quotas); + @Test + public void testPreSetUserQuotaOnNamespaceReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSetUserQuota(ctx, userName, namespace, quotas); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSetTableQuotaReadOnlyException() throws IOException { - MasterReadOnlyController.preSetTableQuota(ctx, tableName, quotas); + @Test + public void testPreSetTableQuotaReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSetTableQuota(ctx, tableName, quotas); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSetNamespaceQuotaReadOnlyException() throws IOException { - MasterReadOnlyController.preSetNamespaceQuota(ctx, namespace, quotas); + @Test + public void testPreSetNamespaceQuotaReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSetNamespaceQuota(ctx, namespace, quotas); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreSetRegionServerQuotaReadOnlyException() throws IOException { - MasterReadOnlyController.preSetRegionServerQuota(ctx, regionServer, quotas); + @Test + public void testPreSetRegionServerQuotaReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preSetRegionServerQuota(ctx, regionServer, quotas); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMergeRegionsReadOnlyException() throws IOException { - MasterReadOnlyController.preMergeRegions(ctx, regionsToMerge); + @Test + public void testPreMergeRegionsReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preMergeRegions(ctx, regionsToMerge); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMoveServersAndTablesReadOnlyException() throws IOException { - MasterReadOnlyController.preMoveServersAndTables(ctx, servers, tables, targetGroup); + @Test + public void testPreMoveServersAndTablesReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preMoveServersAndTables(ctx, servers, tables, targetGroup); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMoveServersReadOnlyException() throws IOException { - MasterReadOnlyController.preMoveServers(ctx, servers, targetGroup); + @Test + public void testPreMoveServersReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preMoveServers(ctx, servers, targetGroup); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMoveTablesReadOnlyException() throws IOException { - MasterReadOnlyController.preMoveTables(ctx, tables, targetGroup); + @Test + public void testPreMoveTablesReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preMoveTables(ctx, tables, targetGroup); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreAddRSGroupReadOnlyException() throws IOException { - MasterReadOnlyController.preAddRSGroup(ctx, name); + @Test + public void testPreAddRSGroupReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preAddRSGroup(ctx, name); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreRemoveRSGroupReadOnlyException() throws IOException { - MasterReadOnlyController.preRemoveRSGroup(ctx, name); + @Test + public void testPreRemoveRSGroupReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preRemoveRSGroup(ctx, name); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreBalanceRSGroupReadOnlyException() throws IOException { - MasterReadOnlyController.preBalanceRSGroup(ctx, groupName, request); + @Test + public void testPreBalanceRSGroupReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preBalanceRSGroup(ctx, groupName, request); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreRemoveServersReadOnlyException() throws IOException { - MasterReadOnlyController.preRemoveServers(ctx, servers); + @Test + public void testPreRemoveServersReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preRemoveServers(ctx, servers); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreRenameRSGroupReadOnlyException() throws IOException { - MasterReadOnlyController.preRenameRSGroup(ctx, oldName, newName); + @Test + public void testPreRenameRSGroupReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preRenameRSGroup(ctx, oldName, newName); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreUpdateRSGroupConfigReadOnlyException() throws IOException { - MasterReadOnlyController.preUpdateRSGroupConfig(ctx, groupName, configuration); + @Test + public void testPreUpdateRSGroupConfigReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preUpdateRSGroupConfig(ctx, groupName, configuration); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreAddReplicationPeerReadOnlyException() throws IOException { - MasterReadOnlyController.preAddReplicationPeer(ctx, peerId, peerConfig); + @Test + public void testPreAddReplicationPeerReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preAddReplicationPeer(ctx, peerId, peerConfig); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreRemoveReplicationPeerReadOnlyException() throws IOException { - MasterReadOnlyController.preRemoveReplicationPeer(ctx, peerId); + @Test + public void testPreRemoveReplicationPeerReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preRemoveReplicationPeer(ctx, peerId); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreEnableReplicationPeerReadOnlyException() throws IOException { - MasterReadOnlyController.preEnableReplicationPeer(ctx, peerId); + @Test + public void testPreEnableReplicationPeerReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preEnableReplicationPeer(ctx, peerId); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreDisableReplicationPeerReadOnlyException() throws IOException { - MasterReadOnlyController.preDisableReplicationPeer(ctx, peerId); + @Test + public void testPreDisableReplicationPeerReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preDisableReplicationPeer(ctx, peerId); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreUpdateReplicationPeerConfigReadOnlyException() throws IOException { - MasterReadOnlyController.preUpdateReplicationPeerConfig(ctx, peerId, peerConfig); + @Test + public void testPreUpdateReplicationPeerConfigReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preUpdateReplicationPeerConfig(ctx, peerId, peerConfig); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreTransitReplicationPeerSyncReplicationStateReadOnlyException() - throws IOException { - MasterReadOnlyController.preTransitReplicationPeerSyncReplicationState(ctx, peerId, state); + @Test + public void testPreTransitReplicationPeerSyncReplicationStateReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preTransitReplicationPeerSyncReplicationState(ctx, peerId, state); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreGrantReadOnlyException() throws IOException { - MasterReadOnlyController.preGrant(ctx, userPermission, mergeExistingPermissions); + @Test + public void testPreGrantReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preGrant(ctx, userPermission, mergeExistingPermissions); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreRevokeReadOnlyException() throws IOException { - MasterReadOnlyController.preRevoke(ctx, userPermission); + @Test + public void testPreRevokeReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + MasterReadOnlyController.preRevoke(ctx, userPermission); + }); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionObserver.java index f56a88399531..c4a05454db8f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionObserver.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.hbase.security.access; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -24,9 +25,9 @@ import java.util.List; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.CompareOperator; -import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException; import org.apache.hadoop.hbase.client.Append; import org.apache.hadoop.hbase.client.CheckAndMutate; import org.apache.hadoop.hbase.client.CheckAndMutateResult; @@ -180,9 +181,11 @@ private void mockOperationMasterStoreTable() { when(regionInfo.getTable()).thenReturn(MasterRegionFactory.TABLE_NAME); } - @Test(expected = DoNotRetryIOException.class) - public void testPreFlushV1ReadOnlyException() throws IOException { - regionReadOnlyController.preFlush(c, flushLifeCycleTracker); + @Test + public void testPreFlushV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preFlush(c, flushLifeCycleTracker); + }); } @Test @@ -197,9 +200,11 @@ public void testPreFlushV1ReadOnlyMasterStoreNoException() throws IOException { regionReadOnlyController.preFlush(c, flushLifeCycleTracker); } - @Test(expected = DoNotRetryIOException.class) - public void testPreFlushV2ReadOnlyException() throws IOException { - regionReadOnlyController.preFlush(c, store, scanner, flushLifeCycleTracker); + @Test + public void testPreFlushV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preFlush(c, store, scanner, flushLifeCycleTracker); + }); } @Test @@ -214,9 +219,11 @@ public void testPreFlushV2ReadOnlyMasterStoreNoException() throws IOException { regionReadOnlyController.preFlush(c, store, scanner, flushLifeCycleTracker); } - @Test(expected = DoNotRetryIOException.class) - public void testPreFlushScannerOpenReadOnlyException() throws IOException { - regionReadOnlyController.preFlushScannerOpen(c, store, options, flushLifeCycleTracker); + @Test + public void testPreFlushScannerOpenReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preFlushScannerOpen(c, store, options, flushLifeCycleTracker); + }); } @Test @@ -231,24 +238,33 @@ public void testPreFlushScannerOpenReadOnlyMasterStoreNoException() throws IOExc regionReadOnlyController.preFlushScannerOpen(c, store, options, flushLifeCycleTracker); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMemStoreCompactionReadOnlyException() throws IOException { - regionReadOnlyController.preMemStoreCompaction(c, store); + @Test + public void testPreMemStoreCompactionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preMemStoreCompaction(c, store); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMemStoreCompactionCompactScannerOpenReadOnlyException() throws IOException { - regionReadOnlyController.preMemStoreCompactionCompactScannerOpen(c, store, options); + @Test + public void testPreMemStoreCompactionCompactScannerOpenReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preMemStoreCompactionCompactScannerOpen(c, store, options); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreMemStoreCompactionCompactReadOnlyException() throws IOException { - regionReadOnlyController.preMemStoreCompactionCompact(c, store, scanner); + @Test + public void testPreMemStoreCompactionCompactReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preMemStoreCompactionCompact(c, store, scanner); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCompactSelectionReadOnlyException() throws IOException { - regionReadOnlyController.preCompactSelection(c, store, candidates, compactionLifeCycleTracker); + @Test + public void testPreCompactSelectionReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCompactSelection(c, store, candidates, + compactionLifeCycleTracker); + }); } @Test @@ -263,10 +279,12 @@ public void testPreCompactSelectionReadOnlyMasterStoreNoException() throws IOExc regionReadOnlyController.preCompactSelection(c, store, candidates, compactionLifeCycleTracker); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCompactScannerOpenReadOnlyException() throws IOException { - regionReadOnlyController.preCompactScannerOpen(c, store, scanType, options, - compactionLifeCycleTracker, compactionRequest); + @Test + public void testPreCompactScannerOpenReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCompactScannerOpen(c, store, scanType, options, + compactionLifeCycleTracker, compactionRequest); + }); } @Test @@ -283,10 +301,12 @@ public void testPreCompactScannerOpenReadOnlyMasterStoreNoException() throws IOE compactionLifeCycleTracker, compactionRequest); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCompactReadOnlyException() throws IOException { - regionReadOnlyController.preCompact(c, store, scanner, scanType, compactionLifeCycleTracker, - compactionRequest); + @Test + public void testPreCompactReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCompact(c, store, scanner, scanType, compactionLifeCycleTracker, + compactionRequest); + }); } @Test @@ -303,9 +323,11 @@ public void testPreCompactReadOnlyMasterStoreNoException() throws IOException { compactionRequest); } - @Test(expected = DoNotRetryIOException.class) - public void testPrePutV1ReadOnlyException() throws IOException { - regionReadOnlyController.prePut(c, put, edit); + @Test + public void testPrePutV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.prePut(c, put, edit); + }); } @Test @@ -320,9 +342,11 @@ public void testPrePutV1ReadOnlyMasterStoreNoException() throws IOException { regionReadOnlyController.prePut(c, put, edit); } - @Test(expected = DoNotRetryIOException.class) - public void testPrePutV2ReadOnlyException() throws IOException { - regionReadOnlyController.prePut(c, put, edit, durability); + @Test + public void testPrePutV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.prePut(c, put, edit, durability); + }); } @Test @@ -337,9 +361,11 @@ public void testPrePutV2ReadOnlyMasterStoreNoException() throws IOException { regionReadOnlyController.prePut(c, put, edit, durability); } - @Test(expected = DoNotRetryIOException.class) - public void testPreDeleteV1ReadOnlyException() throws IOException { - regionReadOnlyController.preDelete(c, delete, edit); + @Test + public void testPreDeleteV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preDelete(c, delete, edit); + }); } @Test @@ -354,9 +380,11 @@ public void testPreDeleteV1ReadOnlyMasterStoreNoException() throws IOException { regionReadOnlyController.preDelete(c, delete, edit); } - @Test(expected = DoNotRetryIOException.class) - public void testPreDeleteV2ReadOnlyException() throws IOException { - regionReadOnlyController.preDelete(c, delete, edit, durability); + @Test + public void testPreDeleteV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preDelete(c, delete, edit, durability); + }); } @Test @@ -371,9 +399,11 @@ public void testPreDeleteV2ReadOnlyMasterStoreNoException() throws IOException { regionReadOnlyController.preDelete(c, delete, edit, durability); } - @Test(expected = DoNotRetryIOException.class) - public void testPreBatchMutateReadOnlyException() throws IOException { - regionReadOnlyController.preBatchMutate(c, miniBatchOp); + @Test + public void testPreBatchMutateReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preBatchMutate(c, miniBatchOp); + }); } @Test @@ -388,9 +418,12 @@ public void testPreBatchMutateReadOnlyMasterStoreNoException() throws IOExceptio regionReadOnlyController.preBatchMutate(c, miniBatchOp); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndPutV1ReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndPut(c, row, family, qualifier, op, comparator, put, result); + @Test + public void testPreCheckAndPutV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndPut(c, row, family, qualifier, op, comparator, put, + result); + }); } @Test @@ -405,9 +438,11 @@ public void testPreCheckAndPutV1ReadOnlyMasterStoreNoException() throws IOExcept regionReadOnlyController.preCheckAndPut(c, row, family, qualifier, op, comparator, put, result); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndPutV2ReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndPut(c, row, filter, put, result); + @Test + public void testPreCheckAndPutV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndPut(c, row, filter, put, result); + }); } @Test @@ -422,10 +457,12 @@ public void testPreCheckAndPutV2ReadOnlyMasterStoreNoException() throws IOExcept regionReadOnlyController.preCheckAndPut(c, row, filter, put, result); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndPutAfterRowLockV1ReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndPutAfterRowLock(c, row, family, qualifier, op, comparator, - put, result); + @Test + public void testPreCheckAndPutAfterRowLockV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndPutAfterRowLock(c, row, family, qualifier, op, comparator, + put, result); + }); } @Test @@ -442,9 +479,11 @@ public void testPreCheckAndPutAfterRowLockV1ReadOnlyMasterStoreNoException() thr put, result); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndPutAfterRowLockV2ReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndPutAfterRowLock(c, row, filter, put, result); + @Test + public void testPreCheckAndPutAfterRowLockV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndPutAfterRowLock(c, row, filter, put, result); + }); } @Test @@ -459,10 +498,12 @@ public void testPreCheckAndPutAfterRowLockV2ReadOnlyMasterStoreNoException() thr regionReadOnlyController.preCheckAndPutAfterRowLock(c, row, filter, put, result); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndDeleteV1ReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndDelete(c, row, family, qualifier, op, comparator, delete, - result); + @Test + public void testPreCheckAndDeleteV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndDelete(c, row, family, qualifier, op, comparator, delete, + result); + }); } @Test @@ -479,9 +520,11 @@ public void testPreCheckAndDeleteV1ReadOnlyMasterStoreNoException() throws IOExc result); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndDeleteV2ReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndDelete(c, row, filter, delete, result); + @Test + public void testPreCheckAndDeleteV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndDelete(c, row, filter, delete, result); + }); } @Test @@ -496,10 +539,12 @@ public void testPreCheckAndDeleteV2ReadOnlyMasterStoreNoException() throws IOExc regionReadOnlyController.preCheckAndDelete(c, row, filter, delete, result); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndDeleteAfterRowLockV1ReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndDeleteAfterRowLock(c, row, family, qualifier, op, - comparator, delete, result); + @Test + public void testPreCheckAndDeleteAfterRowLockV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndDeleteAfterRowLock(c, row, family, qualifier, op, + comparator, delete, result); + }); } @Test @@ -517,9 +562,11 @@ public void testPreCheckAndDeleteAfterRowLockV1ReadOnlyMasterStoreNoException() comparator, delete, result); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndDeleteAfterRowLockV2ReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndDeleteAfterRowLock(c, row, filter, delete, result); + @Test + public void testPreCheckAndDeleteAfterRowLockV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndDeleteAfterRowLock(c, row, filter, delete, result); + }); } @Test @@ -535,49 +582,68 @@ public void testPreCheckAndDeleteAfterRowLockV2ReadOnlyMasterStoreNoException() regionReadOnlyController.preCheckAndDeleteAfterRowLock(c, row, filter, delete, result); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndMutateReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndMutate(c, checkAndMutate, checkAndMutateResult); + @Test + public void testPreCheckAndMutateReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndMutate(c, checkAndMutate, checkAndMutateResult); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCheckAndMutateAfterRowLockReadOnlyException() throws IOException { - regionReadOnlyController.preCheckAndMutateAfterRowLock(c, checkAndMutate, checkAndMutateResult); + @Test + public void testPreCheckAndMutateAfterRowLockReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCheckAndMutateAfterRowLock(c, checkAndMutate, + checkAndMutateResult); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreAppendV1ReadOnlyException() throws IOException { - regionReadOnlyController.preAppend(c, append); + @Test + public void testPreAppendV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preAppend(c, append); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreAppendV2ReadOnlyException() throws IOException { - regionReadOnlyController.preAppend(c, append, edit); + @Test + public void testPreAppendV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preAppend(c, append, edit); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreAppendAfterRowLockReadOnlyException() throws IOException { - regionReadOnlyController.preAppendAfterRowLock(c, append); + @Test + public void testPreAppendAfterRowLockReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preAppendAfterRowLock(c, append); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreIncrementV1ReadOnlyException() throws IOException { - regionReadOnlyController.preIncrement(c, increment); + @Test + public void testPreIncrementV1ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preIncrement(c, increment); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreIncrementV2ReadOnlyException() throws IOException { - regionReadOnlyController.preIncrement(c, increment, edit); + @Test + public void testPreIncrementV2ReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preIncrement(c, increment, edit); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreIncrementAfterRowLockReadOnlyException() throws IOException { - regionReadOnlyController.preIncrementAfterRowLock(c, increment); + @Test + public void testPreIncrementAfterRowLockReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preIncrementAfterRowLock(c, increment); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreReplayWALsReadOnlyException() throws IOException { - regionReadOnlyController.preReplayWALs(ctx, info, edits); + @Test + public void testPreReplayWALsReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preReplayWALs(ctx, info, edits); + }); } @Test @@ -592,19 +658,25 @@ public void testPreReplayWALsReadOnlyMasterStoreNoException() throws IOException regionReadOnlyController.preReplayWALs(ctx, info, edits); } - @Test(expected = DoNotRetryIOException.class) - public void testPreBulkLoadHFileReadOnlyException() throws IOException { - regionReadOnlyController.preBulkLoadHFile(ctx, familyPaths); + @Test + public void testPreBulkLoadHFileReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preBulkLoadHFile(ctx, familyPaths); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreCommitStoreFileReadOnlyException() throws IOException { - regionReadOnlyController.preCommitStoreFile(ctx, family, pairs); + @Test + public void testPreCommitStoreFileReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preCommitStoreFile(ctx, family, pairs); + }); } - @Test(expected = DoNotRetryIOException.class) - public void testPreWALAppendReadOnlyException() throws IOException { - regionReadOnlyController.preWALAppend(ctx, key, edit); + @Test + public void testPreWALAppendReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> { + regionReadOnlyController.preWALAppend(ctx, key, edit); + }); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionServerObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionServerObserver.java index 382e55a0c409..dca87c6ef0e0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionServerObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionServerObserver.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.security.access; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; -import java.io.IOException; -import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException; import org.apache.hadoop.hbase.client.Mutation; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment; @@ -72,18 +72,21 @@ public void tearDown() throws Exception { } - @Test(expected = DoNotRetryIOException.class) - public void testPreRollWALWriterRequestReadOnlyException() throws IOException { - regionServerReadOnlyController.preRollWALWriterRequest(ctx); + @Test + public void testPreRollWALWriterRequestReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, + () -> regionServerReadOnlyController.preRollWALWriterRequest(ctx)); } - @Test(expected = DoNotRetryIOException.class) - public void testPreReplicationSinkBatchMutateReadOnlyException() throws IOException { - regionServerReadOnlyController.preReplicationSinkBatchMutate(ctx, walEntry, mutation); + @Test + public void testPreReplicationSinkBatchMutateReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, + () -> regionServerReadOnlyController.preReplicationSinkBatchMutate(ctx, walEntry, mutation)); } - @Test(expected = DoNotRetryIOException.class) - public void testPreReplicateLogEntriesReadOnlyException() throws IOException { - regionServerReadOnlyController.preReplicateLogEntries(ctx); + @Test + public void testPreReplicateLogEntriesReadOnlyException() { + assertThrows(WriteAttemptedOnReadOnlyClusterException.class, + () -> regionServerReadOnlyController.preReplicateLogEntries(ctx)); } }