121
121
import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
122
122
import static org .junit .jupiter .api .Assertions .assertNotEquals ;
123
123
import static org .junit .jupiter .api .Assertions .assertNotNull ;
124
- import static org .junit .jupiter .api .Assertions .assertNull ;
125
124
import static org .junit .jupiter .api .Assertions .assertThrows ;
126
125
import static org .junit .jupiter .api .Assertions .assertTrue ;
127
126
import static org .mockito .ArgumentMatchers .any ;
@@ -185,7 +184,7 @@ public void tearDown() throws Exception {
185
184
186
185
@ Test
187
186
public void testNewContextReturnsFinalContextWithoutRequestData () {
188
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
187
+ ShareSessionCache cache = new ShareSessionCache (10 );
189
188
sharePartitionManager = SharePartitionManagerBuilder .builder ()
190
189
.withCache (cache )
191
190
.build ();
@@ -212,7 +211,7 @@ public void testNewContextReturnsFinalContextWithoutRequestData() {
212
211
213
212
@ Test
214
213
public void testNewContextReturnsFinalContextWithRequestData () {
215
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
214
+ ShareSessionCache cache = new ShareSessionCache (10 );
216
215
sharePartitionManager = SharePartitionManagerBuilder .builder ()
217
216
.withCache (cache )
218
217
.build ();
@@ -244,7 +243,7 @@ public void testNewContextReturnsFinalContextWithRequestData() {
244
243
245
244
@ Test
246
245
public void testNewContextReturnsFinalContextWhenTopicPartitionsArePresentInRequestData () {
247
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
246
+ ShareSessionCache cache = new ShareSessionCache (10 );
248
247
sharePartitionManager = SharePartitionManagerBuilder .builder ()
249
248
.withCache (cache )
250
249
.build ();
@@ -275,7 +274,7 @@ public void testNewContextReturnsFinalContextWhenTopicPartitionsArePresentInRequ
275
274
276
275
@ Test
277
276
public void testNewContext () {
278
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
277
+ ShareSessionCache cache = new ShareSessionCache (10 );
279
278
sharePartitionManager = SharePartitionManagerBuilder .builder ()
280
279
.withCache (cache )
281
280
.build ();
@@ -372,100 +371,6 @@ public void testNewContext() {
372
371
assertEquals (0 , cache .size ());
373
372
}
374
373
375
- @ Test
376
- public void testShareSessionExpiration () {
377
- ShareSessionCache cache = new ShareSessionCache (2 , 1000 );
378
- sharePartitionManager = SharePartitionManagerBuilder .builder ()
379
- .withCache (cache )
380
- .withTime (time )
381
- .build ();
382
-
383
- Map <Uuid , String > topicNames = new HashMap <>();
384
- Uuid fooId = Uuid .randomUuid ();
385
- topicNames .put (fooId , "foo" );
386
- TopicIdPartition foo0 = new TopicIdPartition (fooId , new TopicPartition ("foo" , 0 ));
387
- TopicIdPartition foo1 = new TopicIdPartition (fooId , new TopicPartition ("foo" , 1 ));
388
-
389
- // Create a new share session, session 1
390
- List <TopicIdPartition > session1req = List .of (foo0 , foo1 );
391
-
392
- String groupId = "grp" ;
393
- ShareRequestMetadata reqMetadata1 = new ShareRequestMetadata (Uuid .randomUuid (), ShareRequestMetadata .INITIAL_EPOCH );
394
-
395
- ShareFetchContext session1context = sharePartitionManager .newContext (groupId , session1req , EMPTY_PART_LIST , reqMetadata1 , false );
396
- assertInstanceOf (ShareSessionContext .class , session1context );
397
-
398
- LinkedHashMap <TopicIdPartition , ShareFetchResponseData .PartitionData > respData1 = new LinkedHashMap <>();
399
- respData1 .put (foo0 , new ShareFetchResponseData .PartitionData ().setPartitionIndex (foo0 .partition ()));
400
- respData1 .put (foo1 , new ShareFetchResponseData .PartitionData ().setPartitionIndex (foo1 .partition ()));
401
-
402
- ShareFetchResponse session1resp = session1context .updateAndGenerateResponseData (groupId , reqMetadata1 .memberId (), respData1 );
403
- assertEquals (Errors .NONE , session1resp .error ());
404
- assertEquals (2 , session1resp .responseData (topicNames ).size ());
405
-
406
- ShareSessionKey session1Key = new ShareSessionKey (groupId , reqMetadata1 .memberId ());
407
- // check share session entered into cache
408
- assertNotNull (cache .get (session1Key ));
409
-
410
- time .sleep (500 );
411
-
412
- // Create a second new share session
413
- List <TopicIdPartition > session2req = List .of (foo0 , foo1 );
414
-
415
- ShareRequestMetadata reqMetadata2 = new ShareRequestMetadata (Uuid .randomUuid (), ShareRequestMetadata .INITIAL_EPOCH );
416
-
417
- ShareFetchContext session2context = sharePartitionManager .newContext (groupId , session2req , EMPTY_PART_LIST , reqMetadata2 , false );
418
- assertInstanceOf (ShareSessionContext .class , session2context );
419
-
420
- LinkedHashMap <TopicIdPartition , ShareFetchResponseData .PartitionData > respData2 = new LinkedHashMap <>();
421
- respData2 .put (foo0 , new ShareFetchResponseData .PartitionData ().setPartitionIndex (foo0 .partition ()));
422
- respData2 .put (foo1 , new ShareFetchResponseData .PartitionData ().setPartitionIndex (foo1 .partition ()));
423
-
424
- ShareFetchResponse session2resp = session2context .updateAndGenerateResponseData (groupId , reqMetadata2 .memberId (), respData2 );
425
- assertEquals (Errors .NONE , session2resp .error ());
426
- assertEquals (2 , session2resp .responseData (topicNames ).size ());
427
-
428
- ShareSessionKey session2Key = new ShareSessionKey (groupId , reqMetadata2 .memberId ());
429
-
430
- // both newly created entries are present in cache
431
- assertNotNull (cache .get (session1Key ));
432
- assertNotNull (cache .get (session2Key ));
433
-
434
- time .sleep (500 );
435
-
436
- // Create a subsequent share fetch context for session 1
437
- ShareFetchContext session1context2 = sharePartitionManager .newContext (groupId , List .of (), EMPTY_PART_LIST ,
438
- new ShareRequestMetadata (reqMetadata1 .memberId (), 1 ), true );
439
- assertInstanceOf (ShareSessionContext .class , session1context2 );
440
-
441
- // total sleep time will now be large enough that share session 1 will be evicted if not correctly touched
442
- time .sleep (501 );
443
-
444
- // create one final share session to test that the least recently used entry is evicted
445
- // the second share session should be evicted because the first share session was incrementally fetched
446
- // more recently than the second session was created
447
- List <TopicIdPartition > session3req = List .of (foo0 , foo1 );
448
-
449
- ShareRequestMetadata reqMetadata3 = new ShareRequestMetadata (Uuid .randomUuid (), ShareRequestMetadata .INITIAL_EPOCH );
450
-
451
- ShareFetchContext session3context = sharePartitionManager .newContext (groupId , session3req , EMPTY_PART_LIST , reqMetadata3 , false );
452
-
453
- LinkedHashMap <TopicIdPartition , ShareFetchResponseData .PartitionData > respData3 = new LinkedHashMap <>();
454
- respData3 .put (foo0 , new ShareFetchResponseData .PartitionData ().setPartitionIndex (foo0 .partition ()));
455
- respData3 .put (foo1 , new ShareFetchResponseData .PartitionData ().setPartitionIndex (foo1 .partition ()));
456
-
457
- ShareFetchResponse session3resp = session3context .updateAndGenerateResponseData (groupId , reqMetadata3 .memberId (), respData3 );
458
- assertEquals (Errors .NONE , session3resp .error ());
459
- assertEquals (2 , session3resp .responseData (topicNames ).size ());
460
-
461
- ShareSessionKey session3Key = new ShareSessionKey (groupId , reqMetadata3 .memberId ());
462
-
463
- assertNotNull (cache .get (session1Key ));
464
- assertNull (cache .get (session2Key ), "share session 2 should have been evicted by latest share session, " +
465
- "as share session 1 was used more recently" );
466
- assertNotNull (cache .get (session3Key ));
467
- }
468
-
469
374
@ Test
470
375
public void testSubsequentShareSession () {
471
376
sharePartitionManager = SharePartitionManagerBuilder .builder ().build ();
@@ -530,7 +435,7 @@ public void testSubsequentShareSession() {
530
435
531
436
@ Test
532
437
public void testZeroSizeShareSession () {
533
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
438
+ ShareSessionCache cache = new ShareSessionCache (10 );
534
439
sharePartitionManager = SharePartitionManagerBuilder .builder ()
535
440
.withCache (cache )
536
441
.build ();
@@ -576,7 +481,7 @@ public void testZeroSizeShareSession() {
576
481
@ Test
577
482
public void testToForgetPartitions () {
578
483
String groupId = "grp" ;
579
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
484
+ ShareSessionCache cache = new ShareSessionCache (10 );
580
485
sharePartitionManager = SharePartitionManagerBuilder .builder ()
581
486
.withCache (cache )
582
487
.build ();
@@ -614,7 +519,7 @@ public void testToForgetPartitions() {
614
519
@ Test
615
520
public void testShareSessionUpdateTopicIdsBrokerSide () {
616
521
String groupId = "grp" ;
617
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
522
+ ShareSessionCache cache = new ShareSessionCache (10 );
618
523
sharePartitionManager = SharePartitionManagerBuilder .builder ()
619
524
.withCache (cache )
620
525
.build ();
@@ -665,7 +570,7 @@ public void testShareSessionUpdateTopicIdsBrokerSide() {
665
570
666
571
@ Test
667
572
public void testGetErroneousAndValidTopicIdPartitions () {
668
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
573
+ ShareSessionCache cache = new ShareSessionCache (10 );
669
574
sharePartitionManager = SharePartitionManagerBuilder .builder ()
670
575
.withCache (cache )
671
576
.build ();
@@ -758,7 +663,7 @@ public void testGetErroneousAndValidTopicIdPartitions() {
758
663
759
664
@ Test
760
665
public void testShareFetchContextResponseSize () {
761
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
666
+ ShareSessionCache cache = new ShareSessionCache (10 );
762
667
sharePartitionManager = SharePartitionManagerBuilder .builder ()
763
668
.withCache (cache )
764
669
.build ();
@@ -859,7 +764,7 @@ public void testShareFetchContextResponseSize() {
859
764
860
765
@ Test
861
766
public void testCachedTopicPartitionsWithNoTopicPartitions () {
862
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
767
+ ShareSessionCache cache = new ShareSessionCache (10 );
863
768
sharePartitionManager = SharePartitionManagerBuilder .builder ()
864
769
.withCache (cache )
865
770
.build ();
@@ -870,7 +775,7 @@ public void testCachedTopicPartitionsWithNoTopicPartitions() {
870
775
871
776
@ Test
872
777
public void testCachedTopicPartitionsForValidShareSessions () {
873
- ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
778
+ ShareSessionCache cache = new ShareSessionCache (10 );
874
779
sharePartitionManager = SharePartitionManagerBuilder .builder ()
875
780
.withCache (cache )
876
781
.build ();
@@ -3108,7 +3013,7 @@ static class SharePartitionManagerBuilder {
3108
3013
private final Persister persister = new NoOpStatePersister ();
3109
3014
private ReplicaManager replicaManager = mock (ReplicaManager .class );
3110
3015
private Time time = new MockTime ();
3111
- private ShareSessionCache cache = new ShareSessionCache (10 , 1000 );
3016
+ private ShareSessionCache cache = new ShareSessionCache (10 );
3112
3017
private Map <SharePartitionKey , SharePartition > partitionCacheMap = new HashMap <>();
3113
3018
private Timer timer = new MockTimer ();
3114
3019
private ShareGroupMetrics shareGroupMetrics = new ShareGroupMetrics (time );
0 commit comments