Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {
// Publishing

group = "com.amplitude"
version = "0.10.0"
version = "0.10.1"

mavenPublishing {
coordinates(
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/kotlin/cohort/CohortApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal class CohortApiV1(
}
log.debug("streamCohort({}): status={}", cohortId, response.status)
when (response.status) {
HttpStatusCode.NoContent -> throw CohortNotModifiedException(cohortId)
HttpStatusCode.NoContent -> return
HttpStatusCode.PayloadTooLarge -> throw CohortTooLargeException(cohortId, maxCohortSize)
else -> {
val input = response.bodyAsChannel().toInputStream()
Expand Down Expand Up @@ -205,7 +205,7 @@ internal class CohortApiV1(
val lm = parsedLastModified
if (id != null && lm != null) {
if (lm <= existingLastModified) {
throw CohortNotModifiedException(id)
return
}
}
ensureWriter()
Expand Down
29 changes: 29 additions & 0 deletions core/src/test/kotlin/cohort/CohortApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,33 @@ class CohortApiTest {
assertEquals(members.toSet(), stored?.members)
assertEquals(members.size, stored?.size)
}

@Test
fun `streaming cohort 204 no content is a no-op and does not throw`(): Unit =
runBlocking {
val cohortId = "stream-no-content"
val mockEngine =
MockEngine { _ ->
respond(
content = ByteReadChannel(""),
status = HttpStatusCode.NoContent,
)
}
val api = CohortApiV1(serverUrl, apiKey, secretKey, mockEngine)
val storage = com.amplitude.cohort.InMemoryCohortStorage()

// Seed existing cohort to ensure it remains unchanged
val existingDesc = com.amplitude.cohort.CohortDescription(cohortId, "User", 1, 100)
val writer = storage.createWriter(existingDesc)
writer.addMembers(listOf("1"))
writer.complete(1)

// Should not throw and should not change existing data
api.streamCohort(cohortId, 100, Int.MAX_VALUE, storage)

val stored = storage.getCohort(cohortId)
assertEquals(1, stored?.size)
assertEquals(100, stored?.lastModified)
assertEquals(setOf("1"), stored?.members)
}
}