|
| 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 | +} |
0 commit comments