Skip to content

Commit

Permalink
revert s3 update
Browse files Browse the repository at this point in the history
  • Loading branch information
olenagerasimova committed Dec 26, 2023
1 parent 051ef7c commit f272018
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 59 deletions.
34 changes: 28 additions & 6 deletions asto/asto-s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SOFTWARE.
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.22.3</version>
<version>2.17.165</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -61,19 +61,41 @@ SOFTWARE.
<dependency>
<groupId>com.adobe.testing</groupId>
<artifactId>s3mock</artifactId>
<version>3.2.0</version>
<version>2.4.9</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.adobe.testing</groupId>
<artifactId>s3mock-junit5</artifactId>
<version>3.2.0</version>
<version>2.4.9</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.11.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>9.4.45.v20220203</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
21 changes: 8 additions & 13 deletions asto/asto-s3/src/test/java/com/artipie/asto/s3/BucketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ class BucketTest {
.withSecureConnection(false)
.build();

/**
* Amazon client.
*/
private final AmazonS3 client = MOCK.createS3Client();

/**
* Bucket name to use in tests.
*/
Expand All @@ -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"))
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -143,7 +138,7 @@ void shouldAbortMultipartUploadWhenFailedToReadContent() {
)
).join();
MatcherAssert.assertThat(
this.client.listMultipartUploads(
client.listMultipartUploads(
new ListMultipartUploadsRequest(this.name)
).getMultipartUploads(),
new IsEmptyIterable<>()
Expand Down
69 changes: 29 additions & 40 deletions asto/asto-s3/src/test/java/com/artipie/asto/s3/S3StorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<MultipartUpload> uploads = this.client.listMultipartUploads(
final List<MultipartUpload> 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(
Expand All @@ -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"),
Expand All @@ -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),
Expand All @@ -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(
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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()),
Expand All @@ -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()
);
Expand All @@ -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());
}
}
Expand Down

0 comments on commit f272018

Please sign in to comment.