@@ -47,6 +47,7 @@ public class AmazonSQSExtendedClientTest {
47
47
private AmazonSQS extendedSqsWithCustomKMS ;
48
48
private AmazonSQS extendedSqsWithDefaultKMS ;
49
49
private AmazonSQS extendedSqsWithGenericReservedAttributeName ;
50
+ private AmazonSQS extendedSqsWithDeprecatedMethods ;
50
51
private AmazonSQS mockSqsBackend ;
51
52
private AmazonS3 mockS3 ;
52
53
private static final String S3_BUCKET_NAME = "test-bucket-name" ;
@@ -80,10 +81,75 @@ public void setupClients() {
80
81
ExtendedClientConfiguration extendedClientConfigurationWithGenericReservedAttributeName = new ExtendedClientConfiguration ()
81
82
.withPayloadSupportEnabled (mockS3 , S3_BUCKET_NAME ).withLegacyReservedAttributeNameDisabled ();
82
83
84
+ ExtendedClientConfiguration extendedClientConfigurationDeprecated = new ExtendedClientConfiguration ()
85
+ .withLargePayloadSupportEnabled (mockS3 , S3_BUCKET_NAME );
86
+
83
87
extendedSqsWithDefaultConfig = spy (new AmazonSQSExtendedClient (mockSqsBackend , extendedClientConfiguration ));
84
88
extendedSqsWithCustomKMS = spy (new AmazonSQSExtendedClient (mockSqsBackend , extendedClientConfigurationWithCustomKMS ));
85
89
extendedSqsWithDefaultKMS = spy (new AmazonSQSExtendedClient (mockSqsBackend , extendedClientConfigurationWithDefaultKMS ));
86
90
extendedSqsWithGenericReservedAttributeName = spy (new AmazonSQSExtendedClient (mockSqsBackend , extendedClientConfigurationWithGenericReservedAttributeName ));
91
+ extendedSqsWithDeprecatedMethods = spy (new AmazonSQSExtendedClient (mockSqsBackend , extendedClientConfigurationDeprecated ));
92
+ }
93
+
94
+ @ Test
95
+ public void testWhenSendMessageWithLargePayloadSupportDisabledThenS3IsNotUsedAndSqsBackendIsResponsibleToFailItWithDeprecatedMethod () {
96
+ int messageLength = MORE_THAN_SQS_SIZE_LIMIT ;
97
+ String messageBody = generateStringWithLength (messageLength );
98
+ ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration ()
99
+ .withLargePayloadSupportDisabled ();
100
+ AmazonSQS sqsExtended = spy (new AmazonSQSExtendedClient (mockSqsBackend , extendedClientConfiguration ));
101
+
102
+ SendMessageRequest messageRequest = new SendMessageRequest (SQS_QUEUE_URL , messageBody );
103
+ sqsExtended .sendMessage (messageRequest );
104
+
105
+ verify (mockS3 , never ()).putObject (isA (PutObjectRequest .class ));
106
+ verify (mockSqsBackend ).sendMessage (eq (messageRequest ));
107
+ }
108
+
109
+ @ Test
110
+ public void testWhenSendMessageWithAlwaysThroughS3AndMessageIsSmallThenItIsStillStoredInS3WithDeprecatedMethod () {
111
+ int messageLength = LESS_THAN_SQS_SIZE_LIMIT ;
112
+ String messageBody = generateStringWithLength (messageLength );
113
+ ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration ()
114
+ .withLargePayloadSupportEnabled (mockS3 , S3_BUCKET_NAME ).withAlwaysThroughS3 (true );
115
+ AmazonSQS sqsExtended = spy (new AmazonSQSExtendedClient (mock (AmazonSQSClient .class ), extendedClientConfiguration ));
116
+
117
+ SendMessageRequest messageRequest = new SendMessageRequest (SQS_QUEUE_URL , messageBody );
118
+ sqsExtended .sendMessage (messageRequest );
119
+
120
+ verify (mockS3 , times (1 )).putObject (isA (PutObjectRequest .class ));
121
+ }
122
+
123
+ @ Test
124
+ public void testWhenSendMessageWithSetMessageSizeThresholdThenThresholdIsHonoredWithDeprecatedMethod () {
125
+ int messageLength = ARBITRARY_SMALLER_THRESHOLD * 2 ;
126
+ String messageBody = generateStringWithLength (messageLength );
127
+ ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration ()
128
+ .withLargePayloadSupportEnabled (mockS3 , S3_BUCKET_NAME ).withMessageSizeThreshold (ARBITRARY_SMALLER_THRESHOLD );
129
+
130
+ AmazonSQS sqsExtended = spy (new AmazonSQSExtendedClient (mock (AmazonSQSClient .class ), extendedClientConfiguration ));
131
+
132
+ SendMessageRequest messageRequest = new SendMessageRequest (SQS_QUEUE_URL , messageBody );
133
+ sqsExtended .sendMessage (messageRequest );
134
+ verify (mockS3 , times (1 )).putObject (isA (PutObjectRequest .class ));
135
+ }
136
+
137
+ @ Test
138
+ public void testReceiveMessageMultipleTimesDoesNotAdditionallyAlterReceiveMessageRequestWithDeprecatedMethod () {
139
+ ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration ()
140
+ .withLargePayloadSupportEnabled (mockS3 , S3_BUCKET_NAME );
141
+ AmazonSQS sqsExtended = spy (new AmazonSQSExtendedClient (mockSqsBackend , extendedClientConfiguration ));
142
+ when (mockSqsBackend .receiveMessage (isA (ReceiveMessageRequest .class ))).thenReturn (new ReceiveMessageResult ());
143
+
144
+ ReceiveMessageRequest messageRequest = new ReceiveMessageRequest ();
145
+ ReceiveMessageRequest expectedRequest = new ReceiveMessageRequest ()
146
+ .withMessageAttributeNames (AmazonSQSExtendedClient .LEGACY_RESERVED_ATTRIBUTE_NAME , SQSExtendedClientConstants .RESERVED_ATTRIBUTE_NAME );
147
+
148
+ sqsExtended .receiveMessage (messageRequest );
149
+ Assert .assertEquals (expectedRequest , messageRequest );
150
+
151
+ sqsExtended .receiveMessage (messageRequest );
152
+ Assert .assertEquals (expectedRequest , messageRequest );
87
153
}
88
154
89
155
@ Test
0 commit comments