Skip to content

Commit 889554f

Browse files
authored
chore: apply checkstyle again (#1339)
* apply checkstyle again * exclude examples from sonar * exclude e2e handlers from sonar
1 parent d0c7f91 commit 889554f

File tree

50 files changed

+1139
-1081
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1139
-1081
lines changed

.sonarcloud.properties

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1+
#
2+
# Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
# Licensed under the Apache License, Version 2.0 (the
4+
# "License"); you may not use this file except in compliance
5+
# with the License. You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
#
13+
#
14+
sonar.exclusions=examples/**/*,powertools-e2e-tests/handlers/**/*
15+
116
# Ignore code duplicates in the examples
2-
sonar.cpd.exclusions=examples/**/*,powertools-e2e-tests/**/*
17+
sonar.cpd.exclusions=examples/**/*,powertools-e2e-tests/**/*

examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
import com.amazonaws.services.lambda.runtime.Context;
44
import com.amazonaws.services.lambda.runtime.events.CloudFormationCustomResourceEvent;
5+
import java.util.Objects;
56
import org.apache.logging.log4j.LogManager;
67
import org.apache.logging.log4j.Logger;
78
import software.amazon.awssdk.awscore.exception.AwsServiceException;
89
import software.amazon.awssdk.core.exception.SdkClientException;
910
import software.amazon.awssdk.core.waiters.WaiterResponse;
1011
import software.amazon.awssdk.http.apache.ApacheHttpClient;
1112
import software.amazon.awssdk.services.s3.S3Client;
12-
import software.amazon.awssdk.services.s3.model.*;
13+
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
14+
import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
15+
import software.amazon.awssdk.services.s3.model.HeadBucketRequest;
16+
import software.amazon.awssdk.services.s3.model.HeadBucketResponse;
17+
import software.amazon.awssdk.services.s3.model.NoSuchBucketException;
1318
import software.amazon.awssdk.services.s3.waiters.S3Waiter;
1419
import software.amazon.lambda.powertools.cloudformation.AbstractCustomResourceHandler;
1520
import software.amazon.lambda.powertools.cloudformation.Response;
1621

17-
import java.util.Objects;
18-
1922
/**
2023
* Handler for requests to Lambda function.
2124
*/

examples/powertools-examples-core/src/main/java/helloworld/App.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
6161
metricsLogger().putMetric("CustomMetric1", 1, Unit.COUNT);
6262

6363
withSingleMetric("CustomMetrics2", 1, Unit.COUNT, "Another", (metric) ->
64-
{
65-
metric.setDimensions(DimensionSet.of("AnotherService", "CustomService"));
66-
metric.setDimensions(DimensionSet.of("AnotherService1", "CustomService1"));
67-
});
64+
{
65+
metric.setDimensions(DimensionSet.of("AnotherService", "CustomService"));
66+
metric.setDimensions(DimensionSet.of("AnotherService1", "CustomService1"));
67+
});
6868

6969
LoggingUtils.appendKey("test", "willBeLogged");
7070

@@ -77,11 +77,11 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
7777
String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
7878

7979
TracingUtils.withSubsegment("loggingResponse", subsegment ->
80-
{
81-
String sampled = "log something out";
82-
log.info(sampled);
83-
log.info(output);
84-
});
80+
{
81+
String sampled = "log something out";
82+
log.info(sampled);
83+
log.info(output);
84+
});
8585

8686
threadOption1();
8787

@@ -107,10 +107,10 @@ private void threadOption1() throws InterruptedException {
107107
private void threadOption2() throws InterruptedException {
108108
Entity traceEntity = AWSXRay.getTraceEntity();
109109
Thread anotherThread = new Thread(() -> withEntitySubsegment("inlineLog", traceEntity, subsegment ->
110-
{
111-
String var = "somethingToProcess";
112-
log.info("inside threaded logging inline {}", var);
113-
}));
110+
{
111+
String var = "somethingToProcess";
112+
log.info("inside threaded logging inline {}", var);
113+
}));
114114
anotherThread.start();
115115
anotherThread.join();
116116
}

examples/powertools-examples-sqs/src/main/java/org/demo/sqs/SqsMessageSender.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ public String handleRequest(final ScheduledEvent input, final Context context) {
6363
// Push 5 messages on each invoke.
6464
List<SendMessageBatchRequestEntry> batchRequestEntries = IntStream.range(0, 5)
6565
.mapToObj(value ->
66-
{
67-
Map<String, MessageAttributeValue> attributeValueHashMap = new HashMap<>();
68-
attributeValueHashMap.put("Key" + value, MessageAttributeValue.builder()
69-
.dataType("String")
70-
.stringValue("Value" + value)
71-
.build());
72-
73-
byte[] array = new byte[7];
74-
random.nextBytes(array);
75-
76-
return SendMessageBatchRequestEntry.builder()
77-
.messageAttributes(attributeValueHashMap)
78-
.id(input.getId() + value)
79-
.messageBody("Sample Message " + value)
80-
.build();
81-
}).collect(toList());
66+
{
67+
Map<String, MessageAttributeValue> attributeValueHashMap = new HashMap<>();
68+
attributeValueHashMap.put("Key" + value, MessageAttributeValue.builder()
69+
.dataType("String")
70+
.stringValue("Value" + value)
71+
.build());
72+
73+
byte[] array = new byte[7];
74+
random.nextBytes(array);
75+
76+
return SendMessageBatchRequestEntry.builder()
77+
.messageAttributes(attributeValueHashMap)
78+
.id(input.getId() + value)
79+
.messageBody("Sample Message " + value)
80+
.build();
81+
}).collect(toList());
8282

8383
SendMessageBatchResponse sendMessageBatchResponse = sqsClient.sendMessageBatch(SendMessageBatchRequest.builder()
8484
.queueUrl(queueUrl)

powertools-cloudformation/src/test/java/software/amazon/lambda/powertools/cloudformation/CloudFormationResponseTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ static CloudFormationResponse testableCloudFormationResponse() {
5858
ExecutableHttpRequest executableRequest = mock(ExecutableHttpRequest.class);
5959

6060
when(client.prepareRequest(any(HttpExecuteRequest.class))).thenAnswer(args ->
61-
{
62-
HttpExecuteRequest request = args.getArgument(0, HttpExecuteRequest.class);
63-
assertThat(request.contentStreamProvider()).isPresent();
64-
65-
InputStream inputStream = request.contentStreamProvider().get().newStream();
66-
HttpExecuteResponse response = mock(HttpExecuteResponse.class);
67-
when(response.responseBody()).thenReturn(Optional.of(AbortableInputStream.create(inputStream)));
68-
when(executableRequest.call()).thenReturn(response);
69-
return executableRequest;
70-
});
61+
{
62+
HttpExecuteRequest request = args.getArgument(0, HttpExecuteRequest.class);
63+
assertThat(request.contentStreamProvider()).isPresent();
64+
65+
InputStream inputStream = request.contentStreamProvider().get().newStream();
66+
HttpExecuteResponse response = mock(HttpExecuteResponse.class);
67+
when(response.responseBody()).thenReturn(Optional.of(AbortableInputStream.create(inputStream)));
68+
when(executableRequest.call()).thenReturn(response);
69+
return executableRequest;
70+
});
7171

7272
return new CloudFormationResponse(client);
7373
}

powertools-core/src/test/java/software/amazon/lambda/powertools/core/internal/UserAgentConfiguratorTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
class UserAgentConfiguratorTest {
3232

33-
private static final String SEM_VER_PATTERN = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
33+
private static final String SEM_VER_PATTERN =
34+
"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
3435
private static final String VERSION = UserAgentConfigurator.getProjectVersion();
3536

3637

powertools-e2e-tests/handlers/largemessage/src/main/java/software/amazon/lambda/powertools/e2e/Function.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import com.amazonaws.services.lambda.runtime.events.SQSBatchResponse;
2020
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
2121
import com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
22+
import java.nio.charset.StandardCharsets;
23+
import java.util.HashMap;
24+
import java.util.Map;
2225
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
2326
import software.amazon.awssdk.regions.Region;
2427
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
@@ -29,10 +32,6 @@
2932
import software.amazon.lambda.powertools.largemessages.LargeMessage;
3033
import software.amazon.lambda.powertools.logging.Logging;
3134

32-
import java.nio.charset.StandardCharsets;
33-
import java.util.HashMap;
34-
import java.util.Map;
35-
3635
public class Function implements RequestHandler<SQSEvent, SQSBatchResponse> {
3736

3837
private static final String TABLE_FOR_ASYNC_TESTS = System.getenv("TABLE_FOR_ASYNC_TESTS");
@@ -49,7 +48,7 @@ public Function() {
4948

5049
@Logging(logEvent = true)
5150
public SQSBatchResponse handleRequest(SQSEvent event, Context context) {
52-
for (SQSMessage message: event.getRecords()) {
51+
for (SQSMessage message : event.getRecords()) {
5352
processRawMessage(message, context);
5453
}
5554
return SQSBatchResponse.builder().build();
@@ -59,14 +58,18 @@ public SQSBatchResponse handleRequest(SQSEvent event, Context context) {
5958
private void processRawMessage(SQSMessage sqsMessage, Context context) {
6059
String bodyMD5 = md5(sqsMessage.getBody());
6160
if (!sqsMessage.getMd5OfBody().equals(bodyMD5)) {
62-
throw new SecurityException(String.format("message digest does not match, expected %s, got %s", sqsMessage.getMd5OfBody(), bodyMD5));
61+
throw new SecurityException(
62+
String.format("message digest does not match, expected %s, got %s", sqsMessage.getMd5OfBody(),
63+
bodyMD5));
6364
}
6465

6566
Map<String, AttributeValue> item = new HashMap<>();
6667
item.put("functionName", AttributeValue.builder().s(context.getFunctionName()).build());
6768
item.put("id", AttributeValue.builder().s(sqsMessage.getMessageId()).build());
6869
item.put("bodyMD5", AttributeValue.builder().s(bodyMD5).build());
69-
item.put("bodySize", AttributeValue.builder().n(String.valueOf(sqsMessage.getBody().getBytes(StandardCharsets.UTF_8).length)).build());
70+
item.put("bodySize",
71+
AttributeValue.builder().n(String.valueOf(sqsMessage.getBody().getBytes(StandardCharsets.UTF_8).length))
72+
.build());
7073

7174
client.putItem(PutItemRequest.builder().tableName(TABLE_FOR_ASYNC_TESTS).item(item).build());
7275
}

powertools-e2e-tests/handlers/largemessage_idempotent/src/main/java/software/amazon/lambda/powertools/e2e/Function.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Function(DynamoDbClient client) {
7171

7272
@Logging(logEvent = true)
7373
public SQSBatchResponse handleRequest(SQSEvent event, Context context) {
74-
for (SQSEvent.SQSMessage message: event.getRecords()) {
74+
for (SQSEvent.SQSMessage message : event.getRecords()) {
7575
processRawMessage(message, context);
7676
}
7777
return SQSBatchResponse.builder().build();
@@ -82,7 +82,9 @@ public SQSBatchResponse handleRequest(SQSEvent event, Context context) {
8282
private String processRawMessage(@IdempotencyKey SQSEvent.SQSMessage sqsMessage, Context context) {
8383
String bodyMD5 = md5(sqsMessage.getBody());
8484
if (!sqsMessage.getMd5OfBody().equals(bodyMD5)) {
85-
throw new SecurityException(String.format("message digest does not match, expected %s, got %s", sqsMessage.getMd5OfBody(), bodyMD5));
85+
throw new SecurityException(
86+
String.format("message digest does not match, expected %s, got %s", sqsMessage.getMd5OfBody(),
87+
bodyMD5));
8688
}
8789

8890
Instant now = Instant.now();
@@ -91,7 +93,9 @@ private String processRawMessage(@IdempotencyKey SQSEvent.SQSMessage sqsMessage,
9193
item.put("id", AttributeValue.builder().s(sqsMessage.getMessageId()).build());
9294
item.put("bodyMD5", AttributeValue.builder().s(bodyMD5).build());
9395
item.put("now", AttributeValue.builder().n(String.valueOf(now.getEpochSecond())).build());
94-
item.put("bodySize", AttributeValue.builder().n(String.valueOf(sqsMessage.getBody().getBytes(StandardCharsets.UTF_8).length)).build());
96+
item.put("bodySize",
97+
AttributeValue.builder().n(String.valueOf(sqsMessage.getBody().getBytes(StandardCharsets.UTF_8).length))
98+
.build());
9599

96100
client.putItem(PutItemRequest.builder().tableName(TABLE_FOR_ASYNC_TESTS).item(item).build());
97101

powertools-e2e-tests/handlers/tracing/src/main/java/software/amazon/lambda/powertools/e2e/Function.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public String handleRequest(Input input, Context context) {
3131
String message = buildMessage(input.getMessage(), context.getFunctionName());
3232

3333
TracingUtils.withSubsegment("internal_stuff", subsegment ->
34-
{
35-
try {
36-
Thread.sleep(100); // simulate stuff
37-
} catch (InterruptedException e) {
38-
throw new RuntimeException(e);
39-
}
40-
});
34+
{
35+
try {
36+
Thread.sleep(100); // simulate stuff
37+
} catch (InterruptedException e) {
38+
throw new RuntimeException(e);
39+
}
40+
});
4141

4242
return message;
4343
}

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/LargeMessageE2ET.java

+29-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package software.amazon.lambda.powertools;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static software.amazon.lambda.powertools.testutils.Infrastructure.FUNCTION_NAME_OUTPUT;
5+
36
import com.amazon.sqs.javamessaging.AmazonSQSExtendedClient;
47
import com.amazon.sqs.javamessaging.ExtendedClientConfiguration;
8+
import java.io.IOException;
9+
import java.io.InputStream;
10+
import java.nio.charset.StandardCharsets;
11+
import java.util.Collections;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
import java.util.UUID;
16+
import java.util.concurrent.TimeUnit;
517
import org.apache.commons.io.IOUtils;
618
import org.junit.jupiter.api.AfterAll;
719
import org.junit.jupiter.api.AfterEach;
@@ -23,19 +35,6 @@
2335
import software.amazon.awssdk.services.sqs.model.SendMessageRequest;
2436
import software.amazon.lambda.powertools.testutils.Infrastructure;
2537

26-
import java.io.IOException;
27-
import java.io.InputStream;
28-
import java.nio.charset.StandardCharsets;
29-
import java.util.Collections;
30-
import java.util.HashMap;
31-
import java.util.List;
32-
import java.util.Map;
33-
import java.util.UUID;
34-
import java.util.concurrent.TimeUnit;
35-
36-
import static org.assertj.core.api.Assertions.assertThat;
37-
import static software.amazon.lambda.powertools.testutils.Infrastructure.FUNCTION_NAME_OUTPUT;
38-
3938
public class LargeMessageE2ET {
4039

4140
private static final Logger LOG = LoggerFactory.getLogger(LargeMessageE2ET.class);
@@ -81,6 +80,13 @@ public static void setup() {
8180
LOG.info("Testing '" + LargeMessageE2ET.class.getSimpleName() + "'");
8281
}
8382

83+
@AfterAll
84+
public static void tearDown() {
85+
if (infrastructure != null) {
86+
infrastructure.destroy();
87+
}
88+
}
89+
8490
@AfterEach
8591
public void reset() {
8692
if (messageId != null) {
@@ -92,19 +98,14 @@ public void reset() {
9298
}
9399
}
94100

95-
@AfterAll
96-
public static void tearDown() {
97-
if (infrastructure != null)
98-
infrastructure.destroy();
99-
}
100-
101101
@Test
102102
public void bigSQSMessageOffloadedToS3_shouldLoadFromS3() throws IOException, InterruptedException {
103103
// given
104104
final ExtendedClientConfiguration extendedClientConfig =
105105
new ExtendedClientConfiguration()
106106
.withPayloadSupportEnabled(s3Client, bucketName);
107-
AmazonSQSExtendedClient client = new AmazonSQSExtendedClient(SqsClient.builder().httpClient(httpClient).build(), extendedClientConfig);
107+
AmazonSQSExtendedClient client =
108+
new AmazonSQSExtendedClient(SqsClient.builder().httpClient(httpClient).build(), extendedClientConfig);
108109
InputStream inputStream = this.getClass().getResourceAsStream("/large_sqs_message.txt");
109110
String bigMessage = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
110111

@@ -122,7 +123,8 @@ public void bigSQSMessageOffloadedToS3_shouldLoadFromS3() throws IOException, In
122123
.builder()
123124
.tableName(tableName)
124125
.keyConditionExpression("functionName = :func")
125-
.expressionAttributeValues(Collections.singletonMap(":func", AttributeValue.builder().s(functionName).build()))
126+
.expressionAttributeValues(
127+
Collections.singletonMap(":func", AttributeValue.builder().s(functionName).build()))
126128
.build();
127129
QueryResponse response = dynamoDbClient.query(request);
128130
List<Map<String, AttributeValue>> items = response.items();
@@ -138,7 +140,8 @@ public void smallSQSMessage_shouldNotReadFromS3() throws IOException, Interrupte
138140
final ExtendedClientConfiguration extendedClientConfig =
139141
new ExtendedClientConfiguration()
140142
.withPayloadSupportEnabled(s3Client, bucketName);
141-
AmazonSQSExtendedClient client = new AmazonSQSExtendedClient(SqsClient.builder().httpClient(httpClient).build(), extendedClientConfig);
143+
AmazonSQSExtendedClient client =
144+
new AmazonSQSExtendedClient(SqsClient.builder().httpClient(httpClient).build(), extendedClientConfig);
142145
String message = "Hello World";
143146

144147
// when
@@ -155,13 +158,15 @@ public void smallSQSMessage_shouldNotReadFromS3() throws IOException, Interrupte
155158
.builder()
156159
.tableName(tableName)
157160
.keyConditionExpression("functionName = :func")
158-
.expressionAttributeValues(Collections.singletonMap(":func", AttributeValue.builder().s(functionName).build()))
161+
.expressionAttributeValues(
162+
Collections.singletonMap(":func", AttributeValue.builder().s(functionName).build()))
159163
.build();
160164
QueryResponse response = dynamoDbClient.query(request);
161165
List<Map<String, AttributeValue>> items = response.items();
162166
assertThat(items).hasSize(1);
163167
messageId = items.get(0).get("id").s();
164-
assertThat(Integer.valueOf(items.get(0).get("bodySize").n())).isEqualTo(message.getBytes(StandardCharsets.UTF_8).length);
168+
assertThat(Integer.valueOf(items.get(0).get("bodySize").n())).isEqualTo(
169+
message.getBytes(StandardCharsets.UTF_8).length);
165170
assertThat(items.get(0).get("bodyMD5").s()).isEqualTo("b10a8db164e0754105b7a99be72e3fe5");
166171
}
167172
}

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/LargeMessageIdempotentE2ET.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public void test_ttlNotExpired_doesNotInsertInDDB_ttlExpired_insertInDDB() throw
142142
.builder()
143143
.tableName(tableName)
144144
.keyConditionExpression("functionName = :func")
145-
.expressionAttributeValues(Collections.singletonMap(":func", AttributeValue.builder().s(functionName).build()))
145+
.expressionAttributeValues(
146+
Collections.singletonMap(":func", AttributeValue.builder().s(functionName).build()))
146147
.build();
147148
QueryResponse response = dynamoDbClient.query(request);
148149
List<Map<String, AttributeValue>> items = response.items();

0 commit comments

Comments
 (0)