localstack/localstack-java-utils

Why are the TestUtils sdk v2 sync clients deprecated?

shduke opened this issue · 3 comments

The TestUtils class in the awssdkv2 package only has async clients; however, the TestUtils in the deprecated package has sync clients. Is there some historic context/reason why the sync ones were deprecated or weren't ported over to the awssdkv2 package as well? Maybe a compatibility issue or something? I couldn't infer the context from the commit messages.

Thanks for the pointer @shduke . There is no particular reason for the current state - the sync clients per se are not deprecated, but the current state/layout of the codebase is a result of several refactoring steps in the past (e.g., some utils we moved to CommonUtils.java, and most of the client factory methods were moved into the v1/v2 specific packages).

In general, the code base in this repo has grown quite organically, and hasn't received too much attention in terms of refactoring, reducing code duplication, etc.

If you could add some refactoring and/or migrate some of the sync clients into the v2 package, that would be awesome. Any PRs would be much appreciated! Thanks for your help.

I found a way to be able to utilize localstack when testing with the v2 sync apis. Basically it just overrides the builder methods

        Ec2ClientBuilder mockec2 = Ec2Client.builder().endpointOverride(URI.create(Localstack.INSTANCE.getEndpointEC2()));
        PowerMockito.mockStatic(Ec2Client.class);
        when(Ec2Client.builder()).thenReturn(mockec2); 

then just make sure you annotate appropriately

@PrepareForTest({ Ec2Client.class })

you should be able to override anything exposed though the builder via this method.

Hi! We just wanted to follow up to see whether your issue has been resolved. Were you able to get it working with the latest version of LocalStack? We would appreciate your feedback!