18
18
19
19
import org .apache .kafka .clients .ClientResponse ;
20
20
import org .apache .kafka .clients .consumer .internals .events .BackgroundEventHandler ;
21
+ import org .apache .kafka .clients .consumer .internals .events .ErrorEvent ;
21
22
import org .apache .kafka .common .Node ;
23
+ import org .apache .kafka .common .errors .GroupAuthorizationException ;
22
24
import org .apache .kafka .common .errors .TimeoutException ;
23
25
import org .apache .kafka .common .protocol .ApiKeys ;
24
26
import org .apache .kafka .common .protocol .Errors ;
33
35
import org .apache .logging .log4j .Level ;
34
36
import org .junit .jupiter .api .BeforeEach ;
35
37
import org .junit .jupiter .api .Test ;
36
- import org .junit .jupiter .params .ParameterizedTest ;
37
- import org .junit .jupiter .params .provider .EnumSource ;
38
38
39
39
import java .util .Collections ;
40
40
import java .util .List ;
49
49
import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
50
50
import static org .junit .jupiter .api .Assertions .assertThrows ;
51
51
import static org .junit .jupiter .api .Assertions .assertTrue ;
52
+ import static org .mockito .ArgumentMatchers .argThat ;
52
53
import static org .mockito .Mockito .mock ;
54
+ import static org .mockito .Mockito .verify ;
53
55
import static org .mockito .Mockito .verifyNoInteractions ;
54
56
55
57
public class CoordinatorRequestManagerTest {
@@ -189,10 +191,23 @@ public void testBackoffAfterRetriableFailure() {
189
191
}
190
192
191
193
@ Test
192
- public void testBackoffAfterFatalError () {
194
+ public void testPropagateAndBackoffAfterFatalError () {
193
195
CoordinatorRequestManager coordinatorManager = setupCoordinatorManager (GROUP_ID );
194
196
expectFindCoordinatorRequest (coordinatorManager , Errors .GROUP_AUTHORIZATION_FAILED );
195
197
198
+ verify (backgroundEventHandler ).add (argThat (backgroundEvent -> {
199
+ if (!(backgroundEvent instanceof ErrorEvent ))
200
+ return false ;
201
+
202
+ RuntimeException exception = ((ErrorEvent ) backgroundEvent ).error ();
203
+
204
+ if (!(exception instanceof GroupAuthorizationException ))
205
+ return false ;
206
+
207
+ GroupAuthorizationException groupAuthException = (GroupAuthorizationException ) exception ;
208
+ return groupAuthException .groupId ().equals (GROUP_ID );
209
+ }));
210
+
196
211
time .sleep (RETRY_BACKOFF_MS - 1 );
197
212
assertEquals (Collections .emptyList (), coordinatorManager .poll (time .milliseconds ()).unsentRequests );
198
213
@@ -238,22 +253,6 @@ public void testNetworkTimeout() {
238
253
res2 = coordinatorManager .poll (time .milliseconds ());
239
254
assertEquals (1 , res2 .unsentRequests .size ());
240
255
}
241
-
242
- @ ParameterizedTest
243
- @ EnumSource (value = Errors .class , names = {"NONE" , "COORDINATOR_NOT_AVAILABLE" })
244
- public void testClearFatalErrorWhenReceivingSuccessfulResponse (Errors error ) {
245
- CoordinatorRequestManager coordinatorManager = setupCoordinatorManager (GROUP_ID );
246
- expectFindCoordinatorRequest (coordinatorManager , Errors .GROUP_AUTHORIZATION_FAILED );
247
- assertTrue (coordinatorManager .fatalError ().isPresent ());
248
-
249
- time .sleep (RETRY_BACKOFF_MS );
250
- // there are no successful responses, so the fatal error should persist
251
- assertTrue (coordinatorManager .fatalError ().isPresent ());
252
-
253
- // receiving a successful response should clear the fatal error
254
- expectFindCoordinatorRequest (coordinatorManager , error );
255
- assertTrue (coordinatorManager .fatalError ().isEmpty ());
256
- }
257
256
258
257
private void expectFindCoordinatorRequest (
259
258
CoordinatorRequestManager coordinatorManager ,
@@ -274,6 +273,7 @@ private CoordinatorRequestManager setupCoordinatorManager(String groupId) {
274
273
new LogContext (),
275
274
RETRY_BACKOFF_MS ,
276
275
RETRY_BACKOFF_MS ,
276
+ this .backgroundEventHandler ,
277
277
groupId
278
278
);
279
279
}
0 commit comments