25
25
import software .amazon .lambda .powertools .idempotency .exceptions .IdempotencyItemNotFoundException ;
26
26
import software .amazon .lambda .powertools .idempotency .exceptions .IdempotencyKeyException ;
27
27
import software .amazon .lambda .powertools .idempotency .exceptions .IdempotencyValidationException ;
28
+ import software .amazon .lambda .powertools .idempotency .internal .cache .LRUCache ;
28
29
import software .amazon .lambda .powertools .idempotency .model .Product ;
29
30
import software .amazon .lambda .powertools .utilities .JsonConfig ;
30
- import software .amazon .lambda .powertools .utilities .cache .LRUCache ;
31
31
32
32
import java .time .Duration ;
33
33
import java .time .Instant ;
@@ -97,7 +97,6 @@ public void saveInProgress_jmespath() {
97
97
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
98
98
persistenceStore .configure (IdempotencyConfig .builder ()
99
99
.withEventKeyJMESPath ("powertools_json(body).id" )
100
- .withUseLocalCache (false )
101
100
.build (), "myfunc" );
102
101
103
102
Instant now = Instant .now ();
@@ -114,7 +113,6 @@ public void saveInProgress_jmespath() {
114
113
public void saveInProgress_jmespath_NotFound_shouldThrowException () {
115
114
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
116
115
persistenceStore .configure (IdempotencyConfig .builder ()
117
- .withUseLocalCache (false )
118
116
.withEventKeyJMESPath ("unavailable" )
119
117
.withThrowOnNoIdempotencyKey (true ) // should throw
120
118
.build (), "" );
@@ -129,7 +127,6 @@ public void saveInProgress_jmespath_NotFound_shouldThrowException() {
129
127
public void saveInProgress_jmespath_NotFound_shouldNotThrowException () {
130
128
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
131
129
persistenceStore .configure (IdempotencyConfig .builder ()
132
- .withUseLocalCache (false )
133
130
.withEventKeyJMESPath ("unavailable" )
134
131
.build (), "" );
135
132
Instant now = Instant .now ();
@@ -143,6 +140,7 @@ public void saveInProgress_withLocalCache_NotExpired_ShouldThrowException() {
143
140
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
144
141
LRUCache <String , DataRecord > cache = new LRUCache <>(2 );
145
142
persistenceStore .configure (IdempotencyConfig .builder ()
143
+ .withUseLocalCache (true )
146
144
.withEventKeyJMESPath ("powertools_json(body).id" )
147
145
.build (), null , cache );
148
146
Instant now = Instant .now ();
@@ -164,6 +162,7 @@ public void saveInProgress_withLocalCache_Expired_ShouldRemoveFromCache() {
164
162
LRUCache <String , DataRecord > cache = new LRUCache <>(2 );
165
163
persistenceStore .configure (IdempotencyConfig .builder ()
166
164
.withEventKeyJMESPath ("powertools_json(body).id" )
165
+ .withUseLocalCache (true )
167
166
.withExpiration (Duration .of (2 , ChronoUnit .SECONDS ))
168
167
.build (), null , cache );
169
168
Instant now = Instant .now ();
@@ -189,7 +188,7 @@ public void saveInProgress_withLocalCache_Expired_ShouldRemoveFromCache() {
189
188
public void saveSuccess_shouldUpdateRecord () throws JsonProcessingException {
190
189
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
191
190
LRUCache <String , DataRecord > cache = new LRUCache <>(2 );
192
- persistenceStore .configure (IdempotencyConfig .builder ().withUseLocalCache ( false ). build (), null , cache );
191
+ persistenceStore .configure (IdempotencyConfig .builder ().build (), null , cache );
193
192
194
193
Product product = new Product (34543 , "product" , 42 );
195
194
Instant now = Instant .now ();
@@ -208,7 +207,8 @@ public void saveSuccess_shouldUpdateRecord() throws JsonProcessingException {
208
207
public void saveSuccess_withCacheEnabled_shouldSaveInCache () throws JsonProcessingException {
209
208
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
210
209
LRUCache <String , DataRecord > cache = new LRUCache <>(2 );
211
- persistenceStore .configure (IdempotencyConfig .builder ().build (), null , cache );
210
+ persistenceStore .configure (IdempotencyConfig .builder ()
211
+ .withUseLocalCache (true ).build (), null , cache );
212
212
213
213
Product product = new Product (34543 , "product" , 42 );
214
214
Instant now = Instant .now ();
@@ -234,7 +234,7 @@ public void saveSuccess_withCacheEnabled_shouldSaveInCache() throws JsonProcessi
234
234
public void getRecord_shouldReturnRecordFromPersistence () throws IdempotencyItemNotFoundException , IdempotencyValidationException {
235
235
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
236
236
LRUCache <String , DataRecord > cache = new LRUCache <>(2 );
237
- persistenceStore .configure (IdempotencyConfig .builder ().withUseLocalCache ( false ). build (), "myfunc" , cache );
237
+ persistenceStore .configure (IdempotencyConfig .builder ().build (), "myfunc" , cache );
238
238
239
239
Instant now = Instant .now ();
240
240
DataRecord record = persistenceStore .getRecord (JsonConfig .get ().getObjectMapper ().valueToTree (event ), now );
@@ -248,7 +248,8 @@ public void getRecord_shouldReturnRecordFromPersistence() throws IdempotencyItem
248
248
public void getRecord_cacheEnabledNotExpired_shouldReturnRecordFromCache () throws IdempotencyItemNotFoundException , IdempotencyValidationException {
249
249
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
250
250
LRUCache <String , DataRecord > cache = new LRUCache <>(2 );
251
- persistenceStore .configure (IdempotencyConfig .builder ().build (), "myfunc" , cache );
251
+ persistenceStore .configure (IdempotencyConfig .builder ()
252
+ .withUseLocalCache (true ).build (), "myfunc" , cache );
252
253
253
254
Instant now = Instant .now ();
254
255
DataRecord dr = new DataRecord (
@@ -270,7 +271,8 @@ public void getRecord_cacheEnabledNotExpired_shouldReturnRecordFromCache() throw
270
271
public void getRecord_cacheEnabledExpired_shouldReturnRecordFromPersistence () throws IdempotencyItemNotFoundException , IdempotencyValidationException {
271
272
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
272
273
LRUCache <String , DataRecord > cache = new LRUCache <>(2 );
273
- persistenceStore .configure (IdempotencyConfig .builder ().build (), "myfunc" , cache );
274
+ persistenceStore .configure (IdempotencyConfig .builder ()
275
+ .withUseLocalCache (true ).build (), "myfunc" , cache );
274
276
275
277
Instant now = Instant .now ();
276
278
DataRecord dr = new DataRecord (
@@ -323,7 +325,8 @@ public void deleteRecord_shouldDeleteRecordFromPersistence() {
323
325
public void deleteRecord_cacheEnabled_shouldDeleteRecordFromCache () {
324
326
APIGatewayProxyRequestEvent event = EventLoader .loadApiGatewayRestEvent ("apigw_event.json" );
325
327
LRUCache <String , DataRecord > cache = new LRUCache <>(2 );
326
- persistenceStore .configure (IdempotencyConfig .builder ().build (), null , cache );
328
+ persistenceStore .configure (IdempotencyConfig .builder ()
329
+ .withUseLocalCache (true ).build (), null , cache );
327
330
328
331
cache .put ("testFunction#47261bd5b456f400f8d191cfb3a7482f" ,
329
332
new DataRecord ("testFunction#47261bd5b456f400f8d191cfb3a7482f" , DataRecord .Status .COMPLETED , 123 , null , null ));
0 commit comments