Skip to content

Commit 2ed8dd0

Browse files
authored
Update tm builder log messages (#3822)
* Update logging and add OTHER enum type to S3ClientType * Add tests * Refactoring * Remove third party plugin
1 parent 8048cd6 commit 2ed8dd0

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/DefaultS3TransferManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@ public DefaultS3TransferManager(DefaultBuilder tmBuilder) {
120120

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

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/S3ClientType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
@SdkInternalApi
2626
public enum S3ClientType {
2727
CRT_BASED,
28-
JAVA_BASED
28+
JAVA_BASED,
29+
OTHER
2930
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.transfer.s3.internal;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import java.util.List;
21+
import org.apache.logging.log4j.Level;
22+
import org.apache.logging.log4j.core.LogEvent;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
import software.amazon.awssdk.services.s3.S3AsyncClient;
26+
import software.amazon.awssdk.testutils.LogCaptor;
27+
import software.amazon.awssdk.transfer.s3.S3TransferManager;
28+
29+
public class TransferManagerLoggingTest {
30+
31+
@Test
32+
public void transferManager_withCrtClient_shouldNotLogWarnMessages(){
33+
LogCaptor logCaptor = LogCaptor.create(Level.WARN);
34+
S3AsyncClient s3Crt = S3AsyncClient.crtCreate();
35+
S3TransferManager tm = S3TransferManager.builder().s3Client(s3Crt).build();
36+
37+
List<LogEvent> events = logCaptor.loggedEvents();
38+
assertThat(events).isEmpty();
39+
logCaptor.clear();
40+
logCaptor.close();
41+
}
42+
43+
@Test
44+
public void transferManager_withJavaClient_shouldLogWarnMessage(){
45+
LogCaptor logCaptor = LogCaptor.create(Level.WARN);
46+
S3AsyncClient s3Java = S3AsyncClient.create();
47+
S3TransferManager tm = S3TransferManager.builder().s3Client(s3Java).build();
48+
49+
List<LogEvent> events = logCaptor.loggedEvents();
50+
assertLogged(events, Level.WARN, "The provided DefaultS3AsyncClient is not an instance of S3CrtAsyncClient, and "
51+
+ "thus multipart upload/download feature is not enabled and resumable file upload is "
52+
+ "not supported. To benefit from maximum throughput, consider using "
53+
+ "S3AsyncClient.crtBuilder().build() instead.");
54+
logCaptor.clear();
55+
logCaptor.close();
56+
}
57+
58+
private static void assertLogged(List<LogEvent> events, org.apache.logging.log4j.Level level, String message) {
59+
assertThat(events).withFailMessage("Expecting events to not be empty").isNotEmpty();
60+
LogEvent event = events.remove(0);
61+
String msg = event.getMessage().getFormattedMessage();
62+
assertThat(msg).isEqualTo(message);
63+
assertThat(event.getLevel()).isEqualTo(level);
64+
}
65+
}

services-custom/s3-transfer-manager/src/test/java/software/amazon/awssdk/transfer/s3/progress/LoggingTransferListenerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
2626
import software.amazon.awssdk.testutils.LogCaptor;
27+
2728
import software.amazon.awssdk.transfer.s3.model.CompletedObjectTransfer;
2829
import software.amazon.awssdk.transfer.s3.model.TransferObjectRequest;
2930
import software.amazon.awssdk.transfer.s3.internal.progress.DefaultTransferProgress;

0 commit comments

Comments
 (0)