-
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
13 changed files
with
262 additions
and
11 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
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 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.mock_integration_test | ||
|
||
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( | ||
MockDestinationSpecification(), | ||
MockDestinationDataDumper, | ||
NoopDestinationCleaner, | ||
NoopExpectedRecordMapper, | ||
NoopNameMapper | ||
) |
40 changes: 40 additions & 0 deletions
40
...src/integrationTest/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,40 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.mock_integration_test | ||
|
||
import io.airbyte.cdk.test.util.DestinationDataDumper | ||
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> { | ||
return synchronized(lock) { | ||
getFile(filename) | ||
} | ||
} | ||
|
||
private fun getFile(filename: String): MutableList<OutputRecord> { | ||
return synchronized(lock) { | ||
if (!files.containsKey(filename)) { | ||
files[filename] = mutableListOf() | ||
} | ||
files[filename]!! | ||
} | ||
} | ||
} | ||
|
||
object MockDestinationDataDumper : DestinationDataDumper { | ||
override fun dumpRecords(streamName: String, streamNamespace: String?): List<OutputRecord> { | ||
return MockDestinationBackend.readFile( | ||
MockStreamLoader.getFilename(streamNamespace, streamName) | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...src/integrationTest/kotlin/io/airbyte/cdk/mock_integration_test/MockDestinationChecker.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,13 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.mock_integration_test | ||
|
||
import io.airbyte.cdk.check.DestinationChecker | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class MockDestinationChecker : DestinationChecker<MockDestinationConfiguration> { | ||
override fun check(config: MockDestinationConfiguration) {} | ||
} |
34 changes: 34 additions & 0 deletions
34
...tegrationTest/kotlin/io/airbyte/cdk/mock_integration_test/MockDestinationConfiguration.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,34 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.mock_integration_test | ||
|
||
import io.airbyte.cdk.command.ConfigurationJsonObjectBase | ||
import io.airbyte.cdk.command.DestinationConfiguration | ||
import io.airbyte.cdk.command.DestinationConfigurationFactory | ||
import io.micronaut.context.annotation.Factory | ||
import jakarta.inject.Singleton | ||
|
||
class MockDestinationConfiguration : DestinationConfiguration() | ||
|
||
@Singleton class MockDestinationSpecification : ConfigurationJsonObjectBase() | ||
|
||
@Singleton | ||
class MockDestinationConfigurationFactory : | ||
DestinationConfigurationFactory<MockDestinationSpecification, MockDestinationConfiguration> { | ||
|
||
override fun makeWithoutExceptionHandling( | ||
pojo: MockDestinationSpecification | ||
): MockDestinationConfiguration { | ||
return MockDestinationConfiguration() | ||
} | ||
} | ||
|
||
@Factory | ||
class MockDestinationConfigurationProvider(private val config: DestinationConfiguration) { | ||
@Singleton | ||
fun get(): MockDestinationConfiguration { | ||
return config as MockDestinationConfiguration | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
.../src/integrationTest/kotlin/io/airbyte/cdk/mock_integration_test/MockDestinationWriter.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,69 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.mock_integration_test | ||
|
||
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.DestinationWriter | ||
import io.airbyte.cdk.write.StreamLoader | ||
import java.time.Instant | ||
import java.util.UUID | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class MockDestinationWriter : DestinationWriter { | ||
override fun getStreamLoader(stream: DestinationStream): StreamLoader { | ||
return MockStreamLoader(stream) | ||
} | ||
} | ||
|
||
class MockStreamLoader(override val stream: DestinationStream) : StreamLoader { | ||
data class LocalBatch(val records: List<DestinationRecord>): Batch { | ||
override val state = Batch.State.LOCAL | ||
} | ||
data class PersistedBatch(val records: List<DestinationRecord>): Batch { | ||
override val state = Batch.State.PERSISTED | ||
} | ||
|
||
override suspend fun processRecords( | ||
records: Iterator<DestinationRecord>, | ||
totalSizeBytes: Long | ||
): Batch { | ||
return LocalBatch(records.asSequence().toList()) | ||
} | ||
|
||
override suspend fun processBatch(batch: Batch): Batch { | ||
return when (batch) { | ||
is LocalBatch -> { | ||
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, | ||
OutputRecord.Meta(changes = it.meta?.changes, syncId = stream.syncId), | ||
) | ||
) | ||
} | ||
PersistedBatch(batch.records) | ||
} | ||
is PersistedBatch -> SimpleBatch(state = Batch.State.COMPLETE) | ||
else -> throw IllegalStateException("Unexpected batch type: $batch") | ||
} | ||
} | ||
|
||
companion object { | ||
fun getFilename(stream: DestinationStream.Descriptor) = | ||
getFilename(stream.namespace, stream.name) | ||
fun getFilename(namespace: String?, name: String) = "(${namespace},${name})" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
airbyte-cdk/bulk/core/load/src/integrationTest/resources/metadata.yaml
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,5 @@ | ||
# This is a minimal metadata.yaml that allows a destination connector to run. | ||
# A real metadata.yaml obviously contains much more stuff, but we don't strictly | ||
# need any of it at runtime. | ||
data: | ||
dockerRepository: "airbyte/fake-destination" |
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