From 7aabc6f7e1859f3b3a679eeaccc17a8266bc3eb2 Mon Sep 17 00:00:00 2001 From: Brian Giori Date: Tue, 23 Jul 2024 10:27:36 -0700 Subject: [PATCH] fix: lint, test --- evaluation-core/build.gradle.kts | 23 ++++++++ .../commonMain/kotlin/EvaluationAllocation.kt | 2 +- .../src/commonMain/kotlin/EvaluationBucket.kt | 2 +- .../kotlin/EvaluationDistribution.kt | 2 +- .../src/commonMain/kotlin/EvaluationEngine.kt | 2 +- .../kotlin/EvaluationSerialization.kt | 4 +- .../commonMain/kotlin/EvaluationVariant.kt | 2 +- .../src/commonMain/kotlin/TopologicalSort.kt | 2 +- .../kotlin/EvaluationIntegrationTest.kt | 53 +++++++++++-------- .../kotlin/EvaluationSerializationTest.kt | 6 ++- ...urEnglishTest.kt => Murmur3EnglishTest.kt} | 6 +-- .../src/commonTest/kotlin/SelectableTest.kt | 7 ++- .../commonTest/kotlin/TopologicalSortTest.kt | 44 +++++++-------- .../src/commonMain/kotlin/Evaluation.kt | 2 +- 14 files changed, 96 insertions(+), 61 deletions(-) rename evaluation-core/src/commonTest/kotlin/{MurMurEnglishTest.kt => Murmur3EnglishTest.kt} (96%) diff --git a/evaluation-core/build.gradle.kts b/evaluation-core/build.gradle.kts index 58eae0d..90328ed 100644 --- a/evaluation-core/build.gradle.kts +++ b/evaluation-core/build.gradle.kts @@ -39,7 +39,30 @@ kotlin { dependencies { implementation(kotlin("test")) implementation("io.ktor:ktor-client-core:$ktorVersion") + } + } + val jvmTest by getting { + dependencies { implementation("io.ktor:ktor-client-cio:$ktorVersion") + } + } + val macosArm64Test by getting { + dependencies { + implementation("io.ktor:ktor-client-curl:$ktorVersion") + } + } + val macosX64Test by getting { + dependencies { + implementation("io.ktor:ktor-client-curl:$ktorVersion") + } + } + val linuxArm64Test by getting { + dependencies { + implementation("io.ktor:ktor-client-curl:$ktorVersion") + } + } + val linuxX64Test by getting { + dependencies { implementation("io.ktor:ktor-client-curl:$ktorVersion") } } diff --git a/evaluation-core/src/commonMain/kotlin/EvaluationAllocation.kt b/evaluation-core/src/commonMain/kotlin/EvaluationAllocation.kt index bfbc6f8..ce08446 100644 --- a/evaluation-core/src/commonMain/kotlin/EvaluationAllocation.kt +++ b/evaluation-core/src/commonMain/kotlin/EvaluationAllocation.kt @@ -13,5 +13,5 @@ data class EvaluationAllocation( val range: List, // The distribution of variants if allocated. - val distributions: List, + val distributions: List ) diff --git a/evaluation-core/src/commonMain/kotlin/EvaluationBucket.kt b/evaluation-core/src/commonMain/kotlin/EvaluationBucket.kt index b40814f..6e8ed0f 100644 --- a/evaluation-core/src/commonMain/kotlin/EvaluationBucket.kt +++ b/evaluation-core/src/commonMain/kotlin/EvaluationBucket.kt @@ -12,5 +12,5 @@ data class EvaluationBucket( // Determines which variant, if any, should be returned based on the // result of the hash functions. - val allocations: List, + val allocations: List ) diff --git a/evaluation-core/src/commonMain/kotlin/EvaluationDistribution.kt b/evaluation-core/src/commonMain/kotlin/EvaluationDistribution.kt index 158f041..5598f11 100644 --- a/evaluation-core/src/commonMain/kotlin/EvaluationDistribution.kt +++ b/evaluation-core/src/commonMain/kotlin/EvaluationDistribution.kt @@ -9,5 +9,5 @@ data class EvaluationDistribution( // The distribution range [start, end), where the max value is 42949672. // E.g. [0, 42949673] = [0%, 100%] - val range: List, + val range: List ) diff --git a/evaluation-core/src/commonMain/kotlin/EvaluationEngine.kt b/evaluation-core/src/commonMain/kotlin/EvaluationEngine.kt index b3045dd..f194273 100644 --- a/evaluation-core/src/commonMain/kotlin/EvaluationEngine.kt +++ b/evaluation-core/src/commonMain/kotlin/EvaluationEngine.kt @@ -266,7 +266,7 @@ class EvaluationEngineImpl(private val log: Logger? = null) : EvaluationEngine { propValue: String, op: String, filterValues: Set, - transformer: (String) -> T?, + transformer: (String) -> T? ): Boolean { val propValueTransformed: T? = transformer.invoke(propValue) val filterValuesTransformed: Set = filterValues.mapNotNull(transformer).toSet() diff --git a/evaluation-core/src/commonMain/kotlin/EvaluationSerialization.kt b/evaluation-core/src/commonMain/kotlin/EvaluationSerialization.kt index 6fa519d..565901c 100644 --- a/evaluation-core/src/commonMain/kotlin/EvaluationSerialization.kt +++ b/evaluation-core/src/commonMain/kotlin/EvaluationSerialization.kt @@ -15,8 +15,6 @@ import kotlinx.serialization.json.contentOrNull import kotlinx.serialization.json.doubleOrNull import kotlinx.serialization.json.intOrNull import kotlinx.serialization.json.longOrNull -import kotlin.jvm.JvmField -import kotlin.jvm.JvmSynthetic internal val json = Json { ignoreUnknownKeys = true @@ -40,7 +38,7 @@ internal fun Collection<*>.toJsonArray(): JsonArray = JsonArray(map { it.toJsonE internal fun Map<*, *>.toJsonObject(): JsonObject = JsonObject( mapNotNull { (it.key as? String ?: return@mapNotNull null) to it.value.toJsonElement() - }.toMap(), + }.toMap() ) internal fun JsonElement.toAny(): Any? { diff --git a/evaluation-core/src/commonMain/kotlin/EvaluationVariant.kt b/evaluation-core/src/commonMain/kotlin/EvaluationVariant.kt index bdd63e5..cda54a7 100644 --- a/evaluation-core/src/commonMain/kotlin/EvaluationVariant.kt +++ b/evaluation-core/src/commonMain/kotlin/EvaluationVariant.kt @@ -10,7 +10,7 @@ data class EvaluationVariant( val key: String, val value: Any? = null, val payload: Any? = null, - val metadata: Map? = null, + val metadata: Map? = null ) : Selectable { override fun select(selector: String): Any? { return when (selector) { diff --git a/evaluation-core/src/commonMain/kotlin/TopologicalSort.kt b/evaluation-core/src/commonMain/kotlin/TopologicalSort.kt index 0a1e365..ee4eee1 100644 --- a/evaluation-core/src/commonMain/kotlin/TopologicalSort.kt +++ b/evaluation-core/src/commonMain/kotlin/TopologicalSort.kt @@ -33,7 +33,7 @@ fun topologicalSort( private fun parentTraversal( flagKey: String, available: MutableMap, - path: MutableSet = mutableSetOf(), + path: MutableSet = mutableSetOf() ): List? { val flag = available[flagKey] ?: return null if (flag.dependencies.isNullOrEmpty()) { diff --git a/evaluation-core/src/commonTest/kotlin/EvaluationIntegrationTest.kt b/evaluation-core/src/commonTest/kotlin/EvaluationIntegrationTest.kt index 5c52a99..74f25df 100644 --- a/evaluation-core/src/commonTest/kotlin/EvaluationIntegrationTest.kt +++ b/evaluation-core/src/commonTest/kotlin/EvaluationIntegrationTest.kt @@ -4,9 +4,6 @@ import com.amplitude.experiment.evaluation.util.FlagApi import kotlinx.coroutines.runBlocking import kotlin.test.DefaultAsserter import kotlin.test.Test -import kotlin.time.Duration -import kotlin.time.Duration.Companion.milliseconds -import kotlin.time.measureTime private const val DEPLOYMENT_KEY = "server-NgJxxvg8OGwwBsWVXqyxQbdiflbhvugy" @@ -123,7 +120,7 @@ class EvaluationIntegrationTest { userId = "user_id", deviceId = "device_id", userProperties = mapOf( - "[Experiment] test-sticky-bucketing" to "on", + "[Experiment] test-sticky-bucketing" to "on" ) ) var result = engine.evaluate(user, flags)["test-sticky-bucketing"] @@ -142,7 +139,7 @@ class EvaluationIntegrationTest { userId = "user_id", deviceId = "device_id", userProperties = mapOf( - "[Experiment] test-sticky-bucketing" to "off", + "[Experiment] test-sticky-bucketing" to "off" ) ) result = engine.evaluate(user, flags)["test-sticky-bucketing"] @@ -161,7 +158,7 @@ class EvaluationIntegrationTest { userId = "user_id", deviceId = "device_id", userProperties = mapOf( - "[Experiment] test-sticky-bucketing" to "not-a-variant", + "[Experiment] test-sticky-bucketing" to "not-a-variant" ) ) result = engine.evaluate(user, flags)["test-sticky-bucketing"] @@ -215,7 +212,7 @@ class EvaluationIntegrationTest { userProperties = mapOf( "key-1" to "value-1", "key-2" to "value-2", - "key-3" to "value-3", + "key-3" to "value-3" ) ) var result = engine.evaluate(user, flags)["test-multiple-conditions-and-values"] @@ -228,7 +225,7 @@ class EvaluationIntegrationTest { user = userContext( userProperties = mapOf( "key-1" to "value-1", - "key-2" to "value-2", + "key-2" to "value-2" ) ) result = engine.evaluate(user, flags)["test-multiple-conditions-and-values"] @@ -656,9 +653,11 @@ class EvaluationIntegrationTest { @Test fun `test version less`() { - val user = freeformUserContext(mapOf( - "version" to "1.9.0" - )) + val user = freeformUserContext( + mapOf( + "version" to "1.9.0" + ) + ) val result = engine.evaluate(user, flags.filter { it.key == "test-version-less" })["test-version-less"] DefaultAsserter.assertEquals( @@ -670,9 +669,11 @@ class EvaluationIntegrationTest { @Test fun `test version less or equal`() { - val user = freeformUserContext(mapOf( - "version" to "1.10.0" - )) + val user = freeformUserContext( + mapOf( + "version" to "1.10.0" + ) + ) val result = engine.evaluate(user, flags)["test-version-less-or-equal"] DefaultAsserter.assertEquals( "Unexpected evaluation result", @@ -683,9 +684,11 @@ class EvaluationIntegrationTest { @Test fun `test version greater`() { - val user = freeformUserContext(mapOf( - "version" to "1.10.0" - )) + val user = freeformUserContext( + mapOf( + "version" to "1.10.0" + ) + ) val result = engine.evaluate(user, flags)["test-version-greater"] DefaultAsserter.assertEquals( "Unexpected evaluation result", @@ -696,9 +699,11 @@ class EvaluationIntegrationTest { @Test fun `test version greater or equal`() { - val user = freeformUserContext(mapOf( - "version" to "1.9.0" - )) + val user = freeformUserContext( + mapOf( + "version" to "1.9.0" + ) + ) val result = engine.evaluate(user, flags)["test-version-greater-or-equal"] DefaultAsserter.assertEquals( "Unexpected evaluation result", @@ -864,9 +869,11 @@ class EvaluationIntegrationTest { @Test fun `test version compare falls back on string comparison`() { - val user = freeformUserContext(mapOf( - "version" to "1.10." - )) + val user = freeformUserContext( + mapOf( + "version" to "1.10." + ) + ) val result = engine.evaluate(user, flags.filter { it.key == "test-version-less" })["test-version-less"] DefaultAsserter.assertEquals( diff --git a/evaluation-core/src/commonTest/kotlin/EvaluationSerializationTest.kt b/evaluation-core/src/commonTest/kotlin/EvaluationSerializationTest.kt index 9d75637..1a1c373 100644 --- a/evaluation-core/src/commonTest/kotlin/EvaluationSerializationTest.kt +++ b/evaluation-core/src/commonTest/kotlin/EvaluationSerializationTest.kt @@ -14,7 +14,11 @@ class EvaluationSerializationTest { ) private val primitiveTypeArray = listOf( - null, "value", 13, 13.12, true + null, + "value", + 13, + 13.12, + true ) private val nestedJsonObject = primitiveTypeObject.toMutableMap().apply { diff --git a/evaluation-core/src/commonTest/kotlin/MurMurEnglishTest.kt b/evaluation-core/src/commonTest/kotlin/Murmur3EnglishTest.kt similarity index 96% rename from evaluation-core/src/commonTest/kotlin/MurMurEnglishTest.kt rename to evaluation-core/src/commonTest/kotlin/Murmur3EnglishTest.kt index 8c65c3b..8588616 100644 --- a/evaluation-core/src/commonTest/kotlin/MurMurEnglishTest.kt +++ b/evaluation-core/src/commonTest/kotlin/Murmur3EnglishTest.kt @@ -11,7 +11,7 @@ import kotlin.test.assertEquals */ private const val MURMUR_SEED = 0x7f3a21ea -class Murmur3Test { +class Murmur3EnglishTest { private val englishWords = ENGLISH_WORDS.trim() private val hash3X8632 = HASH3_X86_32.trim() @@ -19,9 +19,9 @@ class Murmur3Test { @Test fun testMurMur3HashSimple() { val input = "brian".toByteArray() - val result = Murmur3.hash32x86(input, input.size, MURMUR_SEED).toLong() + val result = Murmur3.hash32x86(input, input.size, MURMUR_SEED).toLong() and 0xffffffff val expected = (3948467465 and 0xffffffff) - assertEquals(3948467465, expected) + assertEquals(result, expected) } @Test diff --git a/evaluation-core/src/commonTest/kotlin/SelectableTest.kt b/evaluation-core/src/commonTest/kotlin/SelectableTest.kt index 3ea7912..a1cd52f 100644 --- a/evaluation-core/src/commonTest/kotlin/SelectableTest.kt +++ b/evaluation-core/src/commonTest/kotlin/SelectableTest.kt @@ -15,7 +15,11 @@ class SelectableTest { ) private val primitiveArray = listOf( - null, "value", 13, 13.12, true + null, + "value", + 13, + 13.12, + true ) private val nestedArray = primitiveArray.toMutableList().apply { @@ -30,7 +34,6 @@ class SelectableTest { @Test fun testSelectableEvaluationContextTypes() { - val contextMap = primitiveObject.toMutableMap().apply { put("array", nestedArray) put("object", nestedObject) diff --git a/evaluation-core/src/commonTest/kotlin/TopologicalSortTest.kt b/evaluation-core/src/commonTest/kotlin/TopologicalSortTest.kt index b106992..d72221d 100644 --- a/evaluation-core/src/commonTest/kotlin/TopologicalSortTest.kt +++ b/evaluation-core/src/commonTest/kotlin/TopologicalSortTest.kt @@ -76,13 +76,13 @@ class TopologicalSortTest { run { // no flag keys val flagConfigs = listOf( evaluationFlag(1, dependencies), - evaluationFlag(2, dependencies), + evaluationFlag(2, dependencies) ) val result = topologicalSort(flagConfigs) assertEquals( listOf( evaluationFlag(1, dependencies), - evaluationFlag(2, dependencies), + evaluationFlag(2, dependencies) ), result ) @@ -90,13 +90,13 @@ class TopologicalSortTest { run { // with flag keys val flagConfigs = listOf( evaluationFlag(1, dependencies), - evaluationFlag(2, dependencies), + evaluationFlag(2, dependencies) ) val result = topologicalSort(flagConfigs, setOf("1", "2")) assertEquals( listOf( evaluationFlag(1, dependencies), - evaluationFlag(2, dependencies), + evaluationFlag(2, dependencies) ), result ) @@ -104,7 +104,7 @@ class TopologicalSortTest { run { // with flag keys, no match val flagConfigs = listOf( evaluationFlag(1, dependencies), - evaluationFlag(2, dependencies), + evaluationFlag(2, dependencies) ) val result = topologicalSort(flagConfigs, setOf("99", "999")) assertTrue(result.isEmpty()) @@ -117,14 +117,14 @@ class TopologicalSortTest { val flagConfigs = listOf( evaluationFlag(1, setOf(2)), evaluationFlag(2, setOf(3)), - evaluationFlag(3, setOf()), + evaluationFlag(3, setOf()) ) val result = topologicalSort(flagConfigs) assertEquals( listOf( evaluationFlag(3, setOf()), evaluationFlag(2, setOf(3)), - evaluationFlag(1, setOf(2)), + evaluationFlag(1, setOf(2)) ), result ) @@ -133,14 +133,14 @@ class TopologicalSortTest { val flagConfigs = listOf( evaluationFlag(1, setOf(2)), evaluationFlag(2, setOf(3)), - evaluationFlag(3, setOf()), + evaluationFlag(3, setOf()) ) val result = topologicalSort(flagConfigs, setOf("1", "2")) assertEquals( listOf( evaluationFlag(3, setOf()), evaluationFlag(2, setOf(3)), - evaluationFlag(1, setOf(2)), + evaluationFlag(1, setOf(2)) ), result ) @@ -149,7 +149,7 @@ class TopologicalSortTest { val flagConfigs = listOf( evaluationFlag(1, setOf(2)), evaluationFlag(2, setOf(3)), - evaluationFlag(3, setOf()), + evaluationFlag(3, setOf()) ) val result = topologicalSort(flagConfigs, setOf("99", "999")) assertTrue(result.isEmpty()) @@ -161,7 +161,7 @@ class TopologicalSortTest { run { // no flag keys try { val flagConfigs = listOf( - evaluationFlag(1, setOf(1)), + evaluationFlag(1, setOf(1)) ) val result = topologicalSort(flagConfigs) fail("expected cycle, instead: $result") @@ -172,7 +172,7 @@ class TopologicalSortTest { run { // with flag keys try { val flagConfigs = listOf( - evaluationFlag(1, setOf(1)), + evaluationFlag(1, setOf(1)) ) val result = topologicalSort(flagConfigs, setOf("1")) fail("expected cycle, instead: $result") @@ -183,7 +183,7 @@ class TopologicalSortTest { run { // with flag keys, no match try { val flagConfigs = listOf( - evaluationFlag(1, setOf(1)), + evaluationFlag(1, setOf(1)) ) val result = topologicalSort(flagConfigs, setOf("999")) assertTrue(result.isEmpty()) @@ -199,7 +199,7 @@ class TopologicalSortTest { try { val flagConfigs = listOf( evaluationFlag(1, setOf(2)), - evaluationFlag(2, setOf(1)), + evaluationFlag(2, setOf(1)) ) val result = topologicalSort(flagConfigs) fail("expected cycle, instead: $result") @@ -211,7 +211,7 @@ class TopologicalSortTest { try { val flagConfigs = listOf( evaluationFlag(1, setOf(2)), - evaluationFlag(2, setOf(1)), + evaluationFlag(2, setOf(1)) ) val result = topologicalSort(flagConfigs, setOf("2")) fail("expected cycle, instead: $result") @@ -223,7 +223,7 @@ class TopologicalSortTest { try { val flagConfigs = listOf( evaluationFlag(1, setOf(2)), - evaluationFlag(2, setOf(1)), + evaluationFlag(2, setOf(1)) ) val result = topologicalSort(flagConfigs, setOf("999")) assertTrue(result.isEmpty()) @@ -272,7 +272,7 @@ class TopologicalSortTest { evaluationFlag(10, setOf(7)), evaluationFlag(20, setOf()), evaluationFlag(21, setOf(20)), - evaluationFlag(30, setOf()), + evaluationFlag(30, setOf()) ) val result = topologicalSort(flags) val expected = listOf( @@ -288,7 +288,7 @@ class TopologicalSortTest { evaluationFlag(9, setOf(10, 7, 5)), evaluationFlag(20, setOf()), evaluationFlag(21, setOf(20)), - evaluationFlag(30, setOf()), + evaluationFlag(30, setOf()) ) assertEquals(expected, result) } @@ -308,7 +308,7 @@ class TopologicalSortTest { evaluationFlag(10, setOf(7)), evaluationFlag(20, setOf()), evaluationFlag(21, setOf(20)), - evaluationFlag(30, setOf()), + evaluationFlag(30, setOf()) ) val result = topologicalSort(flags) val expected = listOf( @@ -324,7 +324,7 @@ class TopologicalSortTest { evaluationFlag(9, setOf(10, 7, 5)), evaluationFlag(20, setOf()), evaluationFlag(21, setOf(20)), - evaluationFlag(30, setOf()), + evaluationFlag(30, setOf()) ) assertEquals(expected, result) } @@ -344,7 +344,7 @@ class TopologicalSortTest { evaluationFlag(10, setOf(7)), evaluationFlag(20, setOf()), evaluationFlag(21, setOf(20)), - evaluationFlag(30, setOf()), + evaluationFlag(30, setOf()) ) val result = topologicalSort(flags) val expected = listOf( @@ -360,7 +360,7 @@ class TopologicalSortTest { evaluationFlag(9, setOf(10, 7, 5)), evaluationFlag(20, setOf()), evaluationFlag(21, setOf(20)), - evaluationFlag(30, setOf()), + evaluationFlag(30, setOf()) ) assertEquals(expected, result) } diff --git a/evaluation-interop/src/commonMain/kotlin/Evaluation.kt b/evaluation-interop/src/commonMain/kotlin/Evaluation.kt index 2dbea8f..906cdec 100644 --- a/evaluation-interop/src/commonMain/kotlin/Evaluation.kt +++ b/evaluation-interop/src/commonMain/kotlin/Evaluation.kt @@ -23,7 +23,7 @@ internal val engine = EvaluationEngineImpl() @Serializable internal data class InteropResult( val result: Map? = null, - val error: String? = null, + val error: String? = null ) { companion object { fun success(result: Map) =