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
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class WebCacheContainerClient(mockServerHost: String, mockServerPort: Int) {
.withBody(body, mediaType)
)

fun getSecondaryCacheRecordedRequests(uuidKey: String): Array<out HttpRequest>? =
mockServerClient.retrieveRecordedRequests(getSecondaryCacheRequest(uuidKey))
fun getSecondaryCacheRecordedRequests(uuidKey: String): Array<out HttpRequest>? {
val secondaryCacheRequest = getSecondaryCacheRequest(uuidKey)
waitUntil({ mockServerClient.retrieveRecordedRequests(secondaryCacheRequest)!!.isNotEmpty() })
return mockServerClient.retrieveRecordedRequests(secondaryCacheRequest)
}

fun initSecondaryCacheResponse(): Array<out Expectation>? =
mockServerClient.`when`(getSecondaryCacheRequest())
Expand All @@ -59,4 +62,15 @@ class WebCacheContainerClient(mockServerHost: String, mockServerPort: Int) {
request().withMethod(POST.name())
.withPath("/$WEB_CACHE_PATH")
.withBody(jsonPath("\$.puts[?(@.key == '$uuidKey')]"))

private fun waitUntil(closure: () -> Boolean, timeoutMs: Long = 5000, pollInterval: Long = 100) {
val startTime = System.currentTimeMillis()
while (System.currentTimeMillis() - startTime <= timeoutMs) {
if (closure()) {
return
}
Thread.sleep(pollInterval)
}
throw IllegalStateException("Condition was not fulfilled within $timeoutMs ms.")
}
}