Skip to content

Commit

Permalink
#40 add test for bulk lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlwilson committed Nov 16, 2021
1 parent a316fcf commit 5dc744e
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/test/kotlin/recce/server/recrun/RecRecordRepositoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@ class RecRecordRepositoryTest {
List(3) { "test" to "test" } +
List(4) { "test" to "test3" }

val setup = runRepository.save(RecRun("test-dataset")).toFlux().flatMap { run ->
var key = 0
Flux.fromIterable(testRecordData)
.flatMap { (source, target) ->
recordRepository.save(RecRecord(RecRecordKey(run.id!!, "${++key}"), source, target))
}
}

val savedRecords = mutableListOf<RecRecord>()
StepVerifier.create(setup)
StepVerifier.create(saveTestRecords(testRecordData))
.recordWith { savedRecords }
.expectNextCount(testRecordData.size.toLong())
.verifyComplete()
Expand All @@ -60,4 +52,28 @@ class RecRecordRepositoryTest {
}
.verifyComplete()
}

private fun saveTestRecords(testRecordData: List<Pair<String?, String?>>): Flux<RecRecord> {
return runRepository.save(RecRun("test-dataset")).toFlux().flatMap { run ->
var key = 0
Flux.fromIterable(testRecordData)
.flatMap { (source, target) ->
recordRepository.save(RecRecord(RecRecordKey(run.id!!, "${++key}"), source, target))
}
}
}

@Test
fun `should bulk check for existence of records`() {
val testRecordData = List(10) { "test" to null }
val savedRecords = mutableListOf<RecRecord>()
StepVerifier.create(saveTestRecords(testRecordData))
.recordWith { savedRecords }
.expectNextCount(testRecordData.size.toLong())
.verifyComplete()

StepVerifier.create(recordRepository.findByIdInList(savedRecords.map { it.id }))
.expectNextCount(10)
.verifyComplete();
}
}

0 comments on commit 5dc744e

Please sign in to comment.