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

Setup S3ClientV2 S3Mock for AWS SDKV2 Junit5 #2260

Open
Ghjlassi opened this issue Feb 26, 2025 · 4 comments
Open

Setup S3ClientV2 S3Mock for AWS SDKV2 Junit5 #2260

Ghjlassi opened this issue Feb 26, 2025 · 4 comments
Assignees
Labels

Comments

@Ghjlassi
Copy link

Ghjlassi commented Feb 26, 2025

Hello,

I'm using the resource you provided here to create an S3 client.

   `@RegisterExtension
    static final S3MockExtension S3_MOCK =
            S3MockExtension.builder().silent().withSecureConnection(false).build();

    private S3Client s3Client;

    @Before
    public void setUp() {
        s3Client = S3_MOCK.createS3ClientV2();
        s3Client.createBucket(CreateBucketRequest.builder().bucket("my-bucket").build());
    }`

However, I'm encountering the following error:

java.lang.NullPointerException: Cannot invoke "com.adobe.testing.s3mock.S3MockApplication.getHttpPort()" because "this.s3MockFileStore" is null

It seems that the mock isn’t initializing the endpoint correctly. From what I’ve read, JUnit 5 doesn’t require manually starting S3MockStarter, but I suspect this might be the issue.

Any insights on this?

Thanks!

@afranken afranken self-assigned this Feb 26, 2025
@afranken
Copy link
Member

Hi,
the file you linked is the Junit5 test that we use to test that the extension works on every commit.
Not sure why it wouldn't work for you - maybe your Junit5 is not configured correctly? Or the port (9090, 9191) is already in use.

Also, the S3Client is provided by the extension, you can just add it as a function parameter.

@Ghjlassi
Copy link
Author

Thanks for your answer @afranken,
I'm using S3Mock v3.12.0 and have verified that ports 9090 and 9191 are not in use.

The main issue is that the following initialization:

static final S3MockExtension S3_MOCK =
    S3MockExtension.builder().silent().withSecureConnection(false).build();

creates an instance where s3MockFileStore is null, as shown in my debugging screenshot.

Image

The createClientV2() method is invoked here, and internally, it calls:

s3MockFileStore.getHttpPort();
Since s3MockFileStore is null, this results in a NullPointerException.

I haven’t found a way to explicitly set s3MockFileStore. Any ideas on how to resolve this?

Thanks!

@afranken
Copy link
Member

Have you tried just copying the test you linked in your first comment?

@afranken
Copy link
Member

afranken commented Mar 6, 2025

@Ghjlassi did using the test from the S3Mock repository work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants