-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathIsolatedAPISingeltonTest.java
More file actions
51 lines (42 loc) · 1.81 KB
/
IsolatedAPISingeltonTest.java
File metadata and controls
51 lines (42 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package dev.openfeature.sdk.isolated;
import static org.assertj.core.api.Assertions.assertThat;
import dev.openfeature.sdk.FeatureProvider;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.NoOpTransactionContextPropagator;
import dev.openfeature.sdk.OpenFeatureAPI;
import dev.openfeature.sdk.OpenFeatureAPIFactory;
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
class IsolatedAPISingeltonTest {
private final OpenFeatureAPI singleton = OpenFeatureAPI.getInstance();
@AfterEach
void restoreSingleton() {
singleton.shutdown();
singleton.clearHooks();
singleton.setEvaluationContext(null);
singleton.setTransactionContextPropagator(new NoOpTransactionContextPropagator());
}
/**
* Requirement 1.8.1 — isolated instances do not share state with
* the global singleton.
*/
@Test
@DisplayName("isolated instance does not interfere with singleton")
void isolatedInstanceDoesNotInterfereWithSingleton() {
// record singleton baseline
FeatureProvider singletonProvider = singleton.getProvider();
OpenFeatureAPI isolated = OpenFeatureAPIFactory.createAPI();
assertThat(isolated).isNotSameAs(singleton);
// mutate only the isolated instance
isolated.setProvider(new InMemoryProvider(Map.of()));
isolated.addHooks(new NoOpHook());
isolated.setEvaluationContext(new ImmutableContext("isolated-key"));
// singleton remains at baseline
assertThat(singleton.getProvider()).isSameAs(singletonProvider);
assertThat(singleton.getHooks()).isEmpty();
assertThat(singleton.getEvaluationContext()).isNull();
}
}