nastra commented on code in PR #10459:
URL: https://github.com/apache/iceberg/pull/10459#discussion_r1631956569


##########
core/src/test/java/org/apache/iceberg/TestCatalogUtil.java:
##########
@@ -249,6 +253,50 @@ public void fullTableNameWithDifferentValues() {
         .isEqualTo(pathStyleCatalogName + "/" + nameSpaceWithTwoLevels + "." + 
tableName);
   }
 
+  @Test
+  public void testLoadMetricsReporterFromThreadContextClassLoader() throws 
Exception {
+    URL jarUrl =
+        getClass()
+            .getClassLoader()
+            
.getResource("com/example/target/custom-metrics-reporter-1.0-SNAPSHOT.jar");
+    Assertions.assertThat(jarUrl).isNotNull();
+    ClassLoader customClassLoader =
+        new URLClassLoader(new URL[] {jarUrl}, 
ClassLoader.getSystemClassLoader());
+    Map<String, String> properties = new HashMap<>();
+    properties.put(CatalogProperties.METRICS_REPORTER_IMPL, 
"com.example.CustomMetricsReporter");
+
+    // Temporarily change the context class loader to the custom class loader
+    ClassLoader originalContextClassLoader = 
Thread.currentThread().getContextClassLoader();
+    try {
+      try {
+        CatalogUtil.loadMetricsReporter(properties);
+        Assertions.fail("Expected to throw IllegalArgumentException");
+      } catch (IllegalArgumentException e) {
+        Assertions.assertThat(e.getMessage()).contains("Cannot initialize 
MetricsReporter");
+      }
+      Thread.currentThread().setContextClassLoader(customClassLoader);
+      MetricsReporter reporter = CatalogUtil.loadMetricsReporter(properties);
+
+      Assertions.assertThat(reporter).isNotNull();

Review Comment:
   ```suggestion
         
Assertions.assertThat(reporter).isNotNull().isInstanceOf(MetricsReporter.class);
   ```



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to