hanghangliu commented on code in PR #3821:
URL: https://github.com/apache/gobblin/pull/3821#discussion_r1385465402


##########
gobblin-modules/gobblin-orc/src/test/java/org/apache/gobblin/writer/GobblinBaseOrcWriterTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.writer;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.orc.FileFormatException;
+import org.apache.orc.OrcFile;
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.common.io.Files;
+
+import org.apache.gobblin.metrics.MetricContext;
+import org.apache.gobblin.metrics.event.GobblinEventBuilder;
+
+import static 
org.apache.gobblin.writer.GobblinBaseOrcWriter.CORRUPTED_ORC_FILE_DELETION_EVENT;
+
+
+public class GobblinBaseOrcWriterTest {
+
+  @Test
+  public void testOrcValidation()
+      throws IOException {
+    Configuration conf = new Configuration();
+    FileSystem fs = FileSystem.getLocal(conf);
+    File tmpDir = Files.createTempDir();
+    File corruptedOrcFile = new File(tmpDir, "test.orc");
+    try (FileWriter writer = new FileWriter(corruptedOrcFile)) {
+      // write a corrupted ORC file that only contains the header but without 
content
+      writer.write(OrcFile.MAGIC);
+    }
+
+    OrcFile.ReaderOptions readerOptions = new OrcFile.ReaderOptions(conf);
+
+    MetricContext mockContext = Mockito.mock(MetricContext.class);
+    Path p = new Path(corruptedOrcFile.getAbsolutePath());
+    Assert.assertThrows(FileFormatException.class,
+        () -> GobblinBaseOrcWriter.assertOrcFileIsValid(fs, p, readerOptions, 
mockContext));
+
+    GobblinEventBuilder eventBuilder = new 
GobblinEventBuilder(CORRUPTED_ORC_FILE_DELETION_EVENT, 
GobblinBaseOrcWriter.ORC_WRITER_NAMESPACE);

Review Comment:
   Do you think test the EventBuilder like 
[this](https://github.com/apache/gobblin/blob/10397ab9d85829b86f1a04958742e612dcff234b/gobblin-iceberg/src/test/java/org/apache/gobblin/iceberg/writer/IcebergMetadataWriterTest.java#L179)
 makes it easier so you won't need to suppress the warning?



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

Reply via email to