stevenzwu commented on code in PR #18800:
URL: https://github.com/apache/iceberg/pull/18800#discussion_r4807283700
##########
data/src/test/java/org/apache/iceberg/data/TestGenericFormatModel.java:
##########
@@ -70,4 +80,42 @@ protected Object convertConstantToEngine(Type type, Object
value) {
// (LocalDate, LocalDateTime, ...) so reads match the generic comparison
in DataTestHelpers.
return GenericDataUtil.internalToGeneric(type, value);
}
+
+ @Test
+ void registersModelsWhenTheContextClassLoaderCannotSeeIceberg() throws
Exception {
Review Comment:
This class is the TCK binding for the generic object model, so a registry
class-loading test doesn't belong here. It also reads the private `models()`
map reflectively. `TestFormatModelRegistry` already has `register(String)`
tests (with `ThrowsOnInvoke`, etc.), so the same recording-registrar approach
would work there, in `core`, without needing the `data` module's
`GenericFormatModels`.
##########
core/src/test/java/org/apache/iceberg/TestInternalData.java:
##########
@@ -174,6 +178,48 @@ public void
registerToleratesExceptionInInitializerErrorOnInvoke() {
assertThatNoException().isThrownBy(() ->
register(ThrowsInitErrorOnInvoke.class.getName()));
}
+ @Test
+ void registersParquetWhenTheContextClassLoaderCannotSeeIceberg() throws
Exception {
Review Comment:
+1. The behavior under test is `register(String)` resolving the class
through Iceberg's loader instead of the context loader. The existing
`registerTolerates*` tests already call it reflectively, so a test in the same
style would be much shorter than a second classpath copy, a worker thread, and
reflection over `Files`/`FileFormat`/`OutputFile`:
```java
@Test
void registerUsesIcebergClassLoader() throws Exception {
ClassLoader original = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(null);
try {
Registrar.registered = false;
register(Registrar.class.getName());
assertThat(Registrar.registered).isTrue();
} finally {
Thread.currentThread().setContextClassLoader(original);
}
}
public static class Registrar {
static boolean registered;
public static void register() {
registered = true;
}
}
```
With a null context loader the old lookup can't find `Registrar` and just
logs, so this should fail without the fix and pass with it.
It would also let us drop `TestHelpers.testClasspath()`, which I'd rather
not add to `api`'s shared test fixture:
- It is a public helper in a class used across modules, added for two tests
that need an isolated loader.
- It assumes `java.class.path` lists the real test classpath. That holds
under Gradle, but breaks with IDE runners that shorten the command line
(manifest-only jar or argfile) and with module-path runs.
- Each test loads and initializes a second copy of Iceberg, including the
Parquet write path, which adds class-loading time and metaspace.
--
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]