xushiyan commented on a change in pull request #2112:
URL: https://github.com/apache/hudi/pull/2112#discussion_r494635687



##########
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/testutils/HoodieTestCommitMetadataGenerator.java
##########
@@ -62,67 +62,53 @@
   /**
    * Create a commit file with default CommitMetadata.
    */
-  public static void createCommitFileWithMetadata(String basePath, String 
commitTime, Configuration configuration) {
+  public static void createCommitFileWithMetadata(String basePath, String 
commitTime, Configuration configuration) throws Exception {
     createCommitFileWithMetadata(basePath, commitTime, configuration, 
Option.empty(), Option.empty());
   }
 
   public static void createCommitFileWithMetadata(String basePath, String 
commitTime, Configuration configuration,
-      Option<Integer> writes, Option<Integer> updates) {
+      Option<Integer> writes, Option<Integer> updates) throws Exception {
     createCommitFileWithMetadata(basePath, commitTime, configuration, 
UUID.randomUUID().toString(),
         UUID.randomUUID().toString(), writes, updates);
   }
 
   public static void createCommitFileWithMetadata(String basePath, String 
commitTime, Configuration configuration,
-      String fileId1, String fileId2, Option<Integer> writes, Option<Integer> 
updates) {
-    Arrays.asList(HoodieTimeline.makeCommitFileName(commitTime), 
HoodieTimeline.makeInflightCommitFileName(commitTime),
-        HoodieTimeline.makeRequestedCommitFileName(commitTime))
-        .forEach(f -> {
-          Path commitFile = new Path(
-              basePath + "/" + HoodieTableMetaClient.METAFOLDER_NAME + "/" + 
f);
-          FSDataOutputStream os = null;
-          try {
-            FileSystem fs = FSUtils.getFs(basePath, configuration);
-            os = fs.create(commitFile, true);
-            // Generate commitMetadata
-            HoodieCommitMetadata commitMetadata =
-                generateCommitMetadata(basePath, commitTime, fileId1, fileId2, 
writes, updates);
-            // Write empty commit metadata
-            os.writeBytes(new 
String(commitMetadata.toJsonString().getBytes(StandardCharsets.UTF_8)));
-          } catch (IOException ioe) {
-            throw new HoodieIOException(ioe.getMessage(), ioe);
-          } finally {
-            if (null != os) {
-              try {
-                os.close();
-              } catch (IOException e) {
-                throw new HoodieIOException(e.getMessage(), e);
-              }
-            }
-          }
-        });
+      String fileId1, String fileId2, Option<Integer> writes, Option<Integer> 
updates) throws Exception {
+    List<String> commitFileNames = 
Arrays.asList(HoodieTimeline.makeCommitFileName(commitTime), 
HoodieTimeline.makeInflightCommitFileName(commitTime),
+        HoodieTimeline.makeRequestedCommitFileName(commitTime));
+    for (String name : commitFileNames) {
+      Path commitFilePath = new Path(Paths.get(basePath, 
HoodieTableMetaClient.METAFOLDER_NAME, name).toString());
+      try (FSDataOutputStream os = FSUtils.getFs(basePath, 
configuration).create(commitFilePath, true)) {
+        // Generate commitMetadata
+        HoodieCommitMetadata commitMetadata =
+            generateCommitMetadata(basePath, commitTime, fileId1, fileId2, 
writes, updates);
+        // Write empty commit metadata
+        os.writeBytes(new 
String(commitMetadata.toJsonString().getBytes(StandardCharsets.UTF_8)));
+      }
+    }

Review comment:
       change stream#foreach to for-loop to avoid the noisy try-catch block.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to