szehon-ho commented on code in PR #17236: URL: https://github.com/apache/iceberg/pull/17236#discussion_r3875680914
########## api/src/test/java/org/apache/iceberg/metrics/CachingMetricsContext.java: ########## @@ -0,0 +1,37 @@ +/* + * 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.iceberg.metrics; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * A {@link MetricsContext} that returns the same {@link Counter} instance for a given name, so that + * tests can observe the counters that the code under test increments. {@link DefaultMetricsContext} + * allocates a fresh counter on every {@link #counter(String, Unit)} call, which would otherwise + * hand the test and the code under test two independent counters. + */ +public class CachingMetricsContext extends DefaultMetricsContext { + private final Map<String, Counter> counters = new ConcurrentHashMap<>(); + + @Override + public Counter counter(String name, Unit unit) { Review Comment: Please fully qualify `org.apache.iceberg.metrics.Counter` in both the map value type and this method return type. The inherited deprecated `MetricsContext.Counter` shadows the top-level type, causing `compileTestJava` to fail across CI. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
