Skip to content

Commit 5622b49

Browse files
fix: remove CohortNotModifiedException (#24)
* fix: remove CohortNotModifiedException * fix: lint issues
1 parent eca752b commit 5622b49

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dependencies {
5454
// Publishing
5555

5656
group = "com.amplitude"
57-
version = "0.10.0"
57+
version = "0.10.1"
5858

5959
mavenPublishing {
6060
coordinates(

core/src/main/kotlin/cohort/CohortApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ internal class CohortApiV1(
158158
}
159159
log.debug("streamCohort({}): status={}", cohortId, response.status)
160160
when (response.status) {
161-
HttpStatusCode.NoContent -> throw CohortNotModifiedException(cohortId)
161+
HttpStatusCode.NoContent -> return
162162
HttpStatusCode.PayloadTooLarge -> throw CohortTooLargeException(cohortId, maxCohortSize)
163163
else -> {
164164
val input = response.bodyAsChannel().toInputStream()
@@ -205,7 +205,7 @@ internal class CohortApiV1(
205205
val lm = parsedLastModified
206206
if (id != null && lm != null) {
207207
if (lm <= existingLastModified) {
208-
throw CohortNotModifiedException(id)
208+
return
209209
}
210210
}
211211
ensureWriter()

core/src/test/kotlin/cohort/CohortApiTest.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,33 @@ class CohortApiTest {
271271
assertEquals(members.toSet(), stored?.members)
272272
assertEquals(members.size, stored?.size)
273273
}
274+
275+
@Test
276+
fun `streaming cohort 204 no content is a no-op and does not throw`(): Unit =
277+
runBlocking {
278+
val cohortId = "stream-no-content"
279+
val mockEngine =
280+
MockEngine { _ ->
281+
respond(
282+
content = ByteReadChannel(""),
283+
status = HttpStatusCode.NoContent,
284+
)
285+
}
286+
val api = CohortApiV1(serverUrl, apiKey, secretKey, mockEngine)
287+
val storage = com.amplitude.cohort.InMemoryCohortStorage()
288+
289+
// Seed existing cohort to ensure it remains unchanged
290+
val existingDesc = com.amplitude.cohort.CohortDescription(cohortId, "User", 1, 100)
291+
val writer = storage.createWriter(existingDesc)
292+
writer.addMembers(listOf("1"))
293+
writer.complete(1)
294+
295+
// Should not throw and should not change existing data
296+
api.streamCohort(cohortId, 100, Int.MAX_VALUE, storage)
297+
298+
val stored = storage.getCohort(cohortId)
299+
assertEquals(1, stored?.size)
300+
assertEquals(100, stored?.lastModified)
301+
assertEquals(setOf("1"), stored?.members)
302+
}
274303
}

0 commit comments

Comments
 (0)