Copilot commented on code in PR #10792:
URL: https://github.com/apache/ozone/pull/10792#discussion_r3606474660


##########
hadoop-ozone/ozonefs-common/src/test/java/org/apache/hadoop/fs/ozone/TestBasicRootedOzoneClientAdapterHeadOp.java:
##########
@@ -77,10 +82,29 @@ public void setUp() throws Exception {
     when(volume.getCreationTime()).thenReturn(Instant.EPOCH);
     ObjectStore objectStore = mock(ObjectStore.class);
     when(objectStore.getVolume(anyString())).thenReturn(volume);
-    Field field =
-        
BasicRootedOzoneClientAdapterImpl.class.getDeclaredField("objectStore");
+    setField(adapter, "objectStore", objectStore);
+    setField(adapter, "proxy", proxy);
+    warmLayoutCache("vol", "bucket");
+  }
+
+  private static void setField(Object target, String name, Object value)
+      throws Exception {
+    Field field = 
BasicRootedOzoneClientAdapterImpl.class.getDeclaredField(name);
     field.setAccessible(true);
-    field.set(adapter, objectStore);
+    field.set(target, value);
+  }
+
+  @SuppressWarnings("unchecked")
+  private void warmLayoutCache(String volumeName, String bucketName)
+      throws Exception {
+    Field cacheField =
+        BasicRootedOzoneClientAdapterImpl.class.getDeclaredField(
+            "validatedBucketLayouts");
+    cacheField.setAccessible(true);
+    ConcurrentHashMap<String, BucketLayout> cache =
+        new ConcurrentHashMap<>();
+    cache.put(volumeName + "/" + bucketName, 
BucketLayout.FILE_SYSTEM_OPTIMIZED);
+    cacheField.set(adapter, cache);

Review Comment:
   warmLayoutCache() replaces the validatedBucketLayouts field via reflection. 
In production this field is final, and swapping the reference can be blocked or 
behave inconsistently under newer JDKs. It’s safer to read the existing map 
instance from the field and mutate it (put the warm entry) rather than setting 
a new ConcurrentHashMap.



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

Reply via email to