voonhous commented on code in PR #19253:
URL: https://github.com/apache/hudi/pull/19253#discussion_r3881753635
##########
hudi-hadoop-common/src/test/java/org/apache/hudi/io/hadoop/TestHoodieHadoopIOFactory.java:
##########
@@ -61,9 +68,50 @@ public void testGetFileFormatUtils() throws IOException {
assertTrue(ioFactory.getFileFormatUtils(HoodieFileFormat.ORC) instanceof
OrcUtils);
assertTrue(ioFactory.getFileFormatUtils(HoodieFileFormat.HFILE)
instanceof HFileUtils);
assertTrue(ioFactory.getFileFormatUtils(HoodieFileFormat.LANCE)
instanceof LanceUtils);
+ assertTrue(ioFactory.getFileFormatUtils(HoodieFileFormat.VORTEX)
instanceof VortexUtils);
assertThrows(
UnsupportedOperationException.class,
() -> ioFactory.getFileFormatUtils(HoodieFileFormat.HOODIE_LOG));
}
}
+
+ /**
+ * {@link HoodieIOFactory#getFileFormatUtils(StoragePath)} maps the file
extension to a format
+ * through its own if-chain before delegating to the {@link
HoodieFileFormat} switch in
+ * {@link HoodieHadoopIOFactory#getFileFormatUtils(HoodieFileFormat)}. A
format added to one
+ * dispatch point but missed in the other only fails at runtime, so this
sweeps every enum value
+ * (never a hardcoded list) and requires both entry points to agree: the
same utils class, or
+ * {@link UnsupportedOperationException} from both. Any other exception type
propagates.
+ */
+ @ParameterizedTest
+ @EnumSource(HoodieFileFormat.class)
+ void testGetFileFormatUtilsEntryPointsAgreeForEveryFormat(HoodieFileFormat
format) throws IOException {
+ try (HoodieStorage storage = newStorage()) {
+ HoodieIOFactory ioFactory = new HoodieHadoopIOFactory(storage);
+ StoragePath path = new StoragePath("file:///a/b" +
format.getFileExtension());
+ Option<Class<?>> byFormat = fileFormatUtilsClass(() ->
ioFactory.getFileFormatUtils(format));
+ Option<Class<?>> byPath = fileFormatUtilsClass(() ->
ioFactory.getFileFormatUtils(path));
+ assertEquals(byFormat, byPath, () -> String.format(
+ "Dispatch asymmetry for %s: getFileFormatUtils(HoodieFileFormat) ->
%s but getFileFormatUtils(%s) -> %s; "
+ + "the extension if-chain in HoodieIOFactory and the format
switch in HoodieHadoopIOFactory must "
+ + "cover the same formats.",
+ format, byFormat, path, byPath));
+ }
+ }
+
+ /**
+ * @return the class of the returned utils, or empty when the entry point
throws
+ * {@link UnsupportedOperationException} for the format.
+ */
+ private static Option<Class<?>>
fileFormatUtilsClass(Supplier<FileFormatUtils> entryPoint) {
+ try {
+ return Option.of(entryPoint.get().getClass());
+ } catch (UnsupportedOperationException e) {
+ return Option.empty();
+ }
+ }
+
+ private static HoodieStorage newStorage() {
Review Comment:
Done in 37c870633a17: the factory is a field built from
`HoodieTestUtils.getDefaultStorage()`; `newStorage()`, the try-with-resources
and `throws IOException` are gone.
--
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]