Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

S3Mock causes some S3Client calls to block for 30 seconds #186

Open
klitoskyriacou opened this issue Sep 9, 2022 · 0 comments
Open

S3Mock causes some S3Client calls to block for 30 seconds #186

klitoskyriacou opened this issue Sep 9, 2022 · 0 comments

Comments

@klitoskyriacou
Copy link

The following code shows that S3Client.listBuckets(), which responds almost immediately when using the real AWS S3 service, blocks for 30 seconds when using S3Mock:

    @Test
    void testUpload() throws URISyntaxException {
        S3Mock mockS3 = new S3Mock.Builder().withPort(8001).withInMemoryBackend().build();
        mockS3.start();

        S3Client s3Client = S3Client.builder()
                .endpointOverride(new URI("http://localhost:8001"))
                .credentialsProvider(AnonymousCredentialsProvider.create())
                .region(Region.EU_CENTRAL_1)
                .build();
        s3Client.createBucket(CreateBucketRequest.builder().bucket("test-bucket").build());

        PutObjectRequest putObjectRequest = PutObjectRequest.builder()
                .bucket("test-bucket")
                .key("testfolder/testfile.json")
                .metadata(Map.of("contentType", "json"))
                .build();
        s3Client.putObject(putObjectRequest, RequestBody.empty());

        long start = System.nanoTime();
        ListBucketsResponse listBucketsResponse = s3Client.listBuckets();
        long end = System.nanoTime();
        System.out.printf("listBuckets() took %.1f seconds.%n%s%n", (end - start) / 1e9, listBucketsResponse);
    }

When run using mvn test (or in IntelliJ IDEA) the above test gives the following output:

listBuckets() took 30.1 seconds.
ListBucketsResponse(Buckets=[Bucket(Name=test-bucket, CreationDate=2022-09-09T16:20:26Z)], Owner=Owner(DisplayName=root, ID=731966b0-f56d-4e44-bfc9-465984e4f38c))

This test was run on Ubuntu Linux (versions 20.04 and 22.04).

For the full project (consisting of just two files) allowing you to reproduce this issue easily, clone https://github.com/klitoskyriacou/S3MockDemo.

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

No branches or pull requests

1 participant