Skip to content

Commit

Permalink
fix(sql): Simple tests for SqlStorageService.loadObjects()
Browse files Browse the repository at this point in the history
  • Loading branch information
ajordens committed Jul 8, 2019
1 parent 2f4c978 commit 0b2f51a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@ class SqlConfiguration : CommonStorageServiceDAOConfig() {
registry: Registry,
jooq: DSLContext,
sqlProperties: SqlProperties): SqlStorageService =
SqlStorageService(objectMapper, registry, jooq, Clock.systemDefaultZone(), sqlProperties.retries)
SqlStorageService(
objectMapper,
registry,
jooq,
Clock.systemDefaultZone(),
sqlProperties.retries,
1000
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class SqlStorageService(
private val registry: Registry,
private val jooq: DSLContext,
private val clock: Clock,
private val sqlRetryProperties: SqlRetryProperties
private val sqlRetryProperties: SqlRetryProperties,
private val chunkSize: Int
) : StorageService {

companion object {
Expand Down Expand Up @@ -87,7 +88,7 @@ class SqlStorageService(

val timeToLoadObjects = measureTimeMillis {
objects.addAll(
objectKeys.chunked(1000).flatMap { keys ->
objectKeys.chunked(chunkSize).flatMap { keys ->
val bodies = jooq.withRetry(sqlRetryProperties.reads) { ctx ->
ctx
.select(field("body", String::class.java))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ internal object SqlStorageServiceTests : JUnit5Minutests {
NoopRegistry(),
jooq,
Clock.systemDefaultZone(),
SqlRetryProperties()
SqlRetryProperties(),
1
)

fun tests() = rootContext {
Expand Down Expand Up @@ -143,6 +144,34 @@ internal object SqlStorageServiceTests : JUnit5Minutests {
sqlStorageService.loadObject<Pipeline>(ObjectType.PIPELINE, "id-pipeline001")
}
}

test("bulk load pipelines") {
val objectKeys = mutableSetOf<String>()
(1..10).forEach {
val objectKey = "id-pipeline00$it"
objectKeys.add(objectKey)

sqlStorageService.storeObject(
ObjectType.PIPELINE,
objectKey,
Pipeline().apply {
id = objectKey
name = "pipeline00$it"
lastModified = 100

put("application", "application001")
}
)
}

val pipelines = sqlStorageService.loadObjects<Pipeline>(
ObjectType.PIPELINE,
(objectKeys + "does_not_exist").toList()
)
expectThat(
pipelines.map { it.id }.toSet()
).isEqualTo(objectKeys)
}
}

context("Entity Tags") {
Expand Down

0 comments on commit 0b2f51a

Please sign in to comment.