sharmaar12 commented on code in PR #7464: URL: https://github.com/apache/hbase/pull/7464#discussion_r2587665218
########## hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerMasterObserver.java: ########## @@ -0,0 +1,748 @@ +/* + * 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.security.access; + +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.HBaseClassTestRule; +import org.apache.hadoop.hbase.NamespaceDescriptor; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.BalanceRequest; +import org.apache.hadoop.hbase.client.Mutation; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.SnapshotDescription; +import org.apache.hadoop.hbase.client.TableDescriptor; +import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; +import org.apache.hadoop.hbase.net.Address; +import org.apache.hadoop.hbase.quotas.GlobalQuotaSettings; +import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; +import org.apache.hadoop.hbase.replication.SyncReplicationState; +import org.apache.hadoop.hbase.testclassification.SecurityTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +// Tests methods of Master Observer which are implemented in ReadOnlyController, +// by mocking the coprocessor environment and dependencies + +@Category({ SecurityTests.class, SmallTests.class }) +public class TestReadOnlyControllerMasterObserver { + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestReadOnlyControllerMasterObserver.class); + + ReadOnlyController readOnlyController; + + // Master Coprocessor mocking variables + ObserverContext<MasterCoprocessorEnvironment> c, ctx; + TableDescriptor desc; + RegionInfo[] regions; + TableName tableName; + TableDescriptor currentDescriptor, newDescriptor; + String dstSFT; + byte[] family; + byte[] splitRow; + byte[] splitKey; + List<Mutation> metaEntries; + RegionInfo[] regionsToMerge; + SnapshotDescription snapshot; + TableDescriptor tableDescriptor; + NamespaceDescriptor ns; + NamespaceDescriptor currentNsDescriptor, newNsDescriptor; + String namespace; + String userName; + GlobalQuotaSettings quotas; + String regionServer; + Set<Address> servers; + Set<TableName> tables; + String targetGroup; + String name; + String groupName; + BalanceRequest request; + String oldName, newName; + Map<String, String> configuration; + String peerId; + ReplicationPeerConfig peerConfig; + SyncReplicationState state; + UserPermission userPermission; + boolean mergeExistingPermissions; + + @Before + public void setup() throws Exception { + readOnlyController = new ReadOnlyController(); + + // mocking variables initialization + c = mock(ObserverContext.class); + // ctx is created to make naming variable in sync with the Observer interface + // methods where 'ctx' is used as the ObserverContext variable name instead of 'c'. + // otherwise both are one and the same + ctx = c; Review Comment: The same thing happened with me when I read through RegionObserver code. They also keep using two of these interchangeably. Hence just to avoid confusion with the method signature I kept test code in sync with source code. The correct solution could be to fix all of the observer code but not in our scope. Do you think I should make every method signature to use either ctx or c only? ########## hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerRegionObserver.java: ########## @@ -0,0 +1,588 @@ +/* + * 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.security.access; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.CompareOperator; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Append; +import org.apache.hadoop.hbase.client.CheckAndMutate; +import org.apache.hadoop.hbase.client.CheckAndMutateResult; +import org.apache.hadoop.hbase.client.Delete; +import org.apache.hadoop.hbase.client.Durability; +import org.apache.hadoop.hbase.client.Increment; +import org.apache.hadoop.hbase.client.Mutation; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; +import org.apache.hadoop.hbase.filter.ByteArrayComparable; +import org.apache.hadoop.hbase.filter.Filter; +import org.apache.hadoop.hbase.regionserver.FlushLifeCycleTracker; +import org.apache.hadoop.hbase.regionserver.InternalScanner; +import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress; +import org.apache.hadoop.hbase.regionserver.ScanOptions; +import org.apache.hadoop.hbase.regionserver.ScanType; +import org.apache.hadoop.hbase.regionserver.Store; +import org.apache.hadoop.hbase.regionserver.StoreFile; +import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker; +import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest; +import org.apache.hadoop.hbase.testclassification.SecurityTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.Pair; +import org.apache.hadoop.hbase.wal.WALEdit; +import org.apache.hadoop.hbase.wal.WALKey; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +// Tests methods of Region Observer interface which are implemented in ReadOnlyController, +// by mocking the coprocessor environment and dependencies. +// V1 and V2 means version 1 and version 2 of the coprocessor method signature. +// For example, prePut has 2 versions: +// V1: prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit) +// V2: prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit, Durability durability) + +@Category({ SecurityTests.class, SmallTests.class }) +public class TestReadOnlyControllerRegionObserver { + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestReadOnlyControllerRegionObserver.class); + + ReadOnlyController readOnlyController; + + // Region Coprocessor mocking variables + ObserverContext<RegionCoprocessorEnvironment> c, ctx; + RegionCoprocessorEnvironment env; + RegionInfo regionInfo; + Store store; + InternalScanner scanner; + ScanOptions options; + FlushLifeCycleTracker flushLifeCycleTracker; + List<StoreFile> candidates; + CompactionLifeCycleTracker compactionLifeCycleTracker; + ScanType scanType; + CompactionRequest compactionRequest; + TableName tableName; + Put put; + WALEdit edit; + Durability durability; + Delete delete; + MiniBatchOperationInProgress<Mutation> miniBatchOp; + byte[] row; + byte[] family; + byte[] qualifier; + Filter filter; + CompareOperator op; + ByteArrayComparable comparator; + boolean result; + CheckAndMutate checkAndMutate; + CheckAndMutateResult checkAndMutateResult; + Append append; + Increment increment; + RegionInfo info; + Path edits; + List<Pair<byte[], String>> familyPaths; + List<Pair<Path, Path>> pairs; + WALKey key; + + @Before + public void setup() throws Exception { + readOnlyController = new ReadOnlyController(); + + // mocking variables initialization + c = mock(ObserverContext.class); + // ctx is created to make naming variable in sync with the Observer interface + // methods where 'ctx' is used as the ObserverContext variable name instead of 'c'. + // otherwise both are one and the same + ctx = c; Review Comment: Check: https://github.com/apache/hbase/pull/7464#discussion_r2587665218 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
