Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(java): Use setProviderAndWait in the integration tests #2423

Merged
merged 1 commit into from
Sep 24, 2024
Merged
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 @@ -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
Loading