Skip to content

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

Merged
laurit merged 16 commits into
open-telemetry:mainfrom
jaydeluca:aws-2.2-client-core
Dec 30, 2024
Merged

Convert Aws sdk 2.2 Client core tests from groovy to java#12949
laurit merged 16 commits into
open-telemetry:mainfrom
jaydeluca:aws-2.2-client-core

Conversation

@jaydeluca

Copy link
Copy Markdown
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() {

@laurit laurit Dec 23, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
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