diff --git a/src/test/kotlin/org/prebid/cache/functional/AerospikeModuleStorageSpec.kt b/src/test/kotlin/org/prebid/cache/functional/AerospikeModuleStorageSpec.kt new file mode 100644 index 00000000..1bbd3ac5 --- /dev/null +++ b/src/test/kotlin/org/prebid/cache/functional/AerospikeModuleStorageSpec.kt @@ -0,0 +1,507 @@ +package org.prebid.cache.functional + +import io.kotest.assertions.assertSoftly +import io.kotest.assertions.throwables.shouldThrowExactly +import io.kotest.core.spec.style.ShouldSpec +import io.kotest.matchers.nulls.beNull +import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.beEmpty +import io.kotest.matchers.string.shouldContain +import java.util.Locale +import org.prebid.cache.functional.BaseSpec.Companion.prebidCacheConfig +import org.prebid.cache.functional.model.request.PayloadTransfer +import org.prebid.cache.functional.service.ApiException +import org.prebid.cache.functional.service.PrebidCacheApi +import org.prebid.cache.functional.util.getRandomLong +import org.prebid.cache.functional.util.getRandomString +import org.springframework.http.HttpStatus.BAD_REQUEST +import org.springframework.http.HttpStatus.NOT_FOUND +import org.springframework.http.HttpStatus.UNAUTHORIZED + +class AerospikeModuleStorageSpec : ShouldSpec({ + + lateinit var apiKey: String + lateinit var applicationName: String + lateinit var cacheApi: PrebidCacheApi + + beforeEach { + apiKey = getRandomString() + applicationName = getRandomString().lowercase(Locale.getDefault()) + val config = prebidCacheConfig.getAerospikeModuleStorageConfig(applicationName, apiKey) + cacheApi = BaseSpec.getPrebidCacheApi(config) + } + + should("return the same text transfer value which was saved to aerospike-module-storage") { + //given: default text payload with application + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = payloadKey + application = applicationName + } + + // when: POST module-storage endpoint is called + cacheApi.postStorageCache(payloadTransfer, apiKey) + + // then: recorded payload should contain the same type and value + val savedPayload = cacheApi.getStorageCache(payloadKey, applicationName, apiKey) + savedPayload.type shouldBe payloadTransfer.type + savedPayload.value shouldBe payloadTransfer.value + + // and: shouldn't contain information about application + savedPayload.application?.should(beNull()) + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.read.request"] shouldBe 1 + metrics["pbc.module_storage.read.text"] shouldBe 1 + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + metrics["pbc.module_storage.read.request.duration"] shouldBe 2 + } + } + + should("return the same xml transfer value which was saved to aerospike-module-storage") { + //given: default xml payload with application + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultXmlPayloadTransfer().apply { + key = payloadKey + application = applicationName + ttlseconds = 400L + } + + // when: POST module-storage endpoint is called + cacheApi.postStorageCache(payloadTransfer, apiKey) + + // then: recorded payload should contain the same type and value + val savedPayload = cacheApi.getStorageCache(payloadKey, applicationName, apiKey) + savedPayload.type shouldBe payloadTransfer.type + savedPayload.value shouldBe payloadTransfer.value + + // and: shouldn't contain information about application + savedPayload.application?.should(beNull()) + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.read.request"] shouldBe 1 + metrics["pbc.module_storage.read.xml"] shouldBe 1 + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + metrics["pbc.module_storage.read.request.duration"] shouldBe 2 + } + } + + should("return the same json transfer value which was saved to aerospike-module-storage") { + //given: default json payload with application + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultJsonPayloadTransfer().apply { + key = payloadKey + application = applicationName + ttlseconds = getRandomLong(300, 1000) + } + + // when: POST module-storage endpoint is called + cacheApi.postStorageCache(payloadTransfer, apiKey) + + // then: recorded payload should contain the same type and value + val savedPayload = cacheApi.getStorageCache(payloadKey, applicationName, apiKey) + savedPayload.type shouldBe payloadTransfer.type + savedPayload.value shouldBe payloadTransfer.value + + // and: shouldn't contain information about application + savedPayload.application?.should(beNull()) + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.read.json"] shouldBe 1 + metrics["pbc.module_storage.read.request"] shouldBe 1 + metrics["pbc.module_storage.write.request"] shouldBe 1 + + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + metrics["pbc.module_storage.read.request.duration"] shouldBe 2 + } + } + + should("throw an exception when post request have nonexistent PBC application name") { + //given: default text payload with nonexistent application name + val payloadKey = getRandomString() + val randomApplication = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = payloadKey + application = randomApplication + } + + // when: POST module-storage endpoint is called + val exception = shouldThrowExactly { + cacheApi.postStorageCache(payloadTransfer, apiKey) + } + + // then: Not found exception is thrown + assertSoftly { + exception.statusCode shouldBe NOT_FOUND.value() + exception.responseBody shouldContain "\"path\":\"/storage\"" + exception.responseBody shouldContain "\"message\":\"Invalid application: ${randomApplication}\"" + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.write.err.badRequest"] shouldBe 1 + metrics["pbc.module_storage.write.err.missingId"] shouldBe 1 + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + } + } + + should("throw an exception when post request have null application name") { + //given: default text payload with null application name + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = payloadKey + application = null + } + + // when: POST module-storage endpoint is called + val exception = shouldThrowExactly { cacheApi.postStorageCache(payloadTransfer, apiKey) } + + // then: Bad request exception is thrown + assertSoftly { + exception.statusCode shouldBe BAD_REQUEST.value() + exception.responseBody shouldContain "\"path\":\"/storage\"" + exception.responseBody shouldContain "application must not be empty" + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.write.err.badRequest"] shouldBe 2 + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + } + } + + should("throw an exception when post request have empty application name") { + //given: default text payload with empty application name + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = payloadKey + application = "" + } + + // when: POST module-storage endpoint is called + val exception = shouldThrowExactly { cacheApi.postStorageCache(payloadTransfer, apiKey) } + + // then: Bad request exception is thrown + assertSoftly { + exception.statusCode shouldBe BAD_REQUEST.value() + exception.responseBody shouldContain "\"path\":\"/storage\"" + exception.responseBody shouldContain "application must not be empty" + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.write.err.badRequest"] shouldBe 2 + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + } + } + + should("throw an exception when post request have null key name") { + //given: default text payload with empty payloadKey + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = null + application = applicationName + } + + // when: POST module-storage endpoint is called + val exception = shouldThrowExactly { cacheApi.postStorageCache(payloadTransfer, apiKey) } + + // then: Bad request exception is thrown + assertSoftly { + exception.statusCode shouldBe BAD_REQUEST.value() + exception.responseBody shouldContain "\"path\":\"/storage\"" + exception.responseBody shouldContain "key must not be empty" + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.write.err.badRequest"] shouldBe 2 + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + } + } + + should("throw an exception when post request have empty key name") { + //given: default text payload with empty payloadKey + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = "" + application = applicationName + } + + // when: POST module-storage endpoint is called + val exception = shouldThrowExactly { cacheApi.postStorageCache(payloadTransfer, apiKey) } + + // then: Bad request exception is thrown + assertSoftly { + exception.statusCode shouldBe BAD_REQUEST.value() + exception.responseBody shouldContain "\"path\":\"/storage\"" + exception.responseBody shouldContain "key must not be empty" + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.write.err.badRequest"] shouldBe 2 + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + } + } + + should("throw an exception when post request have invalid PBC apiKey") { + //given: default text payload with application + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = payloadKey + application = applicationName + } + + // when: POST module-storage endpoint is called + val exception = + shouldThrowExactly { cacheApi.postStorageCache(payloadTransfer, getRandomString()) } + + // then: Not found exception is thrown + assertSoftly { + exception.statusCode shouldBe UNAUTHORIZED.value() + exception.responseBody should beEmpty() + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.write.err.unauthorized"] shouldBe 1 + } + } + + should("throw an exception when get request contain invalid payload key") { + //given: default text payload with application + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = getRandomString() + application = applicationName + } + + // and: POST module-storage endpoint is called + cacheApi.postStorageCache(payloadTransfer, apiKey) + + // when: GET module-storage endpoint is called with invalid data + val exception = shouldThrowExactly { + cacheApi.getStorageCache(getRandomString(), applicationName, apiKey) + } + + // then: Not found exception is thrown + assertSoftly { + exception.statusCode shouldBe NOT_FOUND.value() + exception.responseBody shouldContain "\"path\":\"/storage\"" + exception.responseBody shouldContain "Invalid application or key" + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.read.err.badRequest"] shouldBe 1 + metrics["pbc.module_storage.read.err.missingId"] shouldBe 1 + metrics["pbc.module_storage.read.request"] shouldBe 1 + + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + metrics["pbc.module_storage.read.request.duration"] shouldBe 2 + } + } + + should("throw an exception when get request contain invalid application name") { + //given: default text payload with application + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = payloadKey + application = applicationName + } + + // and: POST module-storage endpoint is called + cacheApi.postStorageCache(payloadTransfer, apiKey) + + //and: random application name + val randomApplication = getRandomString() + + // when: GET module-storage endpoint is called with invalid data + val exception = shouldThrowExactly { + cacheApi.getStorageCache(payloadKey, randomApplication, apiKey) + } + + // then: Not found exception is thrown + assertSoftly { + exception.statusCode shouldBe NOT_FOUND.value() + exception.responseBody shouldContain "\"path\":\"/storage\"" + exception.responseBody shouldContain "\"message\":\"Invalid application: ${randomApplication}\"" + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.read.err.badRequest"] shouldBe 1 + metrics["pbc.module_storage.read.err.missingId"] shouldBe 1 + metrics["pbc.module_storage.read.request"] shouldBe 1 + + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + metrics["pbc.module_storage.read.request.duration"] shouldBe 2 + } + } + + should("throw an exception when get request contain invalid apiKey") { + //given: default text payload with application + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultTextPayloadTransfer().apply { + key = payloadKey + application = applicationName + } + + // and: POST module-storage endpoint is called + cacheApi.postStorageCache(payloadTransfer, apiKey) + + // when: GET module-storage endpoint is called with invalid data + val exception = shouldThrowExactly { + cacheApi.getStorageCache(payloadKey, applicationName, getRandomString()) + } + + // then: Not found exception is thrown + assertSoftly { + exception.statusCode shouldBe UNAUTHORIZED.value() + exception.responseBody should beEmpty() + } + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.read.err.unauthorized"] shouldBe 1 + + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + } + } + + should("not throw an exception when ttlsecond is zero") { + //given: default json payload with application + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultJsonPayloadTransfer().apply { + key = payloadKey + application = applicationName + ttlseconds = 0 + } + + // when: POST module-storage endpoint is called + cacheApi.postStorageCache(payloadTransfer, apiKey) + + // then: recorded payload should contain the same type and value + val savedPayload = cacheApi.getStorageCache(payloadKey, applicationName, apiKey) + savedPayload.type shouldBe payloadTransfer.type + savedPayload.value shouldBe payloadTransfer.value + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.read.json"] shouldBe 1 + metrics["pbc.module_storage.read.request"] shouldBe 1 + + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + metrics["pbc.module_storage.read.request.duration"] shouldBe 2 + } + } + + should("not throw an exception when ttlsecond is null and config ttlseconds are present") { + //given: default json payload with application + val payloadKey = getRandomString() + val payloadTransfer = PayloadTransfer.getDefaultJsonPayloadTransfer().apply { + key = payloadKey + application = applicationName + ttlseconds = null + } + + // when: POST module-storage endpoint is called + cacheApi.postStorageCache(payloadTransfer, apiKey) + + // then: recorded payload should contain the same type and value + val savedPayload = cacheApi.getStorageCache(payloadKey, applicationName, apiKey) + savedPayload.type shouldBe payloadTransfer.type + savedPayload.value shouldBe payloadTransfer.value + + // and: shouldn't contain information about application + savedPayload.application?.should(beNull()) + + // and: pbc should populate corresponding metrics + val metrics = cacheApi.getMetrics() + assertSoftly { + metrics["pbc.module_storage.read.json"] shouldBe 1 + metrics["pbc.module_storage.read.request"] shouldBe 1 + + metrics["pbc.module_storage.write.request"] shouldBe 1 + } + + // and: pbc should populate time metrics + assertSoftly { + metrics["pbc.module_storage.write.request.duration"] shouldBe 2 + metrics["pbc.module_storage.read.request.duration"] shouldBe 2 + } + } +}) diff --git a/src/test/kotlin/org/prebid/cache/functional/GeneralCacheSpec.kt b/src/test/kotlin/org/prebid/cache/functional/GeneralCacheSpec.kt index 1a28a63f..b477aff1 100644 --- a/src/test/kotlin/org/prebid/cache/functional/GeneralCacheSpec.kt +++ b/src/test/kotlin/org/prebid/cache/functional/GeneralCacheSpec.kt @@ -122,7 +122,7 @@ class GeneralCacheSpec : ShouldSpec({ val postResponse = prebidCacheApi.postCache(requestObject) // when: GET cache endpoint is called - val getCacheResponse = BaseSpec.getPrebidCacheApi().getCache(postResponse.responses[0].uuid) + val getCacheResponse = prebidCacheApi.getCache(postResponse.responses[0].uuid) // then: response content type is the same as request object type getCacheResponse.contentType()?.contentType shouldBe "application" diff --git a/src/test/kotlin/org/prebid/cache/functional/StorageSpec.kt b/src/test/kotlin/org/prebid/cache/functional/RedisModuleStorageSpec.kt similarity index 97% rename from src/test/kotlin/org/prebid/cache/functional/StorageSpec.kt rename to src/test/kotlin/org/prebid/cache/functional/RedisModuleStorageSpec.kt index 09600cae..6e7b4eeb 100644 --- a/src/test/kotlin/org/prebid/cache/functional/StorageSpec.kt +++ b/src/test/kotlin/org/prebid/cache/functional/RedisModuleStorageSpec.kt @@ -12,13 +12,14 @@ import org.prebid.cache.functional.BaseSpec.Companion.prebidCacheConfig import org.prebid.cache.functional.model.request.PayloadTransfer import org.prebid.cache.functional.service.ApiException import org.prebid.cache.functional.service.PrebidCacheApi +import org.prebid.cache.functional.util.getRandomLong import org.prebid.cache.functional.util.getRandomString import org.springframework.http.HttpStatus.BAD_REQUEST import org.springframework.http.HttpStatus.NOT_FOUND import org.springframework.http.HttpStatus.UNAUTHORIZED import org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR -class StorageSpec : ShouldSpec({ +class RedisModuleStorageSpec : ShouldSpec({ lateinit var apiKey: String lateinit var applicationName: String @@ -27,7 +28,7 @@ class StorageSpec : ShouldSpec({ beforeSpec { apiKey = getRandomString() applicationName = getRandomString().lowercase(Locale.getDefault()) - val config = prebidCacheConfig.getBaseModuleStorageConfig(applicationName, apiKey) + val config = prebidCacheConfig.getRedisModuleStorageConfig(applicationName, apiKey) cacheApi = BaseSpec.getPrebidCacheApi(config) } @@ -78,7 +79,7 @@ class StorageSpec : ShouldSpec({ val payloadTransfer = PayloadTransfer.getDefaultJsonPayloadTransfer().apply { key = payloadKey application = applicationName - ttlseconds = 300L + ttlseconds = getRandomLong(300, 1000) } // when: POST module-storage endpoint is called @@ -104,7 +105,8 @@ class StorageSpec : ShouldSpec({ // when: POST module-storage endpoint is called val exception = shouldThrowExactly { - cacheApi.postStorageCache(payloadTransfer, apiKey) } + cacheApi.postStorageCache(payloadTransfer, apiKey) + } // then: Not found exception is thrown assertSoftly { @@ -291,7 +293,8 @@ class StorageSpec : ShouldSpec({ // when: POST module-storage endpoint is called val exception = shouldThrowExactly { - cacheApi.postStorageCache(payloadTransfer, apiKey) } + cacheApi.postStorageCache(payloadTransfer, apiKey) + } // then: Expire time exception is thrown assertSoftly { diff --git a/src/test/kotlin/org/prebid/cache/functional/model/request/AvailableTag.kt b/src/test/kotlin/org/prebid/cache/functional/model/request/AvailableTag.kt new file mode 100644 index 00000000..f9dc9de7 --- /dev/null +++ b/src/test/kotlin/org/prebid/cache/functional/model/request/AvailableTag.kt @@ -0,0 +1,6 @@ +package org.prebid.cache.functional.model.request + +data class AvailableTag( + val tag: String, + val values: List +) diff --git a/src/test/kotlin/org/prebid/cache/functional/model/request/Measurement.kt b/src/test/kotlin/org/prebid/cache/functional/model/request/Measurement.kt new file mode 100644 index 00000000..f2f583b0 --- /dev/null +++ b/src/test/kotlin/org/prebid/cache/functional/model/request/Measurement.kt @@ -0,0 +1,6 @@ +package org.prebid.cache.functional.model.request + +data class Measurement( + val statistic: String, + val value: Number +) diff --git a/src/test/kotlin/org/prebid/cache/functional/model/request/MetricDetail.kt b/src/test/kotlin/org/prebid/cache/functional/model/request/MetricDetail.kt new file mode 100644 index 00000000..c69ab41f --- /dev/null +++ b/src/test/kotlin/org/prebid/cache/functional/model/request/MetricDetail.kt @@ -0,0 +1,9 @@ +package org.prebid.cache.functional.model.request + +data class MetricDetail( + val name: String, + val description: String? = null, + val baseUnit: String? = null, + val measurements: List, + val availableTags: List +) diff --git a/src/test/kotlin/org/prebid/cache/functional/service/PrebidCacheApi.kt b/src/test/kotlin/org/prebid/cache/functional/service/PrebidCacheApi.kt index 7cc55ffe..9019c642 100644 --- a/src/test/kotlin/org/prebid/cache/functional/service/PrebidCacheApi.kt +++ b/src/test/kotlin/org/prebid/cache/functional/service/PrebidCacheApi.kt @@ -19,6 +19,7 @@ import io.ktor.http.ContentType.Application.Json import io.ktor.http.HttpHeaders.ContentType import io.ktor.http.HttpStatusCode import io.ktor.serialization.jackson.jackson +import org.prebid.cache.functional.model.request.MetricDetail import org.prebid.cache.functional.model.request.PayloadTransfer import org.prebid.cache.functional.model.request.RequestObject import org.prebid.cache.functional.model.response.ResponseObject @@ -113,6 +114,19 @@ class PrebidCacheApi( } } + suspend fun getMetrics(): Map { + val response: Map> = get(endpoint = METRICS_ENDPOINT).body() + val metricNames = response["names"] ?: emptyList() + val results: List> = metricNames.map { name -> + val detail: MetricDetail = get(endpoint = "$METRICS_ENDPOINT/$name").body() + val countValue = detail.measurements + .firstOrNull { it.statistic == "COUNT" } + ?.value?.toInt() ?: 0 + name to countValue + } + return results.toMap() + } + companion object { private const val CACHE_ENDPOINT = "/cache" private const val UUID_QUERY_PARAMETER = "uuid" @@ -123,5 +137,7 @@ class PrebidCacheApi( private const val API_KEY_PARAMETER = "x-pbc-api-key" private const val KEY_PARAMETER = "k" private const val APPLICATION_PARAMETER = "a" + + private const val METRICS_ENDPOINT = "/metrics" } } diff --git a/src/test/kotlin/org/prebid/cache/functional/testcontainers/PrebidCacheContainerConfig.kt b/src/test/kotlin/org/prebid/cache/functional/testcontainers/PrebidCacheContainerConfig.kt index c18b5a29..ba996bd3 100644 --- a/src/test/kotlin/org/prebid/cache/functional/testcontainers/PrebidCacheContainerConfig.kt +++ b/src/test/kotlin/org/prebid/cache/functional/testcontainers/PrebidCacheContainerConfig.kt @@ -35,10 +35,18 @@ class PrebidCacheContainerConfig( ): Map = getBaseConfig(allowExternalUuid, cacheWriteSecured) + getApacheIgniteConfig(ingineCacheName) - fun getBaseModuleStorageConfig(applicationName: String, apiKey: String): Map = + fun getRedisModuleStorageConfig(applicationName: String, apiKey: String): Map = getBaseConfig(allowExternalUuid = true, apiKey = apiKey) + getModuleStorageRedisConfig(applicationName) + getRedisConfig() + fun getAerospikeModuleStorageConfig( + applicationName: String, + apiKey: String, + aerospikeNamespace: String = NAMESPACE + ): Map = getBaseConfig(allowExternalUuid = true, apiKey = apiKey) + + getModuleStorageAerospikeConfig(applicationName) + + getAerospikeConfig(aerospikeNamespace) + fun getCacheExpiryConfig(minExpiry: String = "15", maxExpiry: String = "28800"): Map = mapOf( "cache.min.expiry" to minExpiry, @@ -92,12 +100,29 @@ class PrebidCacheContainerConfig( private fun getModuleStorageRedisConfig( applicationName: String, - timeoutMs: Long = 9999L, ): Map = mapOf( "storage.redis.${applicationName}.port" to RedisContainer.PORT.toString(), "storage.redis.${applicationName}.host" to redisHost, - "storage.redis.${applicationName}.timeout" to timeoutMs.toString(), + "storage.redis.${applicationName}.timeout" to "9999", + "storage.default-ttl-seconds" to 1000L.toString() + ) + + private fun getModuleStorageAerospikeConfig( + applicationName: String, + preventUuidDuplication: Boolean = false, + ): Map = + mapOf( + "storage.aerospike.${applicationName}.port" to AerospikeContainer.PORT.toString(), + "storage.aerospike.${applicationName}.host" to aerospikeHost, + "storage.aerospike.${applicationName}.cores" to "4", + "storage.aerospike.${applicationName}.timeout" to "9999", + "storage.aerospike.${applicationName}.password" to "", + "storage.aerospike.${applicationName}.first_backoff" to "300", + "storage.aerospike.${applicationName}.max_backoff" to "1000", + "storage.aerospike.${applicationName}.max_retry" to "3", + "storage.aerospike.${applicationName}.namespace" to NAMESPACE, + "storage.aerospike.${applicationName}.prevent-u-u-i-d-duplication" to preventUuidDuplication.toString(), "storage.default-ttl-seconds" to 1000L.toString() ) diff --git a/src/test/kotlin/org/prebid/cache/functional/util/PrebidCacheUtil.kt b/src/test/kotlin/org/prebid/cache/functional/util/PrebidCacheUtil.kt index d20b8dc0..4b4acf75 100644 --- a/src/test/kotlin/org/prebid/cache/functional/util/PrebidCacheUtil.kt +++ b/src/test/kotlin/org/prebid/cache/functional/util/PrebidCacheUtil.kt @@ -1,6 +1,7 @@ package org.prebid.cache.functional.util -import java.util.* +import java.util.UUID +import java.util.Random fun getRandomUuid(): String = UUID.randomUUID().toString() @@ -9,4 +10,4 @@ fun getRandomString(length: Int = 16): String { return List(length) { allowedChars.random() }.joinToString("") } -fun getRandomLong(length: Int = 16): Long = Random().nextInt(length).toLong() +fun getRandomLong(start: Int = 0, end: Int = 16): Long = Random().nextInt(start, end).toLong()