Skip to content

Update tm builder log messages #3822

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

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ public DefaultS3TransferManager(DefaultBuilder tmBuilder) {

if (s3AsyncClient instanceof S3CrtAsyncClient) {
s3ClientType = S3ClientType.CRT_BASED;
} else {
} else if (s3AsyncClient.getClass().getName().equals("software.amazon.awssdk.services.s3.DefaultS3AsyncClient")) {
s3ClientType = S3ClientType.JAVA_BASED;
log.warn(() -> "The provided S3AsyncClient is not an instance of S3CrtAsyncClient, and thus multipart"
log.warn(() -> "The provided DefaultS3AsyncClient is not an instance of S3CrtAsyncClient, and thus multipart"
+ " upload/download feature is not enabled and resumable file upload is not supported. To benefit "
+ "from maximum throughput,"
+ " consider using S3AsyncClient.crtBuilder().build() instead.");
+ "from maximum throughput, consider using S3AsyncClient.crtBuilder().build() instead.");
} else {
s3ClientType = S3ClientType.OTHER;
log.debug(() -> "The provided S3AsyncClient is not an instance of S3CrtAsyncClient, and thus multipart"
+ " upload/download feature may not be enabled and resumable file upload may not be supported.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
@SdkInternalApi
public enum S3ClientType {
CRT_BASED,
JAVA_BASED
JAVA_BASED,
OTHER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.transfer.s3.internal;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.testutils.LogCaptor;
import software.amazon.awssdk.transfer.s3.S3TransferManager;

public class TransferManagerLoggingTest {

@Test
public void transferManager_withCrtClient_shouldNotLogWarnMessages(){
LogCaptor logCaptor = LogCaptor.create(Level.WARN);
S3AsyncClient s3Crt = S3AsyncClient.crtCreate();
S3TransferManager tm = S3TransferManager.builder().s3Client(s3Crt).build();

List<LogEvent> events = logCaptor.loggedEvents();
assertThat(events).isEmpty();
logCaptor.clear();
logCaptor.close();
}

@Test
public void transferManager_withJavaClient_shouldLogWarnMessage(){
LogCaptor logCaptor = LogCaptor.create(Level.WARN);
S3AsyncClient s3Java = S3AsyncClient.create();
S3TransferManager tm = S3TransferManager.builder().s3Client(s3Java).build();

List<LogEvent> events = logCaptor.loggedEvents();
assertLogged(events, Level.WARN, "The provided DefaultS3AsyncClient is not an instance of S3CrtAsyncClient, and "
+ "thus multipart upload/download feature is not enabled and resumable file upload is "
+ "not supported. To benefit from maximum throughput, consider using "
+ "S3AsyncClient.crtBuilder().build() instead.");
logCaptor.clear();
logCaptor.close();
}

private static void assertLogged(List<LogEvent> events, org.apache.logging.log4j.Level level, String message) {
assertThat(events).withFailMessage("Expecting events to not be empty").isNotEmpty();
LogEvent event = events.remove(0);
String msg = event.getMessage().getFormattedMessage();
assertThat(msg).isEqualTo(message);
assertThat(event.getLevel()).isEqualTo(level);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.testutils.LogCaptor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I didn't know we have LogCaptor, can we use it instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, using LogCaptor from testutils instead


import software.amazon.awssdk.transfer.s3.model.CompletedObjectTransfer;
import software.amazon.awssdk.transfer.s3.model.TransferObjectRequest;
import software.amazon.awssdk.transfer.s3.internal.progress.DefaultTransferProgress;
Expand Down