1
1
package software .amazon .lambda .powertools ;
2
2
3
+ import static org .assertj .core .api .Assertions .assertThat ;
4
+ import static software .amazon .lambda .powertools .testutils .Infrastructure .FUNCTION_NAME_OUTPUT ;
5
+
3
6
import com .amazon .sqs .javamessaging .AmazonSQSExtendedClient ;
4
7
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 ;
5
17
import org .apache .commons .io .IOUtils ;
6
18
import org .junit .jupiter .api .AfterAll ;
7
19
import org .junit .jupiter .api .AfterEach ;
23
35
import software .amazon .awssdk .services .sqs .model .SendMessageRequest ;
24
36
import software .amazon .lambda .powertools .testutils .Infrastructure ;
25
37
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
-
39
38
public class LargeMessageE2ET {
40
39
41
40
private static final Logger LOG = LoggerFactory .getLogger (LargeMessageE2ET .class );
@@ -81,6 +80,13 @@ public static void setup() {
81
80
LOG .info ("Testing '" + LargeMessageE2ET .class .getSimpleName () + "'" );
82
81
}
83
82
83
+ @ AfterAll
84
+ public static void tearDown () {
85
+ if (infrastructure != null ) {
86
+ infrastructure .destroy ();
87
+ }
88
+ }
89
+
84
90
@ AfterEach
85
91
public void reset () {
86
92
if (messageId != null ) {
@@ -92,19 +98,14 @@ public void reset() {
92
98
}
93
99
}
94
100
95
- @ AfterAll
96
- public static void tearDown () {
97
- if (infrastructure != null )
98
- infrastructure .destroy ();
99
- }
100
-
101
101
@ Test
102
102
public void bigSQSMessageOffloadedToS3_shouldLoadFromS3 () throws IOException , InterruptedException {
103
103
// given
104
104
final ExtendedClientConfiguration extendedClientConfig =
105
105
new ExtendedClientConfiguration ()
106
106
.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 );
108
109
InputStream inputStream = this .getClass ().getResourceAsStream ("/large_sqs_message.txt" );
109
110
String bigMessage = IOUtils .toString (inputStream , StandardCharsets .UTF_8 );
110
111
@@ -122,7 +123,8 @@ public void bigSQSMessageOffloadedToS3_shouldLoadFromS3() throws IOException, In
122
123
.builder ()
123
124
.tableName (tableName )
124
125
.keyConditionExpression ("functionName = :func" )
125
- .expressionAttributeValues (Collections .singletonMap (":func" , AttributeValue .builder ().s (functionName ).build ()))
126
+ .expressionAttributeValues (
127
+ Collections .singletonMap (":func" , AttributeValue .builder ().s (functionName ).build ()))
126
128
.build ();
127
129
QueryResponse response = dynamoDbClient .query (request );
128
130
List <Map <String , AttributeValue >> items = response .items ();
@@ -138,7 +140,8 @@ public void smallSQSMessage_shouldNotReadFromS3() throws IOException, Interrupte
138
140
final ExtendedClientConfiguration extendedClientConfig =
139
141
new ExtendedClientConfiguration ()
140
142
.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 );
142
145
String message = "Hello World" ;
143
146
144
147
// when
@@ -155,13 +158,15 @@ public void smallSQSMessage_shouldNotReadFromS3() throws IOException, Interrupte
155
158
.builder ()
156
159
.tableName (tableName )
157
160
.keyConditionExpression ("functionName = :func" )
158
- .expressionAttributeValues (Collections .singletonMap (":func" , AttributeValue .builder ().s (functionName ).build ()))
161
+ .expressionAttributeValues (
162
+ Collections .singletonMap (":func" , AttributeValue .builder ().s (functionName ).build ()))
159
163
.build ();
160
164
QueryResponse response = dynamoDbClient .query (request );
161
165
List <Map <String , AttributeValue >> items = response .items ();
162
166
assertThat (items ).hasSize (1 );
163
167
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 );
165
170
assertThat (items .get (0 ).get ("bodyMD5" ).s ()).isEqualTo ("b10a8db164e0754105b7a99be72e3fe5" );
166
171
}
167
172
}
0 commit comments