jerryshao commented on code in PR #14884:
URL: https://github.com/apache/gravitino/pull/14884#discussion_r4560520179


##########
plugins/idp-basic/src/test/java/org/apache/gravitino/idp/storage/service/TestIdpMetaServiceMetrics.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.gravitino.idp.storage.service;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import com.codahale.metrics.MetricRegistry;
+import java.io.IOException;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.gravitino.exceptions.NotFoundException;
+import org.apache.gravitino.metrics.MethodMonitorAspect;
+import org.apache.gravitino.metrics.MetricsSystem;
+import org.apache.gravitino.metrics.source.MetricsSource;
+import org.aspectj.lang.Aspects;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Verifies that {@code @Monitored} methods in this plugin are woven and 
record metrics. */
+class TestIdpMetaServiceMetrics extends AbstractIdpMetaServiceTest {
+
+  private MethodMonitorAspect aspect;
+  private Object originalMetricsSystem;
+  private MetricsSource metricsSource;
+
+  @BeforeEach
+  void installMetricsSystem() throws IllegalAccessException {
+    // The aspect reads the metrics system once when it is created, so replace 
it for this test.
+    aspect = Aspects.aspectOf(MethodMonitorAspect.class);
+    originalMetricsSystem = FieldUtils.readField(aspect, "metricsSystem", 
true);
+    metricsSource = new 
MetricsSource(MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME) {};
+    MetricsSystem metricsSystem = new MetricsSystem();
+    metricsSystem.register(metricsSource);
+    FieldUtils.writeField(aspect, "metricsSystem", metricsSystem, true);

Review Comment:
   The test swaps a private field on the aspect singleton through reflection, 
which breaks silently if the field is renamed and could leak into tests running 
in parallel in the same JVM. Consider a package-visible setter or a test hook 
on the aspect, and keep the restore in AfterEach.



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