Skip to content

Commit 24e8dae

Browse files
Merge pull request #140 from seanliu-oss/make-WAIT_TIME_SECONDS-modifiable
Make wait time seconds modifiable
2 parents c6f742e + c9fe063 commit 24e8dae

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/main/java/com/amazon/sqs/javamessaging/SQSMessageConsumerPrefetch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
* This runs until the message consumer is closed and in-progress SQS
5555
* <code>receiveMessage</code> call returns.
5656
* <P>
57-
* Uses SQS <code>receiveMessage</code> with long-poll wait time of 20 seconds.
57+
* Uses SQS <code>receiveMessage</code> with long-poll wait time of WAIT_TIME_SECONDS (default to 20) seconds.
5858
* <P>
5959
* Add re-tries on top of <code>SqsClient</code> re-tries on SQS calls.
6060
*/
6161
public class SQSMessageConsumerPrefetch implements Runnable, PrefetchManager {
6262

6363
private static final Logger LOG = LoggerFactory.getLogger(SQSMessageConsumerPrefetch.class);
6464

65-
protected static final int WAIT_TIME_SECONDS = 20;
65+
protected static int WAIT_TIME_SECONDS = 20;
6666

6767
protected static final String ALL = "All";
6868

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.amazon.sqs.javamessaging;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.lang.reflect.Field;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
class ModifyWaitTimeSecondsTest {
11+
@DisplayName("Should be able to modify SQSMessageConsumerPrefetch.WAIT_TIME_SECONDS via Reflection")
12+
@Test
13+
void WaitTimeSecondsShouldBeModifiableViaReflection() throws NoSuchFieldException, IllegalAccessException {
14+
Field wait_time_seconds = SQSMessageConsumerPrefetch.class.getDeclaredField("WAIT_TIME_SECONDS");
15+
wait_time_seconds.setAccessible(true);
16+
wait_time_seconds.setInt(null,5);
17+
assertEquals(5,SQSMessageConsumerPrefetch.WAIT_TIME_SECONDS);
18+
}
19+
}

0 commit comments

Comments
 (0)