14
14
15
15
package software .amazon .lambda .powertools ;
16
16
17
- import static software .amazon .lambda .powertools .testutils .Infrastructure .FUNCTION_NAME_OUTPUT ;
18
- import static software .amazon .lambda .powertools .testutils .lambda .LambdaInvoker .invokeFunction ;
19
-
20
17
import com .fasterxml .jackson .core .JsonProcessingException ;
21
- import com .fasterxml .jackson .databind .JsonMappingException ;
22
18
import com .fasterxml .jackson .databind .ObjectMapper ;
23
- import java .time .Year ;
24
- import java .util .ArrayList ;
25
- import java .util .Arrays ;
26
- import java .util .HashMap ;
27
- import java .util .List ;
28
- import java .util .Map ;
29
- import java .util .UUID ;
30
- import java .util .concurrent .TimeUnit ;
31
- import java .util .stream .Collectors ;
32
- import java .util .stream .Stream ;
33
- import org .assertj .core .api .Assertions ;
34
- import org .junit .jupiter .api .AfterAll ;
35
- import org .junit .jupiter .api .AfterEach ;
36
- import org .junit .jupiter .api .BeforeAll ;
37
- import org .junit .jupiter .api .Test ;
38
- import org .junit .jupiter .api .Timeout ;
19
+ import org .junit .jupiter .api .*;
39
20
import software .amazon .awssdk .core .SdkBytes ;
40
21
import software .amazon .awssdk .http .SdkHttpClient ;
41
22
import software .amazon .awssdk .http .urlconnection .UrlConnectionHttpClient ;
42
23
import software .amazon .awssdk .regions .Region ;
43
24
import software .amazon .awssdk .services .dynamodb .DynamoDbClient ;
44
- import software .amazon .awssdk .services .dynamodb .DynamoDbClientBuilder ;
45
25
import software .amazon .awssdk .services .dynamodb .model .*;
46
26
import software .amazon .awssdk .services .kinesis .KinesisClient ;
47
27
import software .amazon .awssdk .services .kinesis .model .PutRecordsRequest ;
50
30
import software .amazon .awssdk .services .sqs .SqsClient ;
51
31
import software .amazon .awssdk .services .sqs .model .SendMessageBatchRequest ;
52
32
import software .amazon .awssdk .services .sqs .model .SendMessageBatchRequestEntry ;
53
- import software .amazon .awssdk .services .sqs .model .SendMessageRequest ;
54
33
import software .amazon .lambda .powertools .testutils .Infrastructure ;
55
- import software .amazon .lambda .powertools .testutils .lambda .InvocationResult ;
56
34
import software .amazon .lambda .powertools .utilities .JsonConfig ;
35
+
36
+ import java .util .*;
37
+ import java .util .concurrent .TimeUnit ;
38
+ import java .util .stream .Collectors ;
39
+
57
40
import static org .assertj .core .api .Assertions .assertThat ;
41
+ import static software .amazon .lambda .powertools .testutils .Infrastructure .FUNCTION_NAME_OUTPUT ;
58
42
59
43
public class BatchE2ET {
60
- private static Infrastructure infrastructure ;
61
- private static String functionName ;
62
44
private static final SdkHttpClient httpClient = UrlConnectionHttpClient .builder ().build ();
63
45
private static final Region region = Region .of (System .getProperty ("AWS_DEFAULT_REGION" , "eu-west-1" ));
46
+ private static Infrastructure infrastructure ;
47
+ private static String functionName ;
64
48
private static String queueUrl ;
65
49
private static String kinesisStreamName ;
66
50
@@ -72,6 +56,14 @@ public class BatchE2ET {
72
56
private static String ddbStreamsTestTable ;
73
57
private final List <Product > testProducts ;
74
58
59
+ public BatchE2ET () {
60
+ testProducts = Arrays .asList (
61
+ new Product (1 , "product1" , 1.23 ),
62
+ new Product (2 , "product2" , 4.56 ),
63
+ new Product (3 , "product3" , 6.78 )
64
+ );
65
+ }
66
+
75
67
@ BeforeAll
76
68
@ Timeout (value = 5 , unit = TimeUnit .MINUTES )
77
69
public static void setup () {
@@ -97,7 +89,7 @@ public static void setup() {
97
89
kinesisStreamName = outputs .get ("KinesisStreamName" );
98
90
outputTable = outputs .get ("TableNameForAsyncTests" );
99
91
ddbStreamsTestTable = outputs .get ("DdbStreamsTestTable" );
100
-
92
+
101
93
ddbClient = DynamoDbClient .builder ()
102
94
.region (region )
103
95
.httpClient (httpClient )
@@ -114,14 +106,22 @@ public static void setup() {
114
106
.build ();
115
107
}
116
108
109
+ @ AfterAll
110
+ public static void tearDown () {
111
+ // TODO bring this back after testing
112
+ if (infrastructure != null ) {
113
+ // infrastructure.destroy();
114
+ }
115
+ }
116
+
117
117
@ AfterEach
118
118
public void cleanUpTest () {
119
119
// Delete everything in the output table
120
120
ScanResponse items = ddbClient .scan (ScanRequest .builder ()
121
121
.tableName (outputTable )
122
122
.build ());
123
123
124
- for (Map <String , AttributeValue > item :items .items ()) {
124
+ for (Map <String , AttributeValue > item : items .items ()) {
125
125
HashMap <String , AttributeValue > key = new HashMap <String , AttributeValue >() {
126
126
{
127
127
put ("functionName" , AttributeValue .builder ()
@@ -130,28 +130,13 @@ public void cleanUpTest() {
130
130
put ("id" , AttributeValue .builder ()
131
131
.s (item .get ("id" ).s ())
132
132
.build ());
133
- }};
133
+ }
134
+ };
134
135
135
136
ddbClient .deleteItem (DeleteItemRequest .builder ()
136
- .tableName (outputTable )
137
- .key (key )
138
- .build ());
139
- }
140
- }
141
-
142
- public BatchE2ET () {
143
- testProducts = Arrays .asList (
144
- new Product (1 , "product1" , 1.23 ),
145
- new Product (2 , "product2" , 4.56 ),
146
- new Product (3 , "product3" , 6.78 )
147
- );
148
- }
149
-
150
- @ AfterAll
151
- public static void tearDown () {
152
- // TODO bring this back after testing
153
- if (infrastructure != null ) {
154
- // infrastructure.destroy();
137
+ .tableName (outputTable )
138
+ .key (key )
139
+ .build ());
155
140
}
156
141
}
157
142
@@ -219,15 +204,16 @@ public void ddbStreamsBatchProcessingSucceeds() throws InterruptedException {
219
204
String theId = "my-test-id" ;
220
205
221
206
// WHEN
222
- ddbClient .putItem (PutItemRequest .builder ()
223
- .tableName (ddbStreamsTestTable )
224
- .item (new HashMap <String , AttributeValue >() {
225
- {
226
- put ("id" , AttributeValue .builder ()
227
- .s (theId )
228
- .build ());
229
- }})
230
- .build ());
207
+ ddbClient .putItem (PutItemRequest .builder ()
208
+ .tableName (ddbStreamsTestTable )
209
+ .item (new HashMap <String , AttributeValue >() {
210
+ {
211
+ put ("id" , AttributeValue .builder ()
212
+ .s (theId )
213
+ .build ());
214
+ }
215
+ })
216
+ .build ());
231
217
Thread .sleep (90000 ); // wait for function to be executed
232
218
233
219
// THEN
0 commit comments