Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ public void subscribe(ExperimentRunCallback callback) {
this.callbacks.add(callback);
}

public void shutdown() {
if (repository != null) {
repository.shutdown();
repository = null;
log.info("Repository shut down");
}
}

private <ValueType> void fireSubscriptions(Experiment<ValueType> experiment, ExperimentResult<ValueType> result) {
String key = experiment.getKey();
// If assigned variation has changed, fire subscriptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,44 @@ void test_initialization_withFailedFeatureFetch() throws FeatureFetchException {
}
}

@Test
void test_shutdown_withANonInitializedClient() {
mockRepository = createMockRepository();
mockBuilder = createMockBuilder(mockRepository);
FeatureRefreshCallback mockCallback = mock(FeatureRefreshCallback.class);

try (MockedStatic<GBFeaturesRepository> mockedStatic = mockStatic(GBFeaturesRepository.class)) {
mockedStatic.when(GBFeaturesRepository::builder).thenReturn(mockBuilder);

Options options = createDefaultOptions(mockCallback);

GrowthBookClient client = new GrowthBookClient(options);

client.shutdown();

verify(mockRepository, never()).shutdown();
}
}
@Test
void test_shutdown_withAnInitializedClient() {
mockRepository = createMockRepository();
mockBuilder = createMockBuilder(mockRepository);
FeatureRefreshCallback mockCallback = mock(FeatureRefreshCallback.class);

try (MockedStatic<GBFeaturesRepository> mockedStatic = mockStatic(GBFeaturesRepository.class)) {
mockedStatic.when(GBFeaturesRepository::builder).thenReturn(mockBuilder);

Options options = createDefaultOptions(mockCallback);

GrowthBookClient client = new GrowthBookClient(options);
client.initialize();

client.shutdown();

verify(mockRepository).shutdown();
}
}

//@Test
void test_evalFeature_withUserContext() {
String attributes = "{ \"user_group\": \"subscriber\", \"beta_users\": true }";
Expand Down Expand Up @@ -167,4 +205,4 @@ private Options createDefaultOptions(FeatureRefreshCallback callback) {
.featureRefreshCallback(callback)
.build();
}
}
}
Loading