From f272018ddade17fb5b9d7728d57936de6b21ee05 Mon Sep 17 00:00:00 2001 From: olenagerasimova Date: Tue, 26 Dec 2023 11:54:35 +0300 Subject: [PATCH] revert s3 update --- asto/asto-s3/pom.xml | 34 +++++++-- .../java/com/artipie/asto/s3/BucketTest.java | 21 +++--- .../com/artipie/asto/s3/S3StorageTest.java | 69 ++++++++----------- 3 files changed, 65 insertions(+), 59 deletions(-) diff --git a/asto/asto-s3/pom.xml b/asto/asto-s3/pom.xml index 883f88270..b5214fe3b 100644 --- a/asto/asto-s3/pom.xml +++ b/asto/asto-s3/pom.xml @@ -44,7 +44,7 @@ SOFTWARE. software.amazon.awssdk s3 - 2.22.3 + 2.17.165 com.fasterxml.jackson.core @@ -61,19 +61,41 @@ SOFTWARE. com.adobe.testing s3mock - 3.2.0 + 2.4.9 test + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + org.eclipse.jetty + jetty-http + + com.adobe.testing s3mock-junit5 - 3.2.0 + 2.4.9 + test + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.11.4 test - jakarta.servlet - jakarta.servlet-api - 5.0.0 + org.eclipse.jetty + jetty-http + 9.4.45.v20220203 test diff --git a/asto/asto-s3/src/test/java/com/artipie/asto/s3/BucketTest.java b/asto/asto-s3/src/test/java/com/artipie/asto/s3/BucketTest.java index 2c09cb4ce..4c1765598 100644 --- a/asto/asto-s3/src/test/java/com/artipie/asto/s3/BucketTest.java +++ b/asto/asto-s3/src/test/java/com/artipie/asto/s3/BucketTest.java @@ -47,11 +47,6 @@ class BucketTest { .withSecureConnection(false) .build(); - /** - * Amazon client. - */ - private final AmazonS3 client = MOCK.createS3Client(); - /** * Bucket name to use in tests. */ @@ -63,9 +58,9 @@ class BucketTest { private Bucket bucket; @BeforeEach - void setUp() { + void setUp(final AmazonS3 client) { this.name = UUID.randomUUID().toString(); - this.client.createBucket(this.name); + client.createBucket(this.name); this.bucket = new Bucket( S3AsyncClient.builder() .region(Region.of("us-east-1")) @@ -81,9 +76,9 @@ void setUp() { } @Test - void shouldUploadPartAndCompleteMultipartUpload() throws Exception { + void shouldUploadPartAndCompleteMultipartUpload(final AmazonS3 client) throws Exception { final String key = "multipart"; - final String id = this.client.initiateMultipartUpload( + final String id = client.initiateMultipartUpload( new InitiateMultipartUploadRequest(this.name, key) ).getUploadId(); final byte[] data = "data".getBytes(); @@ -113,16 +108,16 @@ void shouldUploadPartAndCompleteMultipartUpload() throws Exception { ) ).join(); final byte[] downloaded; - try (S3Object s3Object = this.client.getObject(this.name, key)) { + try (S3Object s3Object = client.getObject(this.name, key)) { downloaded = ByteStreams.toByteArray(s3Object.getObjectContent()); } MatcherAssert.assertThat(downloaded, new IsEqual<>(data)); } @Test - void shouldAbortMultipartUploadWhenFailedToReadContent() { + void shouldAbortMultipartUploadWhenFailedToReadContent(final AmazonS3 client) { final String key = "abort"; - final String id = this.client.initiateMultipartUpload( + final String id = client.initiateMultipartUpload( new InitiateMultipartUploadRequest(this.name, key) ).getUploadId(); final byte[] data = "abort_test".getBytes(); @@ -143,7 +138,7 @@ void shouldAbortMultipartUploadWhenFailedToReadContent() { ) ).join(); MatcherAssert.assertThat( - this.client.listMultipartUploads( + client.listMultipartUploads( new ListMultipartUploadsRequest(this.name) ).getMultipartUploads(), new IsEmptyIterable<>() diff --git a/asto/asto-s3/src/test/java/com/artipie/asto/s3/S3StorageTest.java b/asto/asto-s3/src/test/java/com/artipie/asto/s3/S3StorageTest.java index bf4b3497c..7d4eb5b1d 100644 --- a/asto/asto-s3/src/test/java/com/artipie/asto/s3/S3StorageTest.java +++ b/asto/asto-s3/src/test/java/com/artipie/asto/s3/S3StorageTest.java @@ -57,45 +57,40 @@ class S3StorageTest { .withSecureConnection(false) .build(); - /** - * Amazon client. - */ - private final AmazonS3 client = MOCK.createS3Client(); - /** * Bucket to use in tests. */ private String bucket; @BeforeEach - void setUp() { + void setUp(final AmazonS3 client) { this.bucket = UUID.randomUUID().toString(); - this.client.createBucket(this.bucket); + client.createBucket(this.bucket); } @Test - void shouldUploadObjectWhenSave() throws Exception { + void shouldUploadObjectWhenSave(final AmazonS3 client) throws Exception { final byte[] data = "data2".getBytes(); final String key = "a/b/c"; this.storage().save(new Key.From(key), new Content.OneTime(new Content.From(data))).join(); - MatcherAssert.assertThat(this.download(key), Matchers.equalTo(data)); + MatcherAssert.assertThat(this.download(client, key), Matchers.equalTo(data)); } @Test @Timeout(5) - void shouldUploadObjectWhenSaveContentOfUnknownSize() throws Exception { + void shouldUploadObjectWhenSaveContentOfUnknownSize(final AmazonS3 client) throws Exception { final byte[] data = "data?".getBytes(); final String key = "unknown/size"; this.storage().save( new Key.From(key), new Content.OneTime(new Content.From(data)) ).join(); - MatcherAssert.assertThat(this.download(key), Matchers.equalTo(data)); + MatcherAssert.assertThat(this.download(client, key), Matchers.equalTo(data)); } @Test @Timeout(15) - void shouldUploadObjectWhenSaveLargeContent() throws Exception { + void shouldUploadObjectWhenSaveLargeContent(final AmazonS3 client) throws Exception { final int size = 20 * 1024 * 1024; final byte[] data = new byte[size]; new Random().nextBytes(data); @@ -104,28 +99,26 @@ void shouldUploadObjectWhenSaveLargeContent() throws Exception { new Key.From(key), new Content.OneTime(new Content.From(data)) ).join(); - MatcherAssert.assertThat(this.download(key), Matchers.equalTo(data)); + MatcherAssert.assertThat(this.download(client, key), Matchers.equalTo(data)); } @Test - void shouldAbortMultipartUploadWhenFailedToReadContent() { + void shouldAbortMultipartUploadWhenFailedToReadContent(final AmazonS3 client) { this.storage().save( new Key.From("abort"), new Content.OneTime(new Content.From(Flowable.error(new IllegalStateException()))) ).exceptionally(ignore -> null).join(); - final List uploads = this.client.listMultipartUploads( + final List uploads = client.listMultipartUploads( new ListMultipartUploadsRequest(this.bucket) ).getMultipartUploads(); MatcherAssert.assertThat(uploads, new IsEmptyIterable<>()); } @Test - void shouldExistForSavedObject() throws Exception { + void shouldExistForSavedObject(final AmazonS3 client) throws Exception { final byte[] data = "content".getBytes(); final String key = "some/existing/key"; - this.client.putObject( - this.bucket, key, new ByteArrayInputStream(data), new ObjectMetadata() - ); + client.putObject(this.bucket, key, new ByteArrayInputStream(data), new ObjectMetadata()); final boolean exists = new BlockingStorage(this.storage()) .exists(new Key.From(key)); MatcherAssert.assertThat( @@ -135,7 +128,7 @@ this.bucket, key, new ByteArrayInputStream(data), new ObjectMetadata() } @Test - void shouldListKeysInOrder() throws Exception { + void shouldListKeysInOrder(final AmazonS3 client) throws Exception { final byte[] data = "some data!".getBytes(); Arrays.asList( new Key.From("1"), @@ -144,7 +137,7 @@ void shouldListKeysInOrder() throws Exception { new Key.From("a", "z"), new Key.From("z") ).forEach( - key -> this.client.putObject( + key -> client.putObject( this.bucket, key.string(), new ByteArrayInputStream(data), @@ -163,12 +156,10 @@ void shouldListKeysInOrder() throws Exception { } @Test - void shouldGetObjectWhenLoad() throws Exception { + void shouldGetObjectWhenLoad(final AmazonS3 client) throws Exception { final byte[] data = "data".getBytes(); final String key = "some/key"; - this.client.putObject( - this.bucket, key, new ByteArrayInputStream(data), new ObjectMetadata() - ); + client.putObject(this.bucket, key, new ByteArrayInputStream(data), new ObjectMetadata()); final byte[] value = new BlockingStorage(this.storage()) .value(new Key.From(key)); MatcherAssert.assertThat( @@ -178,10 +169,10 @@ this.bucket, key, new ByteArrayInputStream(data), new ObjectMetadata() } @Test - void shouldCopyObjectWhenMoved() throws Exception { + void shouldCopyObjectWhenMoved(final AmazonS3 client) throws Exception { final byte[] original = "something".getBytes(); final String source = "source"; - this.client.putObject( + client.putObject( this.bucket, source, new ByteArrayInputStream(original), new ObjectMetadata() @@ -191,7 +182,7 @@ source, new ByteArrayInputStream(original), new Key.From(source), new Key.From(destination) ); - try (S3Object s3Object = this.client.getObject(this.bucket, destination)) { + try (S3Object s3Object = client.getObject(this.bucket, destination)) { MatcherAssert.assertThat( ByteStreams.toByteArray(s3Object.getObjectContent()), new IsEqual<>(original) @@ -200,9 +191,9 @@ source, new ByteArrayInputStream(original), } @Test - void shouldDeleteOriginalObjectWhenMoved() throws Exception { + void shouldDeleteOriginalObjectWhenMoved(final AmazonS3 client) throws Exception { final String source = "src"; - this.client.putObject( + client.putObject( this.bucket, source, new ByteArrayInputStream("some data".getBytes()), @@ -213,29 +204,27 @@ void shouldDeleteOriginalObjectWhenMoved() throws Exception { new Key.From("dest") ); MatcherAssert.assertThat( - this.client.doesObjectExist(this.bucket, source), + client.doesObjectExist(this.bucket, source), new IsEqual<>(false) ); } @Test - void shouldDeleteObject() throws Exception { + void shouldDeleteObject(final AmazonS3 client) throws Exception { final byte[] data = "to be deleted".getBytes(); final String key = "to/be/deleted"; - this.client.putObject( - this.bucket, key, new ByteArrayInputStream(data), new ObjectMetadata() - ); + client.putObject(this.bucket, key, new ByteArrayInputStream(data), new ObjectMetadata()); new BlockingStorage(this.storage()).delete(new Key.From(key)); MatcherAssert.assertThat( - this.client.doesObjectExist(this.bucket, key), + client.doesObjectExist(this.bucket, key), new IsEqual<>(false) ); } @Test - void readMetadata() throws Exception { + void readMetadata(final AmazonS3 client) throws Exception { final String key = "random/data"; - this.client.putObject( + client.putObject( this.bucket, key, new ByteArrayInputStream("random data".getBytes()), new ObjectMetadata() ); @@ -262,8 +251,8 @@ void returnsIdentifier() { ); } - private byte[] download(final String key) throws IOException { - try (S3Object s3Object = this.client.getObject(this.bucket, key)) { + private byte[] download(final AmazonS3 client, final String key) throws IOException { + try (S3Object s3Object = client.getObject(this.bucket, key)) { return ByteStreams.toByteArray(s3Object.getObjectContent()); } }