-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Destination S3V2: Fix: Parquet never writes empty files (#49982)
- Loading branch information
1 parent
668409a
commit ab8e834
Showing
2 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...test/kotlin/io/airbyte/cdk/load/write/object_storage/ObjectStorageFormattingWriterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.load.write.object_storage | ||
|
||
import io.airbyte.cdk.load.file.NoopProcessor | ||
import io.airbyte.cdk.load.file.object_storage.BufferedFormattingWriter | ||
import io.airbyte.cdk.load.file.object_storage.ObjectStorageFormattingWriter | ||
import io.mockk.coEvery | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.mockk | ||
import java.io.ByteArrayOutputStream | ||
import org.junit.jupiter.api.Test | ||
|
||
class ObjectStorageFormattingWriterTest { | ||
@MockK(relaxed = true) lateinit var underlyingWriter: ObjectStorageFormattingWriter | ||
|
||
@Test | ||
fun `buffered formatting writer never produces empty parts`() { | ||
val outputStream = ByteArrayOutputStream() | ||
outputStream.write("i am a header".toByteArray()) | ||
val bufferedWriter = | ||
BufferedFormattingWriter( | ||
underlyingWriter, | ||
outputStream, | ||
NoopProcessor, | ||
NoopProcessor.wrapper(outputStream), | ||
) | ||
|
||
assert(bufferedWriter.bufferSize == 0) { "buffer appears empty despite header" } | ||
assert(bufferedWriter.takeBytes() == null) { "buffer yields no data despite header" } | ||
assert(bufferedWriter.finish() == null) { "buffer yields no data despite header" } | ||
} | ||
|
||
@Test | ||
fun `buffered formatting writer yields entire buffer once any data has been added`() { | ||
val outputStream = ByteArrayOutputStream() | ||
outputStream.write("i am a header".toByteArray()) | ||
val bufferedWriter = | ||
BufferedFormattingWriter( | ||
underlyingWriter, | ||
outputStream, | ||
NoopProcessor, | ||
NoopProcessor.wrapper(outputStream), | ||
) | ||
|
||
assert(bufferedWriter.takeBytes() == null) | ||
coEvery { bufferedWriter.accept(any()) } coAnswers { outputStream.write("!".toByteArray()) } | ||
bufferedWriter.accept(mockk()) | ||
val bytes = bufferedWriter.takeBytes() | ||
assert(bytes != null) { "buffer yields data now that we've written to it" } | ||
assert(bytes.contentEquals("i am a header!".toByteArray())) { | ||
"buffer yields all data written to it" | ||
} | ||
} | ||
} |