Skip to content

Commit 64651ad

Browse files
feat(lapis): return empty lineage definitions when SILO returns an empty file (#1126)
follow up to #1117
1 parent d206dc4 commit 64651ad

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

lapis/src/main/kotlin/org/genspectrum/lapis/silo/SiloClient.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ open class CachedSiloClient(
128128
) { it.GET() }
129129

130130
val body = response.body()
131+
132+
if (body.isBlank()) {
133+
return emptyMap()
134+
}
135+
131136
try {
132137
return yamlObjectMapper.objectMapper.readValue(body)
133138
} catch (e: Exception) {

lapis/src/test/kotlin/org/genspectrum/lapis/silo/SiloClientTest.kt

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class SiloClientTest(
5454

5555
private var counter = 0
5656

57+
private val columnName = "test_column"
58+
5759
@BeforeEach
5860
fun setup() {
5961
mockServer = ClientAndServer.startClientAndServer(MOCK_SERVER_PORT)
@@ -439,31 +441,19 @@ class SiloClientTest(
439441

440442
@Test
441443
fun `get lineage definition`() {
442-
val columnName = "test_column"
443-
MockServerClient("localhost", MOCK_SERVER_PORT)
444-
.`when`(
445-
request()
446-
.withMethod("GET")
447-
.withPath("/lineageDefinition/$columnName")
448-
.withHeader("X-Request-Id", REQUEST_ID_VALUE),
449-
)
450-
.respond(
451-
response()
452-
.withStatusCode(200)
453-
.withBody(
454-
"""
455-
A: {}
456-
A.1:
457-
parents:
458-
- A
459-
B:
460-
aliases:
461-
- A.1.1
462-
parents:
463-
- A.1
464-
""".trimIndent(),
465-
),
466-
)
444+
expectLineageDefinitionRequestAndRespondWith(
445+
"""
446+
A: {}
447+
A.1:
448+
parents:
449+
- A
450+
B:
451+
aliases:
452+
- A.1.1
453+
parents:
454+
- A.1
455+
""".trimIndent(),
456+
)
467457

468458
val actual = underTest.getLineageDefinition(columnName)
469459

@@ -479,9 +469,24 @@ class SiloClientTest(
479469
)
480470
}
481471

472+
@Test
473+
fun `GIVEN silo returns empty lineage definition file THEN returns empty object`() {
474+
expectLineageDefinitionRequestAndRespondWith("")
475+
476+
val actual = underTest.getLineageDefinition(columnName)
477+
478+
assertThat(actual, equalTo(emptyMap()))
479+
}
480+
482481
@Test
483482
fun `GIVEN silo returns invalid lineage definition file THEN returns appropriate error`() {
484-
val columnName = "test_column"
483+
expectLineageDefinitionRequestAndRespondWith("not an object")
484+
485+
val exception = assertThrows<RuntimeException> { underTest.getLineageDefinition(columnName) }
486+
assertThat(exception.message, containsString("Failed to parse lineage definition from SILO: "))
487+
}
488+
489+
private fun expectLineageDefinitionRequestAndRespondWith(lineageDefinition: String) {
485490
MockServerClient("localhost", MOCK_SERVER_PORT)
486491
.`when`(
487492
request()
@@ -492,11 +497,8 @@ class SiloClientTest(
492497
.respond(
493498
response()
494499
.withStatusCode(200)
495-
.withBody(""),
500+
.withBody(lineageDefinition),
496501
)
497-
498-
val exception = assertThrows<RuntimeException> { underTest.getLineageDefinition(columnName) }
499-
assertThat(exception.message, containsString("Failed to parse lineage definition from SILO: "))
500502
}
501503

502504
companion object {

0 commit comments

Comments
 (0)