Skip to content

Commit

Permalink
chore: Use setProviderAndWait now that it is available
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Sep 24, 2024
1 parent cb8350e commit 1aa9b68
Showing 1 changed file with 4 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ void init() throws InvalidOptions, ExecutionException, InterruptedException {

GoFeatureFlagProviderOptions options = GoFeatureFlagProviderOptions.builder().endpoint(relayProxyEndpoint).build();
GoFeatureFlagProvider provider = new GoFeatureFlagProvider(options);
OpenFeatureAPI.getInstance().setProvider(provider);
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
goffClient = api.getClient();
this.waitProviderReady();
}

@AfterEach
Expand Down Expand Up @@ -333,10 +332,9 @@ void authenticatedRelayProxyValid() throws InvalidOptions, ExecutionException, I
GoFeatureFlagProviderOptions options = GoFeatureFlagProviderOptions.builder()
.apiKey("authorized_token").endpoint(relayProxyAuthenticatedEndpoint).build();
GoFeatureFlagProvider provider = new GoFeatureFlagProvider(options);
OpenFeatureAPI.getInstance().setProvider(provider);
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
goffClient = api.getClient();
this.waitProviderReady();

String flagKey = "bool_targeting_match";
FlagEvaluationDetails expected = FlagEvaluationDetails.builder()
Expand All @@ -356,10 +354,9 @@ void authenticatedRelayProxyEmptyToken() throws InvalidOptions, ExecutionExcepti
GoFeatureFlagProviderOptions options = GoFeatureFlagProviderOptions.builder()
.apiKey("").endpoint(relayProxyAuthenticatedEndpoint).build();
GoFeatureFlagProvider provider = new GoFeatureFlagProvider(options);
OpenFeatureAPI.getInstance().setProvider(provider);
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
goffClient = api.getClient();
this.waitProviderReady();

String flagKey = "bool_targeting_match";
FlagEvaluationDetails expected = FlagEvaluationDetails.builder()
Expand All @@ -379,10 +376,9 @@ void authenticatedRelayProxyInvalidToken() throws InvalidOptions, ExecutionExcep
GoFeatureFlagProviderOptions options = GoFeatureFlagProviderOptions.builder()
.apiKey("invalid-api-key").endpoint(relayProxyAuthenticatedEndpoint).build();
GoFeatureFlagProvider provider = new GoFeatureFlagProvider(options);
OpenFeatureAPI.getInstance().setProvider(provider);
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
goffClient = api.getClient();
this.waitProviderReady();

String flagKey = "bool_targeting_match";
FlagEvaluationDetails expected = FlagEvaluationDetails.builder()
Expand All @@ -394,17 +390,6 @@ void authenticatedRelayProxyInvalidToken() throws InvalidOptions, ExecutionExcep
FlagEvaluationDetails<Boolean> got = goffClient.getBooleanDetails(flagKey, false, defaultEvaluationContext);
assertEquals(expected, got);
}

private void waitProviderReady() throws ExecutionException, InterruptedException {
CompletableFuture<EventDetails> completableFuture = new CompletableFuture<>();
OpenFeatureAPI.getInstance().onProviderReady(new Consumer<EventDetails>() {
@Override
public void accept(EventDetails eventDetails) {
completableFuture.complete(eventDetails);
}
});
completableFuture.get();
}
}


Expand Down

0 comments on commit 1aa9b68

Please sign in to comment.