diff --git a/Provider/src/main/java/dev/openfeature/contrib/providers/ConfidenceFeatureProvider.kt b/Provider/src/main/java/dev/openfeature/contrib/providers/ConfidenceFeatureProvider.kt index de716589..d6d1bc63 100644 --- a/Provider/src/main/java/dev/openfeature/contrib/providers/ConfidenceFeatureProvider.kt +++ b/Provider/src/main/java/dev/openfeature/contrib/providers/ConfidenceFeatureProvider.kt @@ -48,7 +48,7 @@ class ConfidenceFeatureProvider private constructor( private val client: ConfidenceClient, private val flagApplier: FlagApplier, private val eventsPublisher: EventsPublisher, - private val dispatcher: CoroutineDispatcher + dispatcher: CoroutineDispatcher ) : FeatureProvider { private val job = SupervisorJob() private val coroutineScope = CoroutineScope(job + dispatcher) @@ -300,7 +300,7 @@ class ConfidenceFeatureProvider private constructor( } } -sealed class InitialisationStrategy { - object FetchAndActivate : InitialisationStrategy() - object ActivateAndFetchAsync : InitialisationStrategy() +sealed interface InitialisationStrategy { + object FetchAndActivate : InitialisationStrategy + object ActivateAndFetchAsync : InitialisationStrategy } \ No newline at end of file diff --git a/Provider/src/main/java/dev/openfeature/contrib/providers/cache/DiskStorage.kt b/Provider/src/main/java/dev/openfeature/contrib/providers/cache/DiskStorage.kt new file mode 100644 index 00000000..8cb2fc8d --- /dev/null +++ b/Provider/src/main/java/dev/openfeature/contrib/providers/cache/DiskStorage.kt @@ -0,0 +1,15 @@ +package dev.openfeature.contrib.providers.cache + +import dev.openfeature.contrib.providers.client.ResolvedFlag +import dev.openfeature.sdk.EvaluationContext + +interface DiskStorage { + fun store( + resolvedFlags: List, + resolveToken: String, + evaluationContext: EvaluationContext + ): CacheData + fun read(): CacheData? + + fun clear() +} \ No newline at end of file diff --git a/Provider/src/main/java/dev/openfeature/contrib/providers/cache/StorageFileCache.kt b/Provider/src/main/java/dev/openfeature/contrib/providers/cache/StorageFileCache.kt index 84e5f170..18ceb9b2 100644 --- a/Provider/src/main/java/dev/openfeature/contrib/providers/cache/StorageFileCache.kt +++ b/Provider/src/main/java/dev/openfeature/contrib/providers/cache/StorageFileCache.kt @@ -11,17 +11,6 @@ import java.io.File const val FLAGS_FILE_NAME = "confidence_flags_cache.json" -interface DiskStorage { - fun store( - resolvedFlags: List, - resolveToken: String, - evaluationContext: EvaluationContext - ): CacheData - fun read(): CacheData? - - fun clear() -} - class StorageFileCache private constructor(context: Context) : DiskStorage { private val file: File = File(context.filesDir, FLAGS_FILE_NAME) diff --git a/Provider/src/test/java/dev/openfeature/contrib/providers/StorageFileCacheTests.kt b/Provider/src/test/java/dev/openfeature/contrib/providers/StorageFileCacheTests.kt index c4aefc14..d1d56e20 100644 --- a/Provider/src/test/java/dev/openfeature/contrib/providers/StorageFileCacheTests.kt +++ b/Provider/src/test/java/dev/openfeature/contrib/providers/StorageFileCacheTests.kt @@ -13,8 +13,11 @@ import dev.openfeature.sdk.ImmutableStructure import dev.openfeature.sdk.Reason import dev.openfeature.sdk.Value import dev.openfeature.sdk.async.awaitProviderReady +import dev.openfeature.sdk.events.EventHandler +import dev.openfeature.sdk.events.OpenFeatureEvents import junit.framework.TestCase import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test @@ -61,12 +64,16 @@ class StorageFileCacheTests { @Test fun testOfflineScenarioLoadsStoredCache() = runTest { val mockClient: ConfidenceClient = mock() + val testDispatcher = UnconfinedTestDispatcher(testScheduler) + val eventPublisher = EventHandler.eventsPublisher(testDispatcher) + eventPublisher.publish(OpenFeatureEvents.ProviderStale) val cache1 = InMemoryCache() whenever(mockClient.resolve(eq(listOf()), any())).thenReturn(ResolveResponse.Resolved(ResolveFlags(resolvedFlags, "token1"))) val provider1 = ConfidenceFeatureProvider.create( context = mockContext, clientSecret = "", client = mockClient, + eventsPublisher = eventPublisher, cache = cache1 ) runBlocking {