From 019dbfc57a09dcd98134ce54247409a3e7b8127d Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Wed, 7 Feb 2024 12:55:13 +0100 Subject: [PATCH] fix: Remove STALE event (#122) * build: Bump OF dependency Signed-off-by: Fabrizio Demaria * fix: Remove STALE event Signed-off-by: Fabrizio Demaria --------- Signed-off-by: Fabrizio Demaria --- .../src/main/java/com/example/confidencedemoapp/MainVm.kt | 1 - Provider/build.gradle.kts | 2 +- .../com/spotify/confidence/ConfidenceFeatureProvider.kt | 2 -- .../java/com/spotify/confidence/StorageFileCacheTests.kt | 8 ++------ README.md | 5 ++--- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/ConfidenceDemoApp/src/main/java/com/example/confidencedemoapp/MainVm.kt b/ConfidenceDemoApp/src/main/java/com/example/confidencedemoapp/MainVm.kt index b5938929..a4438f50 100644 --- a/ConfidenceDemoApp/src/main/java/com/example/confidencedemoapp/MainVm.kt +++ b/ConfidenceDemoApp/src/main/java/com/example/confidencedemoapp/MainVm.kt @@ -15,7 +15,6 @@ import dev.openfeature.sdk.FlagEvaluationDetails import dev.openfeature.sdk.ImmutableContext import dev.openfeature.sdk.OpenFeatureAPI import dev.openfeature.sdk.Value -import dev.openfeature.sdk.async.setProviderAndWait import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.util.UUID diff --git a/Provider/build.gradle.kts b/Provider/build.gradle.kts index b8472f55..2b80ad8f 100644 --- a/Provider/build.gradle.kts +++ b/Provider/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } object Versions { - const val openFeatureSDK = "0.2.2" + const val openFeatureSDK = "0.2.3" const val okHttp = "4.10.0" const val kotlinxSerialization = "1.6.0" const val coroutines = "1.7.3" diff --git a/Provider/src/main/java/com/spotify/confidence/ConfidenceFeatureProvider.kt b/Provider/src/main/java/com/spotify/confidence/ConfidenceFeatureProvider.kt index 57ca8243..b51e2b75 100644 --- a/Provider/src/main/java/com/spotify/confidence/ConfidenceFeatureProvider.kt +++ b/Provider/src/main/java/com/spotify/confidence/ConfidenceFeatureProvider.kt @@ -120,8 +120,6 @@ class ConfidenceFeatureProvider private constructor( newContext: EvaluationContext ) { if (newContext != oldContext) { - eventHandler.publish(OpenFeatureEvents.ProviderStale) - // on the new context we want to fetch new values and update // the storage & cache right away which is why we pass `InitialisationStrategy.FetchAndActivate` internalInitialize( diff --git a/Provider/src/test/java/com/spotify/confidence/StorageFileCacheTests.kt b/Provider/src/test/java/com/spotify/confidence/StorageFileCacheTests.kt index 1330188f..ee62037f 100644 --- a/Provider/src/test/java/com/spotify/confidence/StorageFileCacheTests.kt +++ b/Provider/src/test/java/com/spotify/confidence/StorageFileCacheTests.kt @@ -15,9 +15,7 @@ import dev.openfeature.sdk.ImmutableContext import dev.openfeature.sdk.ImmutableStructure import dev.openfeature.sdk.Reason import dev.openfeature.sdk.Value -import dev.openfeature.sdk.async.awaitReadyOrError -import dev.openfeature.sdk.events.EventHandler -import dev.openfeature.sdk.events.OpenFeatureEvents +import dev.openfeature.sdk.events.awaitReadyOrError import junit.framework.TestCase import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -64,13 +62,12 @@ class StorageFileCacheTests { whenever(mockContext.filesDir).thenReturn(Files.createTempDirectory("tmpTests").toFile()) } + @OptIn(ExperimentalCoroutinesApi::class) @Test fun testOfflineScenarioLoadsStoredCache() = runTest { val mockClient: ConfidenceClient = mock() whenever(mockClient.apply(any(), any())).thenReturn(Result.Success) val testDispatcher = UnconfinedTestDispatcher(testScheduler) - val eventPublisher = EventHandler(testDispatcher) - eventPublisher.publish(OpenFeatureEvents.ProviderStale) val cache1 = InMemoryCache() whenever(mockClient.resolve(eq(listOf()), any())).thenReturn( ResolveResponse.Resolved( @@ -81,7 +78,6 @@ class StorageFileCacheTests { context = mockContext, clientSecret = "", client = mockClient, - eventHandler = eventPublisher, cache = cache1 ) provider1.initialize(ImmutableContext(targetingKey = "user1")) diff --git a/README.md b/README.md index dcf1632b..674032fe 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,11 @@ Where: ### Changing context after the provider initialization The evaluation context can be changed during the app session using `setEvaluationContext(...)`. -After calling this method the new context is set for the provider and the flags will be fetched again and the cache and storage will be updated accordingly. -The OpenFeature Events `ProviderStale` and `ProviderReady` events will be emitted accordingly. +After calling this method the new context is set for the provider, the flags will be fetched again and the cache and storage will be updated accordingly. The event `ProviderReady` will be emitted once the new flags are ready to be consumed by the application (note that the selected initialization strategy property doesn't play a role in this case). Notes: - If a flag can't be resolved from cache, the provider does NOT automatically resort to calling remote: refreshing the cache from remote only happens when setting a new provider and/or evaluation context in the global OpenFeatureAPI -- It's advised not to perform resolves while `setProvider` and `setEvaluationContext` are running: resolves might return the default value with reason `STALE` during such operations. +- It's advised not to perform resolves while `setProvider` and `setEvaluationContext` are running: resolves might return the default value with reason `STALE` during such operations. The event `ProviderReady` can be used to guarantee correctness. ## Apply events This Provider automatically emits `apply` events to the Confidence backend once a flag's property is read by the application. This allows Confidence to track who was exposed to what variant and when.