Skip to content
Merged
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
22 changes: 19 additions & 3 deletions kbdd/src/main/kotlin/ru/fix/kbdd/rest/Rest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ru.fix.kbdd.json.json
import ru.fix.kbdd.map.MapDsl
import java.io.InputStream
import java.util.concurrent.Executors
import kotlin.coroutines.CoroutineContext

private val log = KotlinLogging.logger { }

Expand All @@ -43,14 +44,29 @@ object Rest {

private val lastResponse = ThreadLocal<Response>()

var threadPoolSize = 10
var restAssuredConfigCustomizer: RestAssuredConfig.() -> RestAssuredConfig = { this }

private val dispatcher by lazy {
Executors.newFixedThreadPool(threadPoolSize).asCoroutineDispatcher() +
var defaultBlockingThreadPoolSize = 10
@Deprecated("Old alias for backward compatibility", ReplaceWith("defaultBlockingThreadPoolSize"))
var threadPoolSize: Int
get() = defaultBlockingThreadPoolSize
set(value) {
defaultBlockingThreadPoolSize = value
}

/**
* Being able to completely override dispatcher for blocking http calls.
* By default, it creates fixed thread pool with [defaultBlockingThreadPoolSize] threads.
*/
var httpBlockingCallsDispatcherProvider: () -> CoroutineContext = {
Executors.newFixedThreadPool(defaultBlockingThreadPoolSize).asCoroutineDispatcher() +
CoroutineExceptionHandler { _, thr -> log.error(thr) {} }
}

private val dispatcher: CoroutineContext by lazy {
httpBlockingCallsDispatcherProvider()
}


/**
* Provides DSL for building HTTP request
Expand Down