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

Convert Aws sdk 2.2 Client core tests from groovy to java #12949

Merged
merged 16 commits into from
Dec 30, 2024

Conversation

jaydeluca
Copy link
Member

Related to #7195

@jaydeluca jaydeluca requested a review from a team as a code owner December 22, 2024 16:41
equalTo(maybeStable(DB_OPERATION), operation));
}

private static Stream<Arguments> provideArguments() {
Copy link
Contributor

@laurit laurit Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use something like

  @SuppressWarnings("unchecked")
  private static DynamoDbClient wrapClient(DynamoDbAsyncClient asyncClient) {
    return (DynamoDbClient)
        Proxy.newProxyInstance(
            DynamoDbClient.class.getClassLoader(),
            new Class<?>[] {DynamoDbClient.class},
            (proxy, method, args) -> {
              Method asyncMethod =
                  DynamoDbAsyncClient.class.getMethod(method.getName(), method.getParameterTypes());
              CompletableFuture<?> future =
                  (CompletableFuture<?>) asyncMethod.invoke(asyncClient, args);
              return future.get();
            });
  }

so that the parameters would not need to be duplicated between sync and async case. Async test could use Object response = call.apply(wrapClient(client)); Note that the response passed to validateOperationResponse won't be a Future any more with this.
Could generalize this to

  @SuppressWarnings("unchecked")
  protected static <T, U> T wrapClient(Class<T> syncClientClass, Class<U> asyncClientClass, U asyncClient) {
    return (T)
        Proxy.newProxyInstance(
            AbstractAws2ClientCoreTest.class.getClassLoader(),
            new Class<?>[] {syncClientClass},
            (proxy, method, args) -> {
              Method asyncMethod =
                  asyncClientClass.getMethod(method.getName(), method.getParameterTypes());
              CompletableFuture<?> future =
                  (CompletableFuture<?>) asyncMethod.invoke(asyncClient, args);
              return future.get();
            });
  }

from what I noticed only s3 getObject has different parameters for sync and async.
Idk if the slightly reduced code size is worth it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are a wizard. thank you for this suggestion

@laurit laurit merged commit d69fd1a into open-telemetry:main Dec 30, 2024
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants