@@ -265,6 +265,38 @@ public void testWhenIgnorePayloadNotFoundIsSentThenNotFoundKeysInS3AreDeletedInS
265
265
Assert .assertEquals ("receipt-handle" , deleteMessageRequestArgumentCaptor .getValue ().getReceiptHandle ());
266
266
}
267
267
268
+ @ Test
269
+ public void testWhenIgnorePayloadNotFoundIsNotSentThenNotFoundKeysInS3AreNotDeletedInSQS () throws Exception {
270
+ ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration ()
271
+ .withLargePayloadSupportEnabled (mockS3 , S3_BUCKET_NAME );
272
+
273
+ AmazonServiceException mockException = mock (AmazonServiceException .class );
274
+ when (mockException .getErrorCode ()).thenReturn ("NoSuchKey" );
275
+
276
+ Message mockMessage = mock (Message .class );
277
+ MessageS3Pointer messageS3Pointer = new MessageS3Pointer ();
278
+ when (mockMessage .getBody ()).thenReturn (new JsonDataConverter ().serializeToJson (messageS3Pointer ));
279
+ when (mockMessage .getReceiptHandle ()).thenReturn ("receipt-handle" );
280
+ Map <String , MessageAttributeValue > messageAttributes = new HashMap <>();
281
+ messageAttributes .put (SQSExtendedClientConstants .RESERVED_ATTRIBUTE_NAME , new MessageAttributeValue ());
282
+ when (mockMessage .getMessageAttributes ()).thenReturn (messageAttributes );
283
+
284
+ ReceiveMessageResult mockReceiveMessageResult = mock (ReceiveMessageResult .class );
285
+ when (mockSqsBackend .receiveMessage (any (ReceiveMessageRequest .class ))).thenReturn (mockReceiveMessageResult );
286
+ when (mockReceiveMessageResult .getMessages ()).thenReturn (Collections .singletonList (mockMessage ));
287
+
288
+ doThrow (mockException ).when (mockS3 ).getObject (any (GetObjectRequest .class ));
289
+
290
+ AmazonSQS sqsExtended = spy (new AmazonSQSExtendedClient (mockSqsBackend , extendedClientConfiguration ));
291
+
292
+ try {
293
+ sqsExtended .receiveMessage (SQS_QUEUE_URL );
294
+ Assert .fail ("exception should have been thrown" );
295
+ } catch (AmazonServiceException e ) {
296
+ verify (mockSqsBackend , never ()).deleteMessage (any (DeleteMessageRequest .class ));
297
+ }
298
+ }
299
+
268
300
private String generateStringWithLength (int messageLength ) {
269
301
char [] charArray = new char [messageLength ];
270
302
Arrays .fill (charArray , 'x' );
0 commit comments