Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ public void shutdown() {
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
providerRepository = new ProviderRepository(this);
eventSupport = new EventSupport();
clearHooks();
setEvaluationContext(new ImmutableContext());
Comment thread
chrfwow marked this conversation as resolved.
Outdated
setTransactionContextPropagator(new NoOpTransactionContextPropagator());
}
}
}
Expand Down
25 changes: 19 additions & 6 deletions src/test/java/dev/openfeature/sdk/ShutdownBehaviorSpecTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.openfeature.sdk;

import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;

import dev.openfeature.sdk.fixtures.ProviderFixture;
Expand Down Expand Up @@ -131,16 +133,27 @@ void mustShutdownAllProvidersOnShuttingDownApi() {
}

@Test
@DisplayName("once shutdown is complete, api must be ready to use again")
void apiIsReadyToUseAfterShutdown() {
@Specification(
number = "1.6.2",
text =
"The API's `shutdown` function MUST reset all state of the API, removing all hooks, event handlers, evaluation context, transaction context propagators, and providers.")
@DisplayName("shutdown must reset the state of the API")
void apiStateMustBeResetOnShuttingDownApi() {

FeatureProvider provider = ProviderFixture.createMockedProvider();
TransactionContextPropagator transactionContextPropagator = new NoOpTransactionContextPropagator();
EvaluationContext evaluationContext = mock(EvaluationContext.class);

NoOpProvider p1 = new NoOpProvider();
api.setProvider(p1);
api.setProvider(provider);
api.setEvaluationContext(evaluationContext);
api.setTransactionContextPropagator(transactionContextPropagator);
Comment thread
jarebudev marked this conversation as resolved.

api.shutdown();

NoOpProvider p2 = new NoOpProvider();
api.setProvider(p2);
assertNotEquals(provider, api.getProvider());
assertTrue(api.getHooks().isEmpty());
assertNotEquals(evaluationContext, api.getEvaluationContext());
assertNotEquals(transactionContextPropagator, api.getTransactionContextPropagator());
Comment thread
chrfwow marked this conversation as resolved.
}

@Test
Expand Down
Loading