Skip to content

Commit 2b4135f

Browse files
committed
fixup: remove OpenFeatureAPIFactory class per review consensus
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
1 parent 01748e2 commit 2b4135f

4 files changed

Lines changed: 23 additions & 83 deletions

File tree

src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* there is shared across all {@link Client}s. For dependency-injection frameworks, testing, or
2323
* multi-tenant scenarios that need fully independent state (providers, hooks, evaluation context,
2424
* event handlers, transaction context propagators), create isolated instances via
25-
* {@code dev.openfeature.sdk.isolated.OpenFeatureAPIFactory.createAPI()}.
25+
* {@link #createIsolated()}.
2626
*
2727
* <p><strong>Note:</strong> Isolated API instances (per spec section 1.8) are experimental and
2828
* subject to change.
@@ -55,10 +55,6 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
5555
* state (providers, hooks, evaluation context, event handlers, transaction context
5656
* propagators).
5757
*
58-
* <p>Prefer {@code OpenFeatureAPIFactory.createAPI()} from
59-
* {@code dev.openfeature.sdk.isolated}, which satisfies spec requirement 1.8.3
60-
* (factory in a distinct package for intentional discoverability).
61-
*
6258
* @apiNote This API is experimental and subject to change.
6359
* @see <a href="https://openfeature.dev/specification/sections/flag-evaluation#18-isolated-api-instances">
6460
* Spec &sect;1.8 &mdash; Isolated API Instances</a>
@@ -67,7 +63,7 @@ public static OpenFeatureAPI createIsolated() {
6763
return new OpenFeatureAPI();
6864
}
6965

70-
// Package-private: not part of the public API; use createIsolated() or OpenFeatureAPIFactory.
66+
// Package-private: not part of the public API; use createIsolated().
7167
OpenFeatureAPI() {
7268
this(new AutoCloseableReentrantReadWriteLock());
7369
}

src/main/java/dev/openfeature/sdk/isolated/OpenFeatureAPIFactory.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/test/java/dev/openfeature/sdk/isolated/IsolatedAPISingeltonTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import dev.openfeature.sdk.NoOpTransactionContextPropagator;
88
import dev.openfeature.sdk.OpenFeatureAPI;
99
import dev.openfeature.sdk.ThreadLocalTransactionContextPropagator;
10-
import dev.openfeature.sdk.isolated.OpenFeatureAPIFactory;
1110
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
1211
import java.util.Map;
1312
import org.junit.jupiter.api.AfterEach;
@@ -36,7 +35,7 @@ void isolatedInstanceDoesNotInterfereWithSingleton() {
3635
// record singleton baseline
3736
FeatureProvider singletonProvider = singleton.getProvider();
3837

39-
OpenFeatureAPI isolated = OpenFeatureAPIFactory.createAPI();
38+
OpenFeatureAPI isolated = OpenFeatureAPI.createIsolated();
4039
assertThat(isolated).isNotSameAs(singleton);
4140

4241
// mutate only the isolated instance
@@ -57,7 +56,7 @@ void isolatedInstanceDoesNotInterfereWithSingleton() {
5756
@Test
5857
@DisplayName("singleton does not interfere with isolated instance")
5958
void singletonDoesNotInterfereWithIsolatedInstance() {
60-
OpenFeatureAPI isolated = OpenFeatureAPIFactory.createAPI();
59+
OpenFeatureAPI isolated = OpenFeatureAPI.createIsolated();
6160

6261
// record isolated baseline
6362
FeatureProvider isolatedProvider = isolated.getProvider();

src/test/java/dev/openfeature/sdk/isolated/IsolatedAPITest.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import dev.openfeature.sdk.NoOpTransactionContextPropagator;
99
import dev.openfeature.sdk.OpenFeatureAPI;
1010
import dev.openfeature.sdk.ThreadLocalTransactionContextPropagator;
11-
import dev.openfeature.sdk.isolated.OpenFeatureAPIFactory;
1211
import dev.openfeature.sdk.providers.memory.Flag;
1312
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
1413
import java.util.Map;
@@ -31,8 +30,8 @@ class IsolatedAPITest {
3130
@Test
3231
@DisplayName("factory creates distinct API instances")
3332
void factoryCreatesDistinctInstances() {
34-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
35-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
33+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
34+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
3635

3736
assertThat(api1).isInstanceOf(OpenFeatureAPI.class).isNotSameAs(api2);
3837
}
@@ -43,8 +42,8 @@ void factoryCreatesDistinctInstances() {
4342
@Test
4443
@DisplayName("providers are isolated between instances")
4544
void providerIsolation() {
46-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
47-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
45+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
46+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
4847

4948
InMemoryProvider provider = new InMemoryProvider(Map.of());
5049
api1.setProvider(provider);
@@ -59,8 +58,8 @@ void providerIsolation() {
5958
@Test
6059
@DisplayName("hooks are isolated between instances")
6160
void hookIsolation() {
62-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
63-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
61+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
62+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
6463

6564
api1.addHooks(new NoOpHook());
6665

@@ -74,8 +73,8 @@ void hookIsolation() {
7473
@Test
7574
@DisplayName("evaluation context is isolated between instances")
7675
void evaluationContextIsolation() {
77-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
78-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
76+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
77+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
7978

8079
api1.setEvaluationContext(new ImmutableContext("key-1"));
8180
api2.setEvaluationContext(new ImmutableContext("key-2"));
@@ -91,8 +90,8 @@ void evaluationContextIsolation() {
9190
@Timeout(value = 2, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
9291
@DisplayName("event handlers are isolated between instances")
9392
void eventHandlerIsolation() throws Exception {
94-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
95-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
93+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
94+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
9695

9796
CountDownLatch api1HandlerLatch = new CountDownLatch(1);
9897
AtomicBoolean api2HandlerCalled = new AtomicBoolean(false);
@@ -120,8 +119,8 @@ void eventHandlerIsolation() throws Exception {
120119
@Test
121120
@DisplayName("transaction context propagator is isolated between instances")
122121
void transactionContextPropagatorIsolation() {
123-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
124-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
122+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
123+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
125124

126125
ThreadLocalTransactionContextPropagator propagator = new ThreadLocalTransactionContextPropagator();
127126
api1.setTransactionContextPropagator(propagator);
@@ -137,7 +136,7 @@ void transactionContextPropagatorIsolation() {
137136
@Test
138137
@DisplayName("isolated instance conforms to API contract")
139138
void isolatedInstanceConformsToAPIContract() throws Exception {
140-
OpenFeatureAPI api = OpenFeatureAPIFactory.createAPI();
139+
OpenFeatureAPI api = OpenFeatureAPI.createIsolated();
141140

142141
// provider management
143142
InMemoryProvider provider = new InMemoryProvider(Map.of(
@@ -172,8 +171,8 @@ void isolatedInstanceConformsToAPIContract() throws Exception {
172171
@Test
173172
@DisplayName("clearHooks does not affect other instances")
174173
void clearHooksDoesNotAffectOtherInstances() {
175-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
176-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
174+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
175+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
177176

178177
NoOpHook hook = new NoOpHook();
179178
api1.addHooks(hook);
@@ -192,8 +191,8 @@ void clearHooksDoesNotAffectOtherInstances() {
192191
@Test
193192
@DisplayName("clients use their own instance's provider")
194193
void clientUsesItsOwnInstanceProvider() throws Exception {
195-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
196-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
194+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
195+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
197196

198197
api1.setProviderAndWait(new InMemoryProvider(Map.of(
199198
"flag1",
@@ -221,8 +220,8 @@ void warnWhenProviderBoundToMultipleInstances() {
221220
Logger mockLogger = Mockito.mock(Logger.class);
222221
LoggerMock.setMock(OpenFeatureAPI.class, mockLogger);
223222
try {
224-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
225-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
223+
OpenFeatureAPI api1 = OpenFeatureAPI.createIsolated();
224+
OpenFeatureAPI api2 = OpenFeatureAPI.createIsolated();
226225

227226
NoOpProvider provider = new NoOpProvider();
228227
api1.setProvider(provider);

0 commit comments

Comments
 (0)