-
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.
add integration test on in-memory mock destination
- Loading branch information
Showing
6 changed files
with
117 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
19 changes: 19 additions & 0 deletions
19
...test/kotlin/io/airbyte/cdk/mock_integration_test/MockBasicFunctionalityIntegrationTest.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,19 @@ | ||
package io.airbyte.cdk.mock_integration_test | ||
|
||
import io.airbyte.cdk.command.ConfigurationJsonObjectBase | ||
import io.airbyte.cdk.test.util.DestinationDataDumper | ||
import io.airbyte.cdk.test.util.NoopDestinationCleaner | ||
import io.airbyte.cdk.test.util.NoopExpectedRecordMapper | ||
import io.airbyte.cdk.test.util.NoopNameMapper | ||
import io.airbyte.cdk.test.write.BasicFunctionalityIntegrationTest | ||
|
||
class MockBasicFunctionalityIntegrationTest: BasicFunctionalityIntegrationTest( | ||
object: ConfigurationJsonObjectBase() {}, | ||
DestinationDataDumper { streamName, streamNamespace -> | ||
MockDestinationBackend.readFile(MockStreamLoader.getFilename(streamNamespace, streamName)) | ||
}, | ||
NoopDestinationCleaner, | ||
NoopExpectedRecordMapper, | ||
NoopNameMapper | ||
) { | ||
} |
29 changes: 29 additions & 0 deletions
29
.../core/load/src/test/kotlin/io/airbyte/cdk/mock_integration_test/MockDestinationBackend.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,29 @@ | ||
package io.airbyte.cdk.mock_integration_test | ||
|
||
import io.airbyte.cdk.test.util.OutputRecord | ||
|
||
object MockDestinationBackend { | ||
private val lock = Object() | ||
private val files: MutableMap<String, MutableList<OutputRecord>> = mutableMapOf() | ||
|
||
fun insert(filename: String, vararg records: OutputRecord) { | ||
synchronized(lock) { | ||
getFile(filename).addAll(records) | ||
} | ||
} | ||
|
||
fun readFile(filename: String): List<OutputRecord> { | ||
synchronized(lock) { | ||
return getFile(filename) | ||
} | ||
} | ||
|
||
private fun getFile(filename: String): MutableList<OutputRecord> { | ||
synchronized(lock) { | ||
if (!files.containsKey(filename)) { | ||
files[filename] = mutableListOf() | ||
} | ||
return files[filename]!! | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...lk/core/load/src/test/kotlin/io/airbyte/cdk/mock_integration_test/MockDestinationCheck.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,9 @@ | ||
package io.airbyte.cdk.mock_integration_test | ||
|
||
import io.airbyte.cdk.check.DestinationCheck | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class MockDestinationCheck: DestinationCheck { | ||
override fun check() {} | ||
} |
53 changes: 53 additions & 0 deletions
53
...lk/core/load/src/test/kotlin/io/airbyte/cdk/mock_integration_test/MockDestinationWrite.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,53 @@ | ||
package io.airbyte.cdk.mock_integration_test | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.node.ObjectNode | ||
import io.airbyte.cdk.command.DestinationStream | ||
import io.airbyte.cdk.data.ObjectValue | ||
import io.airbyte.cdk.message.Batch | ||
import io.airbyte.cdk.message.DestinationRecord | ||
import io.airbyte.cdk.message.SimpleBatch | ||
import io.airbyte.cdk.test.util.OutputRecord | ||
import io.airbyte.cdk.write.DestinationWrite | ||
import io.airbyte.cdk.write.StreamLoader | ||
import java.time.Instant | ||
import java.util.UUID | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class MockDestinationWrite : DestinationWrite { | ||
override fun getStreamLoader(stream: DestinationStream): StreamLoader { | ||
return MockStreamLoader(stream) | ||
} | ||
} | ||
|
||
class MockStreamLoader(override val stream: DestinationStream) : StreamLoader { | ||
override suspend fun processRecords( | ||
records: Iterator<DestinationRecord>, | ||
totalSizeBytes: Long | ||
): Batch { | ||
records.forEach { | ||
MockDestinationBackend.insert( | ||
getFilename(it.stream), | ||
OutputRecord( | ||
UUID.randomUUID(), | ||
Instant.ofEpochMilli(it.emittedAtMs), | ||
Instant.ofEpochMilli(System.currentTimeMillis()), | ||
stream.generationId, | ||
it.data as ObjectValue, | ||
ObjectMapper().valueToTree<JsonNode?>(it.meta).also { metaNode -> | ||
(metaNode as ObjectNode).put("sync_id", stream.syncId) | ||
}, | ||
) | ||
) | ||
} | ||
return SimpleBatch(state = Batch.State.COMPLETE) | ||
} | ||
|
||
companion object { | ||
fun getFilename(stream: DestinationStream.Descriptor) = | ||
getFilename(stream.namespace, stream.name) | ||
fun getFilename(namespace: String?, name: String) = "(${namespace},${name})" | ||
} | ||
} |
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,4 @@ | ||
--- | ||
data: | ||
dockerRepository: "airbyte/fake-source" | ||
documentationUrl: "https://docs.airbyte.com" |