Skip to content

Commit

Permalink
feat: add stop() for LocalEvaluationClient
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Dec 11, 2024
1 parent 519ae84 commit 03a824e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/kotlin/LocalEvaluationClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class LocalEvaluationClient internal constructor(
}
}

fun stop() {
deploymentRunner.stop()
}

private fun createAssignmentService(deploymentKey: String): AssignmentService? {
if (config.assignmentConfiguration == null) return null
return AmplitudeAssignmentService(
Expand All @@ -98,6 +102,7 @@ class LocalEvaluationClient internal constructor(
metrics = metrics,
)
}

@JvmOverloads
@Deprecated(
"Use the evaluateV2 method. EvaluateV2 returns variant objects with default values (e.g. null/off) if the user is evaluated, but not assigned a variant.",
Expand Down
17 changes: 17 additions & 0 deletions src/test/kotlin/LocalEvaluationClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class LocalEvaluationClientTest {
val variants = client.evaluate(ExperimentUser(userId = "test_user"))
val variant = variants["sdk-local-evaluation-ci-test"]
Assert.assertEquals(Variant(key = "on", value = "on", payload = "payload"), variant?.copy(metadata = null))
client.stop()
}

@Test
Expand All @@ -53,6 +54,7 @@ class LocalEvaluationClientTest {
)
val variant = variants["this-flag-doesnt-exit"]
Assert.assertNull(variant)
client.stop()
}

@Test
Expand All @@ -65,6 +67,7 @@ class LocalEvaluationClientTest {
val millis = duration / 1000.0 / 1000.0
println("1 flag: $millis")
Assert.assertTrue(millis < 20)
client.stop()
}

@Test
Expand All @@ -80,6 +83,7 @@ class LocalEvaluationClientTest {
val millis = total / 1000.0 / 1000.0
println("10 flags: $millis")
Assert.assertTrue(millis < 40)
client.stop()
}

@Test
Expand All @@ -95,6 +99,7 @@ class LocalEvaluationClientTest {
val millis = total / 1000.0 / 1000.0
println("100 flags: $millis")
Assert.assertTrue(millis < 80)
client.stop()
}

@Test
Expand All @@ -110,6 +115,7 @@ class LocalEvaluationClientTest {
val millis = total / 1000.0 / 1000.0
println("1000 flags: $millis")
Assert.assertTrue(millis < 160)
client.stop()
}

@Test
Expand All @@ -119,6 +125,7 @@ class LocalEvaluationClientTest {
val variants = client.evaluate(ExperimentUser(userId = "user_id", deviceId = "device_id"))
val variant = variants["sdk-ci-local-dependencies-test"]
Assert.assertEquals(variant?.copy(metadata = null), Variant(key = "control", value = "control", payload = null))
client.stop()
}

@Test
Expand All @@ -131,6 +138,7 @@ class LocalEvaluationClientTest {
)
val variant = variants["sdk-ci-local-dependencies-test"]
Assert.assertEquals(variant?.copy(metadata = null), Variant(key = "control", value = "control", payload = null))
client.stop()
}

@Test
Expand All @@ -143,6 +151,7 @@ class LocalEvaluationClientTest {
)
val variant = variants["sdk-ci-local-dependencies-test"]
Assert.assertEquals(variant, null)
client.stop()
}

@Test
Expand All @@ -152,6 +161,7 @@ class LocalEvaluationClientTest {
val variants = client.evaluate(ExperimentUser(userId = "user_id", deviceId = "device_id"))
val variant = variants["sdk-ci-local-dependencies-test-holdout"]
Assert.assertEquals(variant, null)
client.stop()
}

@Test
Expand All @@ -178,6 +188,7 @@ class LocalEvaluationClientTest {
val groupVariant = client.evaluateV2(user, setOf("sdk-local-evaluation-group-cohort-ci-test"))["sdk-local-evaluation-group-cohort-ci-test"]
assertEquals("off", groupVariant?.key)
assertNull(groupVariant?.value)
client.stop()
}

@Test
Expand All @@ -200,6 +211,7 @@ class LocalEvaluationClientTest {
val userVariant = client.evaluateV2(user, setOf("sdk-local-evaluation-user-cohort-ci-test"))["sdk-local-evaluation-user-cohort-ci-test"]
assertEquals("on", userVariant?.key)
assertEquals("on", userVariant?.value)
client.stop()
}

@Test
Expand All @@ -222,6 +234,7 @@ class LocalEvaluationClientTest {
val userVariant = client.evaluateV2(user, setOf("sdk-local-evaluation-user-cohort-ci-test"))["sdk-local-evaluation-user-cohort-ci-test"]
assertEquals("on", userVariant?.key)
assertEquals("on", userVariant?.value)
client.stop()
}

@Test
Expand All @@ -246,6 +259,7 @@ class LocalEvaluationClientTest {
val groupVariant = client.evaluateV2(user, setOf("sdk-local-evaluation-group-cohort-ci-test"))["sdk-local-evaluation-group-cohort-ci-test"]
assertEquals("on", groupVariant?.key)
assertEquals("on", groupVariant?.value)
client.stop()
}

@Test
Expand All @@ -270,6 +284,7 @@ class LocalEvaluationClientTest {
val groupVariant = client.evaluateV2(user, setOf("sdk-local-evaluation-group-cohort-ci-test"))["sdk-local-evaluation-group-cohort-ci-test"]
assertEquals("on", groupVariant?.key)
assertEquals("on", groupVariant?.value)
client.stop()
}

@Test
Expand All @@ -283,6 +298,7 @@ class LocalEvaluationClientTest {
val variants = client.evaluate(ExperimentUser(userId = "test_user"))
val variant = variants["sdk-local-evaluation-ci-test"]
Assert.assertEquals(Variant(key = "on", value = "on", payload = "payload"), variant?.copy(metadata = null))
client.stop()
}

@Test
Expand Down Expand Up @@ -310,5 +326,6 @@ class LocalEvaluationClientTest {
val userVariant = client.evaluateV2(user, setOf("sdk-local-evaluation-user-cohort-ci-test"))["sdk-local-evaluation-user-cohort-ci-test"]
assertEquals("on", userVariant?.key)
assertEquals("on", userVariant?.value)
client.stop()
}
}

0 comments on commit 03a824e

Please sign in to comment.