kgeisz commented on code in PR #7464:
URL: https://github.com/apache/hbase/pull/7464#discussion_r2586243895


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ReadOnlyController.java:
##########
@@ -395,10 +819,10 @@ public void 
preReplicationSinkBatchMutate(ObserverContext<RegionServerCoprocesso
   }
 
   @Override
-  public void 
preClearRegionBlockCache(ObserverContext<RegionServerCoprocessorEnvironment> 
ctx)

Review Comment:
   I see `preClearRegionBlockCache()` was removed here, but I don't see it 
added back anywhere else.  Did you mean to remove it?



##########
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:
   Same as my previous comment.



##########
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:
   I understand you have this to stay consistent with the actual method 
signatures, but IMO this isn't necessary for test code.  The reader has to take 
some extra time to figure out why this is being done.



-- 
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]

Reply via email to