diff --git a/core/build.gradle.kts b/core/build.gradle.kts index d490491..216815c 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -54,7 +54,7 @@ dependencies { // Publishing group = "com.amplitude" -version = "0.10.0" +version = "0.10.1" mavenPublishing { coordinates( diff --git a/core/src/main/kotlin/cohort/CohortApi.kt b/core/src/main/kotlin/cohort/CohortApi.kt index 3f347bd..e6c3b63 100644 --- a/core/src/main/kotlin/cohort/CohortApi.kt +++ b/core/src/main/kotlin/cohort/CohortApi.kt @@ -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() @@ -205,7 +205,7 @@ internal class CohortApiV1( val lm = parsedLastModified if (id != null && lm != null) { if (lm <= existingLastModified) { - throw CohortNotModifiedException(id) + return } } ensureWriter() diff --git a/core/src/test/kotlin/cohort/CohortApiTest.kt b/core/src/test/kotlin/cohort/CohortApiTest.kt index dec32e8..4ce05b0 100644 --- a/core/src/test/kotlin/cohort/CohortApiTest.kt +++ b/core/src/test/kotlin/cohort/CohortApiTest.kt @@ -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) + } }