|
1 | 1 | package dev.openfeature.contrib.providers.gofeatureflag; |
2 | 2 |
|
| 3 | +import static dev.openfeature.contrib.providers.gofeatureflag.controller.GoFeatureFlagController.requestMapper; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 7 | + |
3 | 8 | import java.io.IOException; |
4 | 9 | import java.net.URL; |
5 | 10 | import java.nio.charset.StandardCharsets; |
|
10 | 15 | import java.util.List; |
11 | 16 | import java.util.Map; |
12 | 17 |
|
13 | | -import com.google.common.cache.CacheBuilder; |
| 18 | +import org.jetbrains.annotations.NotNull; |
| 19 | +import org.junit.jupiter.api.AfterEach; |
| 20 | +import org.junit.jupiter.api.BeforeEach; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import org.junit.jupiter.api.TestInfo; |
| 23 | + |
| 24 | +import com.github.benmanes.caffeine.cache.Caffeine; |
14 | 25 | import com.google.common.net.HttpHeaders; |
| 26 | + |
| 27 | +import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidEndpoint; |
| 28 | +import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidOptions; |
15 | 29 | import dev.openfeature.sdk.Client; |
16 | 30 | import dev.openfeature.sdk.ErrorCode; |
17 | | -import dev.openfeature.sdk.EvaluationContext; |
18 | 31 | import dev.openfeature.sdk.FlagEvaluationDetails; |
19 | 32 | import dev.openfeature.sdk.ImmutableContext; |
20 | | -import dev.openfeature.sdk.OpenFeatureAPI; |
21 | | -import dev.openfeature.sdk.ProviderState; |
22 | | -import dev.openfeature.sdk.exceptions.ProviderNotReadyError; |
23 | | -import lombok.extern.slf4j.Slf4j; |
24 | | -import org.jetbrains.annotations.NotNull; |
25 | 33 | import dev.openfeature.sdk.ImmutableMetadata; |
26 | 34 | import dev.openfeature.sdk.MutableContext; |
27 | 35 | import dev.openfeature.sdk.MutableStructure; |
| 36 | +import dev.openfeature.sdk.OpenFeatureAPI; |
28 | 37 | import dev.openfeature.sdk.Reason; |
29 | 38 | import dev.openfeature.sdk.Value; |
30 | | -import org.junit.jupiter.api.AfterEach; |
31 | | -import org.junit.jupiter.api.BeforeEach; |
32 | | -import org.junit.jupiter.api.Test; |
33 | | - |
34 | | -import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidEndpoint; |
35 | | -import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidOptions; |
36 | 39 | import lombok.SneakyThrows; |
| 40 | +import lombok.extern.slf4j.Slf4j; |
37 | 41 | import okhttp3.HttpUrl; |
38 | 42 | import okhttp3.mockwebserver.Dispatcher; |
39 | 43 | import okhttp3.mockwebserver.MockResponse; |
40 | 44 | import okhttp3.mockwebserver.MockWebServer; |
41 | 45 | import okhttp3.mockwebserver.RecordedRequest; |
42 | | -import org.junit.jupiter.api.TestInfo; |
43 | | - |
44 | | -import static dev.openfeature.contrib.providers.gofeatureflag.controller.GoFeatureFlagController.requestMapper; |
45 | | -import static org.assertj.core.api.Assertions.assertThat; |
46 | | -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
47 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
48 | | -import static org.junit.jupiter.api.Assertions.assertThrows; |
49 | 46 |
|
50 | 47 | @Slf4j |
51 | 48 | class GoFeatureFlagProviderTest { |
@@ -361,9 +358,9 @@ void should_resolve_from_cache() { |
361 | 358 | @SneakyThrows |
362 | 359 | @Test |
363 | 360 | void should_resolve_from_cache_max_size() { |
364 | | - CacheBuilder cacheBuilder = CacheBuilder.newBuilder().maximumSize(1); |
| 361 | + Caffeine caffeine = Caffeine.newBuilder().maximumSize(1); |
365 | 362 | GoFeatureFlagProvider g = new GoFeatureFlagProvider(GoFeatureFlagProviderOptions.builder() |
366 | | - .endpoint(this.baseUrl.toString()).timeout(1000).cacheBuilder(cacheBuilder).build()); |
| 363 | + .endpoint(this.baseUrl.toString()).timeout(1000).cacheConfig(caffeine).build()); |
367 | 364 | String providerName = this.testName; |
368 | 365 | OpenFeatureAPI.getInstance().setProviderAndWait(providerName, g); |
369 | 366 | Client client = OpenFeatureAPI.getInstance().getClient(providerName); |
@@ -406,10 +403,6 @@ void should_resolve_from_cache_max_size() { |
406 | 403 | .flagMetadata(defaultMetadata) |
407 | 404 | .build(); |
408 | 405 | assertEquals(wantStr2, gotStr); |
409 | | - |
410 | | - // verify that value previously fetch from cache now not fetched from cache since cache max size is 1, and cache is full. |
411 | | - got = client.getBooleanDetails("bool_targeting_match", false, this.evaluationContext); |
412 | | - assertEquals(want, got); |
413 | 406 | } |
414 | 407 |
|
415 | 408 | @SneakyThrows |
|
0 commit comments