sanjeet006py commented on code in PR #8236: URL: https://github.com/apache/hbase/pull/8236#discussion_r3249470649
########## hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRegionLocatorPagedScanRpcCount.java: ########## @@ -0,0 +1,215 @@ +/* + * 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.assertEquals; + +import java.io.IOException; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.hadoop.hbase.CatalogReplicaMode; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HRegionLocation; +import org.apache.hadoop.hbase.MetaTableAccessor; +import org.apache.hadoop.hbase.RegionLocations; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.metrics.ScanMetrics; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Asserts the single-RPC promise of the paginated meta-scan path + * ({@link MetaTableAccessor#scanMetaForTableRegions(Connection, MetaTableAccessor.Visitor, TableName, byte[], int, CatalogReplicaMode)}) + * by wrapping the meta {@link Table} so we can read {@link ScanMetrics#countOfRPCcalls} from the + * issued {@link ResultScanner} - one per ScannerNext server response. + * <p/> + * Cluster runs with {@code hbase.meta.scanner.caching = 2} so the {@code limit > caching} branch is + * exercised cheaply with a small table (5 user regions). + */ +@Category({ MediumTests.class, ClientTests.class }) Review Comment: I tried to find a way to do this with a mock and got a bit stuck — wanted to share where I landed. The property the test is asserting is "exactly one `ScannerNext` RPC fires for a paged scan, regardless of `hbase.meta.scanner.caching`." That isn't really a property of `MetaTableAccessor` in isolation — it's an emergent property of `ClientScanner` + `ScannerCallable` + the RegionServer responding to the scan's `caching`/`limit`, and `ScanMetrics.countOfRPCcalls` is incremented inside that machinery on real responses. Two mock-based shapes I considered, both of which seem to weaken the test: 1. Capture the `Scan` and assert `scan.getCaching() == rowLimit`. This restates the one-line fix in `getMetaScan` and wouldn't catch a future regression where caching is set correctly but the client-side batching contract changes. 2. Hand-roll a fake `ResultScanner` that simulates `ScannerNext` batching from `caching`/`limit`. That re-implements the contract we're verifying inside the test fake and asserts our fake matches our expectation — feels tautological. If you see a shape I missed that preserves the RPC-count assertion without a cluster, I'd be happy to switch. Otherwise I'd lean toward keeping this as an integration test. -- 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]
