localstack/localstack-java-utils

Localstack docker beans do not work with PER_CLASS JUnit Lifecycle

235daniel opened this issue · 0 comments

Under a PER_CLASS JUnit lifecycle, attempting to wire up Spring test beans (such as a DynamoDB client) returns this error:
java.lang.RuntimeException: Container not started. I believe this is because the Spring application context is loaded before the extension's beforeAll method (https://github.com/localstack/localstack-java-utils/blob/master/src/main/java/cloud/localstack/docker/LocalstackDockerExtension.java#L33) initializes the Localstack containers within a PER_CLASS lifecycle.

Also noticed this issue which seems to mention the same problem: localstack/localstack#1067, but I'm not sure the PR mentioned in that issue was ever created and merged. I was able to fix this issue by creating a custom version of the LocalstackDockerExtension that implements TestInstancePostProcessor (which is loaded before the Spring application context under a PER_CLASS lifecycle) using the same code from the existing beforeAll method.

I can create a PR to add this fix, but I'm wondering if there's any better ways to get this working or if there's any issues with that approach?