LuciferYang commented on code in PR #3450:
URL: https://github.com/apache/parquet-java/pull/3450#discussion_r3107108413
##########
parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriterError.java:
##########
@@ -58,6 +62,48 @@ public class TestParquetWriterError {
@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();
+ @Test
+ public void testWriteAfterAbortShouldThrow() throws Exception {
+ java.nio.file.Path outputFile =
tmpFolder.newFile("abort_test.parquet").toPath();
+ MessageType schema =
+ MessageTypeParser.parseMessageType("message test { required binary
name; required int32 age; }");
+ SimpleGroupFactory groupFactory = new SimpleGroupFactory(schema);
+
+ try (TrackingByteBufferAllocator allocator =
TrackingByteBufferAllocator.wrap(new HeapByteBufferAllocator())) {
+ ParquetWriter<Group> writer = ExampleParquetWriter.builder(new
LocalOutputFile(outputFile))
+ .withType(schema)
+ .withAllocator(allocator)
+ .withWriteMode(ParquetFileWriter.Mode.OVERWRITE)
+ .build();
+
+ // Write one valid record
+ writer.write(groupFactory.newGroup().append("name",
"Alice").append("age", 30));
+
+ // Simulate an aborted state by reflectively setting the aborted flag
+ // on the internal writer. This mirrors what happens when a write fails
+ // with an exception (e.g. OOM during page flush).
+ Field internalWriterField =
ParquetWriter.class.getDeclaredField("writer");
+ internalWriterField.setAccessible(true);
+ InternalParquetRecordWriter<?> internalWriter =
+ (InternalParquetRecordWriter<?>) internalWriterField.get(writer);
+ Field abortedField =
InternalParquetRecordWriter.class.getDeclaredField("aborted");
+ abortedField.setAccessible(true);
+ abortedField.setBoolean(internalWriter, true);
+
+ // Now try to write again - this should throw IOException
+ IOException e = Assert.assertThrows(
Review Comment:
Use `Assert.assertThrows` to better align with the style of other test cases
in the project.(like TestIndexCache)
--
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]