Skip to content

Conversation

@marki1an
Copy link
Collaborator

No description provided.

@marki1an marki1an self-assigned this Sep 15, 2025
@marki1an marki1an added the tests functional Kotlin tests label Sep 15, 2025
Copy link
Collaborator

@osulzhenko osulzhenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it can't do a trick. We need to know exact numbers for metrics because they can still be zero or duplicated. Judging by looks of things, we should either extend the metrics endpoint with an admit /collected-metrics handler or add Graphite to our tests. We should discuss this in the future.

Comment on lines 143 to 159
data class MetricDetail(
val name: String,
val description: String? = null,
val baseUnit: String? = null,
val measurements: List<Measurement>,
val availableTags: List<AvailableTag>
)

data class Measurement(
val statistic: String,
val value: Number
)

data class AvailableTag(
val tag: String,
val values: List<String>
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's part of the model.request package

"storage.aerospike.${applicationName}.max_retry" to "3",
"storage.aerospike.${applicationName}.namespace" to aerospikeNamespace,
"storage.aerospike.${applicationName}.prevent-u-u-i-d-duplication" to preventUuidDuplication.toString(),
"storage.default-ttl-seconds" to 1000L.toString()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically the base config + getAerospikePreventUuidDuplicationConfig, so why not use them?

Copy link
Collaborator Author

@marki1an marki1an Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAerospikePreventUuidDuplicationConfig and storage.aerospike.${applicationName}.prevent-u-u-i-d-duplication different property

Comment on lines +22 to +23
lateinit var apiKey: String
lateinit var applicationName: String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick. We can make apiKey, applicationName and config as constant

val metrics = cacheApi.getMetrics()
assertSoftly {
metrics["pbc.module_storage.read.request"] shouldBe 1
metrics["pbc.module_storage.read.request.duration"] shouldBe 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that measuring request.duration is a correct idea, because it can change from time to time and end up with flakes. We should measure that it exists as a separate // and: block or highlight it in general metrics block

val payloadTransfer = PayloadTransfer.getDefaultJsonPayloadTransfer().apply {
key = payloadKey
application = applicationName
ttlseconds = 300L
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic number

Comment on lines 210 to 260
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<ApiException> { 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
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<ApiException> { 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
metrics["pbc.module_storage.write.request.duration"] shouldBe 2
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should combine them as parameterized tests, same for the others

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we couldn't measure metrics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests functional Kotlin tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants