44import com .exceptionless .exceptionlessclient .configuration .Configuration ;
55import com .exceptionless .exceptionlessclient .exceptions .SubmissionClientException ;
66import com .exceptionless .exceptionlessclient .models .Event ;
7- import com .exceptionless .exceptionlessclient .submission .SubmissionResponse ;
87import com .exceptionless .exceptionlessclient .storage .InMemoryStorage ;
98import com .exceptionless .exceptionlessclient .storage .InMemoryStorageProvider ;
109import com .exceptionless .exceptionlessclient .submission .DefaultSubmissionClient ;
10+ import com .exceptionless .exceptionlessclient .submission .SubmissionResponse ;
1111import org .junit .jupiter .api .BeforeEach ;
1212import org .junit .jupiter .api .Test ;
1313import org .junit .jupiter .api .extension .ExtendWith ;
@@ -111,7 +111,9 @@ public void itShouldNotPostEmptyEvents() {
111111 public void itShouldSuspendProcessingOnClientException () {
112112 storage .save (event );
113113
114- doThrow (new SubmissionClientException ("test" )).when (submissionClient ).postEvents (List .of (event ));
114+ doThrow (new SubmissionClientException ("test" ))
115+ .when (submissionClient )
116+ .postEvents (List .of (event ));
115117
116118 queue .onEventsPosted (testHandler );
117119 queue .process ();
@@ -137,6 +139,42 @@ public void itShouldSuspendProcessingIfServiceIsUnavailable() {
137139 verify (testHandler , times (1 )).accept (List .of (event ), response );
138140 }
139141
142+ @ Test
143+ public void itShouldSuspendProcessingIfServiceIsRateLimitedByHeader () {
144+ storage .save (event );
145+
146+ SubmissionResponse response =
147+ SubmissionResponse .builder ()
148+ .body ("test-message" )
149+ .code (999 )
150+ .rateLimitingHeaderFound (true )
151+ .build ();
152+ doReturn (response ).when (submissionClient ).postEvents (List .of (event ));
153+
154+ queue .onEventsPosted (testHandler );
155+ queue .process ();
156+
157+ assertThat (queue .isProcessingCurrentlySuspended ()).isTrue ();
158+ assertThat (storage .peek ().getValue ()).isEqualTo (event );
159+ verify (testHandler , times (1 )).accept (List .of (event ), response );
160+ }
161+
162+ @ Test
163+ public void itShouldSuspendProcessingIfServiceIsRateLimitedByCode () {
164+ storage .save (event );
165+
166+ SubmissionResponse response =
167+ SubmissionResponse .builder ().body ("test-message" ).code (429 ).build ();
168+ doReturn (response ).when (submissionClient ).postEvents (List .of (event ));
169+
170+ queue .onEventsPosted (testHandler );
171+ queue .process ();
172+
173+ assertThat (queue .isProcessingCurrentlySuspended ()).isTrue ();
174+ assertThat (storage .peek ().getValue ()).isEqualTo (event );
175+ verify (testHandler , times (1 )).accept (List .of (event ), response );
176+ }
177+
140178 @ Test
141179 public void itShouldSuspendAndDiscardProcessingAndClearQueueIfNoPayment () {
142180 storage .save (event );
@@ -250,11 +288,9 @@ public void itShouldReduceSubmissionBatchSizeIfRequestEntitiesAreTooLarge() {
250288 queue .process ();
251289
252290 // One invocation with full batch
253- verify (submissionClient , times (1 ))
254- .postEvents (argThat (argument -> argument .size () == 3 ));
291+ verify (submissionClient , times (1 )).postEvents (argThat (argument -> argument .size () == 3 ));
255292 // One invocation with reduced batch
256- verify (submissionClient , times (1 ))
257- .postEvents (argThat (argument -> argument .size () == 2 ));
293+ verify (submissionClient , times (1 )).postEvents (argThat (argument -> argument .size () == 2 ));
258294 }
259295
260296 @ Test
@@ -303,11 +339,9 @@ public void itShouldResetSubmissionBatchSizeOnNextSuccessfulResponse() {
303339
304340 // Two invocations with full batch; First with the default size and next after a successful
305341 // response
306- verify (submissionClient , times (2 ))
307- .postEvents (argThat (argument -> argument .size () == 3 ));
342+ verify (submissionClient , times (2 )).postEvents (argThat (argument -> argument .size () == 3 ));
308343 // One invocation with reduced batch
309- verify (submissionClient , times (1 ))
310- .postEvents (argThat (argument -> argument .size () == 2 ));
344+ verify (submissionClient , times (1 )).postEvents (argThat (argument -> argument .size () == 2 ));
311345 }
312346
313347 @ Test
0 commit comments