Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Bulk load cdk: add checkpointing test #46749

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sealed class AirbyteConnectorRunner(
val testBeanDefinitions: Array<out RuntimeBeanDefinition<*>>,
val testProperties: Map<String, String> = emptyMap(),
) {
val envs: Array<String> = arrayOf(Environment.CLI, connectorType)
val envs: Array<String> = arrayOf(Environment.CLI, connectorType)

inline fun <reified R : Runnable> run() {
val picocliCommandLineFactory = PicocliCommandLineFactory(this)
Expand Down
1 change: 1 addition & 0 deletions airbyte-cdk/bulk/core/load/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1")
implementation "org.jetbrains.kotlin:kotlin-reflect:2.0.20"
testFixturesImplementation "uk.org.webcompere:system-stubs-jupiter:2.1.7"
testFixturesImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1"
}

task integrationTest(type: Test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.time.format.DateTimeFormatter
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject
import kotlin.test.fail
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.apache.commons.lang3.RandomStringUtils
import org.junit.jupiter.api.AfterEach
Expand Down Expand Up @@ -150,7 +150,7 @@ abstract class IntegrationTest(
catalog.asProtocolObject(),
)
return runBlocking {
val destinationCompletion = async { destination.run() }
val destinationCompletion = launch { destination.run() }
messages.forEach { destination.sendMessage(it.asProtocolMessage()) }
if (streamStatus != null) {
catalog.streams.forEach {
Expand All @@ -175,7 +175,7 @@ abstract class IntegrationTest(
}
}
destination.shutdown()
destinationCompletion.await()
destinationCompletion.join()
destination.readMessages()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ interface DestinationProcess {
suspend fun run()

fun sendMessage(message: AirbyteMessage)
fun sendMessages(vararg messages: AirbyteMessage) {
messages.forEach { sendMessage(it) }
}

/** Return all messages the destination emitted since the last call to [readMessages]. */
fun readMessages(): List<AirbyteMessage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import java.time.Clock
import java.util.Locale
import java.util.Scanner
import javax.inject.Singleton
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -183,6 +184,11 @@ class DockerizedDestination(
getMdcScope().use { process.errorReader().forEachLine { logger.error { it } } }
stderrDrained.complete(Unit)
}
}.invokeOnCompletion { cause: Throwable? ->
// TODO does this work correctly?
if (cause is CancellationException) {
process.destroy()
}
}
}

Expand All @@ -196,15 +202,20 @@ class DockerizedDestination(
}

override suspend fun shutdown() {
println("EDGAO DEBUG entered shutdown")
withContext(Dispatchers.IO) {
println("EDGAO DEBUG closing stdin")
destinationStdin.close()
// The old cdk had a 1-minute timeout here. That seems... weird?
// We can just rely on the junit timeout, presumably?
process.waitFor()
// Wait for ourselves to drain stdout/stderr. Otherwise we won't capture
// all the destination output (logs/trace messages).
println("EDGAO DEBUG draining streams")
stdoutDrained.join()
stderrDrained.join()
// The old cdk had a 1-minute timeout here. That seems... weird?
// We can just rely on the junit timeout, presumably?
println("EDGAO DEBUG waiting for process exit")
process.waitFor()
println("EDGAO DEBUG grabbing exit code")
val exitCode = process.exitValue()
if (exitCode != 0) {
// Hey look, it's possible to extract the error from a failed destination process!
Expand All @@ -214,8 +225,10 @@ class DockerizedDestination(
.traces()
.filter { it.type == AirbyteTraceMessage.Type.ERROR }
.map { it.error }
println("EDGAO DEBUG exiting uncleanly: $exitCode, $filteredTraces")
throw DestinationUncleanExitException(exitCode, filteredTraces)
}
println("EDGAO DEBUG exited with exit code: $exitCode")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import java.io.PipedInputStream
import java.io.PipedOutputStream
import java.io.PrintWriter
import javax.inject.Singleton
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class NonDockerizedDestination(
command: String,
Expand Down Expand Up @@ -53,7 +55,9 @@ class NonDockerizedDestination(
}

override suspend fun run() {
destination.run()
withContext(Dispatchers.IO) {
destination.run()
}
}

override fun sendMessage(message: AirbyteMessage) {
Expand Down
Loading
Loading