24
24
import org .apache .kafka .clients .consumer .internals .events .CompletableEventReaper ;
25
25
import org .apache .kafka .clients .consumer .internals .events .ErrorEvent ;
26
26
import org .apache .kafka .clients .consumer .internals .events .PollEvent ;
27
- import org .apache .kafka .clients .consumer .internals .events .ShareLeaveOnCloseEvent ;
28
- import org .apache .kafka .clients .consumer .internals .events .ShareSubscriptionChangeApplicationEvent ;
29
- import org .apache .kafka .clients .consumer .internals .events .ShareUnsubscribeApplicationEvent ;
27
+ import org .apache .kafka .clients .consumer .internals .events .ShareAcknowledgeOnCloseEvent ;
28
+ import org .apache .kafka .clients .consumer .internals .events .ShareSubscriptionChangeEvent ;
29
+ import org .apache .kafka .clients .consumer .internals .events .ShareUnsubscribeEvent ;
30
30
import org .apache .kafka .common .KafkaException ;
31
31
import org .apache .kafka .common .TopicIdPartition ;
32
32
import org .apache .kafka .common .TopicPartition ;
@@ -153,7 +153,8 @@ private ShareConsumerImpl<String, String> newConsumer(
153
153
@ Test
154
154
public void testSuccessfulStartupShutdown () {
155
155
consumer = newConsumer ();
156
- completeShareLeaveOnCloseApplicationEventSuccessfully ();
156
+ completeShareAcknowledgeOnCloseApplicationEventSuccessfully ();
157
+ completeShareUnsubscribeApplicationEventSuccessfully ();
157
158
assertDoesNotThrow (() -> consumer .close ());
158
159
}
159
160
@@ -179,7 +180,8 @@ public void testWakeupBeforeCallingPoll() {
179
180
@ Test
180
181
public void testFailOnClosedConsumer () {
181
182
consumer = newConsumer ();
182
- completeShareLeaveOnCloseApplicationEventSuccessfully ();
183
+ completeShareAcknowledgeOnCloseApplicationEventSuccessfully ();
184
+ completeShareUnsubscribeApplicationEventSuccessfully ();
183
185
consumer .close ();
184
186
final IllegalStateException res = assertThrows (IllegalStateException .class , consumer ::subscription );
185
187
assertEquals ("This consumer has already been closed." , res .getMessage ());
@@ -188,10 +190,11 @@ public void testFailOnClosedConsumer() {
188
190
@ Test
189
191
public void testVerifyApplicationEventOnShutdown () {
190
192
consumer = newConsumer ();
191
- completeShareLeaveOnCloseApplicationEventSuccessfully ();
192
- doReturn ( null ). when ( applicationEventHandler ). addAndGet ( any () );
193
+ completeShareAcknowledgeOnCloseApplicationEventSuccessfully ();
194
+ completeShareUnsubscribeApplicationEventSuccessfully ( );
193
195
consumer .close ();
194
- verify (applicationEventHandler ).addAndGet (any (ShareLeaveOnCloseEvent .class ));
196
+ verify (applicationEventHandler ).addAndGet (any (ShareAcknowledgeOnCloseEvent .class ));
197
+ verify (applicationEventHandler ).add (any (ShareUnsubscribeEvent .class ));
195
198
}
196
199
197
200
@ Test
@@ -215,7 +218,7 @@ public void testSubscribeGeneratesEvent() {
215
218
String topic = "topic1" ;
216
219
consumer .subscribe (singletonList (topic ));
217
220
assertEquals (singleton (topic ), consumer .subscription ());
218
- verify (applicationEventHandler ).add (ArgumentMatchers .isA (ShareSubscriptionChangeApplicationEvent .class ));
221
+ verify (applicationEventHandler ).add (ArgumentMatchers .isA (ShareSubscriptionChangeEvent .class ));
219
222
}
220
223
221
224
@ Test
@@ -226,7 +229,7 @@ public void testUnsubscribeGeneratesUnsubscribeEvent() {
226
229
consumer .unsubscribe ();
227
230
228
231
assertTrue (consumer .subscription ().isEmpty ());
229
- verify (applicationEventHandler ).add (ArgumentMatchers .isA (ShareUnsubscribeApplicationEvent .class ));
232
+ verify (applicationEventHandler ).add (ArgumentMatchers .isA (ShareUnsubscribeEvent .class ));
230
233
}
231
234
232
235
@ Test
@@ -236,7 +239,7 @@ public void testSubscribeToEmptyListActsAsUnsubscribe() {
236
239
237
240
consumer .subscribe (Collections .emptyList ());
238
241
assertTrue (consumer .subscription ().isEmpty ());
239
- verify (applicationEventHandler ).add (ArgumentMatchers .isA (ShareUnsubscribeApplicationEvent .class ));
242
+ verify (applicationEventHandler ).add (ArgumentMatchers .isA (ShareUnsubscribeEvent .class ));
240
243
}
241
244
242
245
@ Test
@@ -348,11 +351,12 @@ public void testEnsurePollEventSentOnConsumerPoll() {
348
351
consumer .subscribe (singletonList ("topic1" ));
349
352
consumer .poll (Duration .ofMillis (100 ));
350
353
verify (applicationEventHandler ).add (any (PollEvent .class ));
351
- verify (applicationEventHandler ).add (any (ShareSubscriptionChangeApplicationEvent .class ));
354
+ verify (applicationEventHandler ).add (any (ShareSubscriptionChangeEvent .class ));
352
355
353
- completeShareLeaveOnCloseApplicationEventSuccessfully ();
356
+ completeShareAcknowledgeOnCloseApplicationEventSuccessfully ();
357
+ completeShareUnsubscribeApplicationEventSuccessfully ();
354
358
consumer .close ();
355
- verify (applicationEventHandler ).addAndGet (any (ShareLeaveOnCloseEvent .class ));
359
+ verify (applicationEventHandler ).addAndGet (any (ShareAcknowledgeOnCloseEvent .class ));
356
360
}
357
361
358
362
private Properties requiredConsumerPropertiesAndGroupId (final String groupId ) {
@@ -448,17 +452,17 @@ public void testProcessBackgroundEventsTimesOut() throws Exception {
448
452
449
453
private void completeShareUnsubscribeApplicationEventSuccessfully () {
450
454
doAnswer (invocation -> {
451
- ShareUnsubscribeApplicationEvent event = invocation .getArgument (0 );
455
+ ShareUnsubscribeEvent event = invocation .getArgument (0 );
452
456
event .future ().complete (null );
453
457
return null ;
454
- }).when (applicationEventHandler ).add (ArgumentMatchers .isA (ShareUnsubscribeApplicationEvent .class ));
458
+ }).when (applicationEventHandler ).add (ArgumentMatchers .isA (ShareUnsubscribeEvent .class ));
455
459
}
456
460
457
- private void completeShareLeaveOnCloseApplicationEventSuccessfully () {
461
+ private void completeShareAcknowledgeOnCloseApplicationEventSuccessfully () {
458
462
doAnswer (invocation -> {
459
- ShareLeaveOnCloseEvent event = invocation .getArgument (0 );
463
+ ShareAcknowledgeOnCloseEvent event = invocation .getArgument (0 );
460
464
event .future ().complete (null );
461
465
return null ;
462
- }).when (applicationEventHandler ).add (ArgumentMatchers .isA (ShareLeaveOnCloseEvent .class ));
466
+ }).when (applicationEventHandler ).addAndGet (ArgumentMatchers .isA (ShareAcknowledgeOnCloseEvent .class ));
463
467
}
464
468
}
0 commit comments