-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bulk Load CDK: Exception Handler for TaskRunner
- Loading branch information
1 parent
477bcc4
commit 4bbfa4e
Showing
7 changed files
with
116 additions
and
8 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
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
73 changes: 73 additions & 0 deletions
73
airbyte-cdk/bulk/core/load/src/test/kotlin/io/airbyte/cdk/write/WriteOperationTest.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,73 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.write | ||
|
||
import io.airbyte.cdk.Operation | ||
import io.airbyte.cdk.task.Task | ||
import io.airbyte.cdk.task.TaskLauncher | ||
import io.airbyte.cdk.task.TaskRunner | ||
import io.micronaut.context.annotation.Property | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
import jakarta.inject.Singleton | ||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.coroutines.withContext | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
@MicronautTest(environments = ["WriteOperationTest"]) | ||
@Property(name = Operation.PROPERTY, value = "write") | ||
class WriteOperationTest { | ||
@Inject lateinit var writeOperation: WriteOperation | ||
|
||
@Singleton | ||
@Requires(env = ["WriteOperationTest"]) | ||
class NoopInputConsumer : InputConsumer<String> { | ||
override suspend fun run() { | ||
// Do nothing | ||
} | ||
} | ||
|
||
@Singleton | ||
@Requires(env = ["WriteOperationTest"]) | ||
class SimpleTaskLauncher(override val taskRunner: TaskRunner) : TaskLauncher { | ||
val handledException = CompletableDeferred<Boolean>() | ||
|
||
override suspend fun start() { | ||
taskRunner.enqueue( | ||
object : Task { | ||
override suspend fun execute() { | ||
throw RuntimeException("Task failed.") | ||
} | ||
} | ||
) | ||
} | ||
|
||
override suspend fun handleException(t: Throwable) { | ||
// Do this with a task to verify that the | ||
// exception workflow can still run tasks. | ||
taskRunner.enqueue( | ||
object : Task { | ||
override suspend fun execute() { | ||
handledException.complete(true) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun testExceptionHandling(simpleTaskLauncher: SimpleTaskLauncher) = runTest { | ||
withContext(Dispatchers.IO) { | ||
launch { writeOperation.execute() } | ||
Assertions.assertTrue(simpleTaskLauncher.handledException.await()) | ||
simpleTaskLauncher.stop() | ||
} | ||
} | ||
} |