-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(kafka-standalone: common corotuine handling for kafka)
- Loading branch information
Showing
6 changed files
with
67 additions
and
39 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
45 changes: 45 additions & 0 deletions
45
...g-e2e-kafka/src/main/kotlin/com/trendyol/stove/testing/e2e/standalone/kafka/coroutines.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,45 @@ | ||
package com.trendyol.stove.testing.e2e.standalone.kafka | ||
|
||
import kotlinx.coroutines.* | ||
import java.util.concurrent.* | ||
|
||
val CoroutineScope.asExecutor: Executor | ||
get() = StoveCoroutineExecutor(this) | ||
|
||
val CoroutineScope.asExecutorService: ExecutorService | ||
get() = CoroutineExecutorService(this) | ||
|
||
internal class CoroutineExecutorService(private val coroutineScope: CoroutineScope) : AbstractExecutorService() { | ||
override fun execute(command: Runnable) { | ||
coroutineScope.launch { command.run() } | ||
} | ||
|
||
override fun shutdown() { | ||
coroutineScope.cancel() | ||
} | ||
|
||
override fun shutdownNow(): List<Runnable> { | ||
coroutineScope.cancel() | ||
return emptyList() | ||
} | ||
|
||
override fun isShutdown(): Boolean { | ||
return coroutineScope.coroutineContext[Job]?.isCancelled ?: true | ||
} | ||
|
||
override fun isTerminated(): Boolean { | ||
return coroutineScope.coroutineContext[Job]?.isCompleted ?: true | ||
} | ||
|
||
override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean { | ||
// Coroutine jobs don't support await termination out of the box | ||
// This is a simplified implementation | ||
return isTerminated | ||
} | ||
} | ||
|
||
internal class StoveCoroutineExecutor(private val scope: CoroutineScope) : Executor { | ||
override fun execute(command: Runnable) { | ||
scope.launch { command.run() } | ||
} | ||
} |
10 changes: 6 additions & 4 deletions
10
...src/main/kotlin/com/trendyol/stove/testing/e2e/standalone/kafka/intercepting/GrpcUtils.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
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