Skip to content

Commit

Permalink
fix: test grpc status on code
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Apr 8, 2022
1 parent 532646e commit b3f0347
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/com/okp4/connect/cosmos/CosmosSourceTask.kt
Expand Up @@ -6,6 +6,7 @@ import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking
import org.apache.kafka.connect.data.Schema
import org.apache.kafka.connect.errors.ConnectException
import org.apache.kafka.connect.errors.RetriableException
import org.apache.kafka.connect.source.SourceRecord
import org.apache.kafka.connect.source.SourceTask
import tendermint.types.BlockOuterClass.Block
Expand Down Expand Up @@ -53,7 +54,7 @@ class CosmosSourceTask : SourceTask() {
.takeWhile { !serviceClient.isClosed() }
.map { serviceClient.getBlockByHeight(it) }
.map { it.getOrThrow() }
.catch { if (it is StatusException && it.status.code != Status.INVALID_ARGUMENT.code) throw it }
.catch { if (it is StatusException && it.status.code != Status.INVALID_ARGUMENT.code) throw RetriableException(it) }
.map { asSourceRecord(it) }
.toList()
}
Expand Down
Expand Up @@ -8,6 +8,7 @@ import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe
import io.mockk.*
import org.apache.kafka.connect.errors.ConnectException
import org.apache.kafka.connect.errors.RetriableException
import tendermint.types.BlockOuterClass
import tendermint.types.Types

Expand Down Expand Up @@ -115,11 +116,11 @@ class CosmosSourceTaskTest : BehaviorSpec({
cosmosSourceTask.start(props)

then("it shall complete exceptionally") {
val thrown = shouldThrow<StatusException> {
val thrown = shouldThrow<RetriableException> {
cosmosSourceTask.poll()
}

thrown.status shouldBe Status.DEADLINE_EXCEEDED
(thrown.cause as StatusException).status shouldBe Status.DEADLINE_EXCEEDED

coVerifyOrder {
cosmosClient.getBlockByHeight(1)
Expand Down

0 comments on commit b3f0347

Please sign in to comment.