-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bulk-cdk: improve AirbyteConnectorRunner and CliRunner (#45374)
- Loading branch information
Showing
9 changed files
with
164 additions
and
70 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
27 changes: 27 additions & 0 deletions
27
airbyte-cdk/bulk/core/base/src/testFixtures/kotlin/io/airbyte/cdk/command/CliRunnable.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,27 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.command | ||
|
||
import io.airbyte.cdk.output.BufferingOutputConsumer | ||
import io.airbyte.protocol.models.v0.AirbyteMessage | ||
|
||
/** Convenience object for return values in [CliRunner]. */ | ||
data class CliRunnable( | ||
val runnable: Runnable, | ||
val results: BufferingOutputConsumer, | ||
) { | ||
|
||
/** Decorates the [BufferingOutputConsumer] with a callback, which should return quickly. */ | ||
fun withCallback(nonBlockingFn: (AirbyteMessage) -> Unit): CliRunnable { | ||
results.callback = nonBlockingFn | ||
return this | ||
} | ||
|
||
/** Runs the [Runnable]. */ | ||
fun run(): BufferingOutputConsumer { | ||
runnable.run() | ||
return results | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
...dk/bulk/core/base/src/testFixtures/kotlin/io/airbyte/cdk/command/CliRunnerOutputStream.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,50 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.command | ||
|
||
import io.airbyte.cdk.ClockFactory | ||
import io.airbyte.cdk.output.BufferingOutputConsumer | ||
import io.airbyte.cdk.util.Jsons | ||
import io.airbyte.protocol.models.v0.AirbyteMessage | ||
import io.micronaut.context.RuntimeBeanDefinition | ||
import java.io.ByteArrayOutputStream | ||
import java.io.OutputStream | ||
import java.io.PrintStream | ||
|
||
/** Used by [CliRunner] to populate a [BufferingOutputConsumer] instance. */ | ||
class CliRunnerOutputStream : OutputStream() { | ||
|
||
val results = BufferingOutputConsumer(ClockFactory().fixed()) | ||
private val lineStream = ByteArrayOutputStream() | ||
private val printStream = PrintStream(this, true, Charsets.UTF_8) | ||
|
||
val beanDefinition: RuntimeBeanDefinition<PrintStream> = | ||
RuntimeBeanDefinition.builder(PrintStream::class.java) { printStream } | ||
.singleton(true) | ||
.build() | ||
|
||
override fun write(b: Int) { | ||
if (b == '\n'.code) { | ||
readLine() | ||
} else { | ||
lineStream.write(b) | ||
} | ||
} | ||
|
||
override fun close() { | ||
readLine() | ||
lineStream.close() | ||
results.close() | ||
super.close() | ||
} | ||
|
||
private fun readLine() { | ||
val line: String = lineStream.toString(Charsets.UTF_8).trim() | ||
lineStream.reset() | ||
if (line.isNotBlank()) { | ||
results.accept(Jsons.readValue(line, AirbyteMessage::class.java)) | ||
} | ||
} | ||
} |
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.