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


##########
core/src/test/java/org/apache/iceberg/hadoop/HadoopFileIOTest.java:
##########
@@ -176,6 +178,52 @@ public void testResolvingFileIOLoad() {
     assertThat(result).isInstanceOf(HadoopFileIO.class);
   }
 
+  @Test
+  public void testJsonParserWithoutHadoopConf() throws Exception {
+    this.hadoopFileIO = new HadoopFileIO();
+
+    hadoopFileIO.initialize(ImmutableMap.of("properties-bar", "2"));
+    assertThat(hadoopFileIO.properties().get("properties-bar")).isEqualTo("2");
+
+    testJsonParser(hadoopFileIO, tempDir);
+  }
+
+  @Test
+  public void testJsonParserWithHadoopConf() throws Exception {
+    this.hadoopFileIO = new HadoopFileIO();
+
+    Configuration hadoopConf = new Configuration();
+    hadoopConf.setInt("hadoop-conf-foo", 1);
+    hadoopFileIO.setConf(hadoopConf);
+    assertThat(hadoopFileIO.conf().get("hadoop-conf-foo")).isNotNull();
+
+    hadoopFileIO.initialize(ImmutableMap.of("properties-bar", "2"));
+    assertThat(hadoopFileIO.properties().get("properties-bar")).isEqualTo("2");
+
+    testJsonParser(hadoopFileIO, tempDir);
+  }
+
+  private static void testJsonParser(HadoopFileIO hadoopFileIO, File tempDir) 
throws Exception {
+    String json = FileIOParser.toJson(hadoopFileIO);
+    try (FileIO deserialized = FileIOParser.fromJson(json)) {
+      assertThat(deserialized).isInstanceOf(HadoopFileIO.class);
+      HadoopFileIO deserializedHadoopFileIO = (HadoopFileIO) deserialized;
+
+      // properties are carried over during serialization and deserialization
+      
assertThat(deserializedHadoopFileIO.properties()).isEqualTo(hadoopFileIO.properties());
+
+      // FileIOParser doesn't serialize and deserialize Hadoop configuration
+      // so config "foo" is not restored in deserialized object.
+      
assertThat(deserializedHadoopFileIO.conf().get("hadoop-conf-foo")).isNull();
+
+      // make sure deserialized io can create input file
+      String inputFilePath =
+          Files.createTempDirectory(tempDir.toPath(), 
"junit").toFile().getAbsolutePath()
+              + "/test.parquet";
+      deserializedHadoopFileIO.newInputFile(inputFilePath);

Review Comment:
   in other places we typically do something like this:
   ```suggestion
         deserializedHadoopFileIO.newInputFile(File.createTempFile("test", 
"parquet", tempDir).toString());
   ```



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