-
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: Guard against name conflicts
- Loading branch information
1 parent
0159fef
commit 5b6b267
Showing
14 changed files
with
205 additions
and
26 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
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
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
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
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
48 changes: 48 additions & 0 deletions
48
.../src/test/kotlin/io/airbyte/cdk/load/file/object_storage/ObjectStoragePathFactoryUTest.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,48 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.load.file.object_storage | ||
|
||
import io.airbyte.cdk.load.command.DestinationStream | ||
import io.airbyte.cdk.load.command.object_storage.ObjectStoragePathConfiguration | ||
import io.airbyte.cdk.load.command.object_storage.ObjectStoragePathConfigurationProvider | ||
import io.airbyte.cdk.load.file.TimeProvider | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class ObjectStoragePathFactoryUTest { | ||
@MockK lateinit var stream: DestinationStream | ||
@MockK lateinit var pathConfigProvider: ObjectStoragePathConfigurationProvider | ||
@MockK lateinit var timeProvider: TimeProvider | ||
|
||
@BeforeEach | ||
fun setup() { | ||
every { stream.descriptor } returns DestinationStream.Descriptor("test", "stream") | ||
every { timeProvider.syncTimeMillis() } returns 0 | ||
every { timeProvider.currentTimeMillis() } returns 1 | ||
} | ||
|
||
@Test | ||
fun `test matcher with suffix`() { | ||
every { pathConfigProvider.objectStoragePathConfiguration } returns | ||
ObjectStoragePathConfiguration( | ||
"prefix", | ||
null, | ||
"path/", | ||
"ambiguous_filename", | ||
false, | ||
) | ||
val factory = ObjectStoragePathFactory(pathConfigProvider, null, null, timeProvider) | ||
|
||
val matcher = factory.getPathMatcher(stream, "(-\\d+)?") | ||
val match1 = matcher.match("prefix/path/ambiguous_filename") | ||
assert(match1 != null) | ||
assert(match1?.customSuffix == null) | ||
val match2 = matcher.match("prefix/path/ambiguous_filename-1") | ||
assert(match2 != null) | ||
assert(match2?.customSuffix == "-1") | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...est/kotlin/io/airbyte/cdk/load/state/object_storage/ObjectStorageDestinationStateUTest.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,65 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.load.state.object_storage | ||
|
||
import io.airbyte.cdk.load.command.DestinationStream | ||
import io.airbyte.cdk.load.file.object_storage.ObjectStorageClient | ||
import io.airbyte.cdk.load.file.object_storage.ObjectStoragePathFactory | ||
import io.airbyte.cdk.load.file.object_storage.PathMatcher | ||
import io.airbyte.cdk.load.file.object_storage.RemoteObject | ||
import io.mockk.coEvery | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class ObjectStorageDestinationStateUTest { | ||
data class MockObj(override val key: String, override val storageConfig: Unit = Unit) : | ||
RemoteObject<Unit> | ||
|
||
@MockK lateinit var stream: DestinationStream | ||
@MockK lateinit var client: ObjectStorageClient<*> | ||
@MockK lateinit var pathFactory: ObjectStoragePathFactory | ||
|
||
@BeforeEach | ||
fun setup() { | ||
every { stream.descriptor } returns DestinationStream.Descriptor("test", "stream") | ||
every { pathFactory.getPathMatcher(any(), any()) } answers | ||
{ | ||
val suffix = secondArg<String>() | ||
PathMatcher(Regex("([a-z]+)$suffix"), mapOf("suffix" to 2)) | ||
} | ||
every { pathFactory.getLongestStreamConstantPrefix(any(), any()) } returns "prefix/" | ||
} | ||
|
||
@Test | ||
fun `test that the fallback persister correctly infers the unique key to ordinal count`() = | ||
runTest { | ||
coEvery { client.list(any()) } returns | ||
flowOf( | ||
MockObj("dog"), | ||
MockObj("dog-1"), | ||
MockObj("dog-3"), | ||
MockObj("cat"), | ||
MockObj("turtle-100") | ||
) | ||
coEvery { client.getMetadata(any()) } returns mapOf("ab-generation-id" to "1") | ||
|
||
val persister = ObjectStorageFallbackPersister(client, pathFactory) | ||
val state = persister.load(stream) | ||
assert(state.countByKey["dog"] == 3L) | ||
assert(state.countByKey["cat"] == 0L) | ||
assert(state.countByKey["turtle"] == 100L) | ||
|
||
assert(state.ensureUnique("dog") == "dog-4") | ||
assert(state.ensureUnique("dog") == "dog-5") | ||
assert(state.ensureUnique("cat") == "cat-1") | ||
assert(state.ensureUnique("turtle") == "turtle-101") | ||
assert(state.ensureUnique("turtle") == "turtle-102") | ||
assert(state.ensureUnique("spider") == "spider") | ||
} | ||
} |
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
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
Oops, something went wrong.