@@ -475,6 +475,177 @@ func TestStreamReaderImpl_OnPartitionCloseHandle(t *testing.T) {
475475 })
476476}
477477
478+ func TestStreamReaderImpl_TestEndSessionForSplitMergePartitions (t * testing.T ) {
479+ t .Run ("Split" , func (t * testing.T ) {
480+ xtest .TestManyTimes (t , func (t testing.TB ) {
481+
482+ e := newTopicReaderTestEnv (t )
483+
484+ // doesn't check sends
485+ e .stream .EXPECT ().Send (gomock .Any ()).Return (nil ).MinTimes (0 )
486+
487+ e .Start ()
488+
489+ activePartitionID := e .partitionSession .PartitionID
490+
491+ e .SendFromServer (& rawtopicreader.ReadResponse {
492+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
493+ PartitionData : []rawtopicreader.PartitionData {
494+ {
495+ PartitionSessionID : e .partitionSessionID ,
496+ Batches : []rawtopicreader.Batch {{
497+ Codec : rawtopiccommon .CodecRaw ,
498+ MessageData : []rawtopicreader.MessageData {{Offset : 1 , Data : []byte ("OK" )}},
499+ }},
500+ },
501+ },
502+ })
503+
504+ e .SendFromServer (& rawtopicreader.EndPartitionSession {
505+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
506+ PartitionSessionID : e .partitionSessionID ,
507+ ChildPartitionIDs : []int64 {activePartitionID + 1 , activePartitionID + 2 },
508+ })
509+
510+ e .SendFromServer (& rawtopicreader.StartPartitionSessionRequest {
511+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
512+ PartitionSession : rawtopicreader.PartitionSession {
513+ PartitionSessionID : e .partitionSessionID + 1 ,
514+ Path : e .partitionSession .Topic ,
515+ PartitionID : activePartitionID + 1 ,
516+ },
517+ })
518+
519+ e .SendFromServer (& rawtopicreader.StartPartitionSessionRequest {
520+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
521+ PartitionSession : rawtopicreader.PartitionSession {
522+ PartitionSessionID : e .partitionSessionID + 2 ,
523+ Path : e .partitionSession .Topic ,
524+ PartitionID : activePartitionID + 2 ,
525+ },
526+ })
527+
528+ e .SendFromServer (& rawtopicreader.ReadResponse {
529+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
530+ PartitionData : []rawtopicreader.PartitionData {
531+ {
532+ PartitionSessionID : e .partitionSessionID + 1 ,
533+ Batches : []rawtopicreader.Batch {{
534+ Codec : rawtopiccommon .CodecRaw ,
535+ MessageData : []rawtopicreader.MessageData {{Offset : 1 , Data : []byte ("BAD-1" )}},
536+ }},
537+ },
538+ },
539+ })
540+
541+ allMessagesSent := make (empty.Chan )
542+ e .SendFromServerAndSetNextCallback (& rawtopicreader.ReadResponse {
543+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
544+ PartitionData : []rawtopicreader.PartitionData {
545+ {
546+ PartitionSessionID : e .partitionSessionID + 2 ,
547+ Batches : []rawtopicreader.Batch {{
548+ Codec : rawtopiccommon .CodecRaw ,
549+ MessageData : []rawtopicreader.MessageData {{Offset : 1 , Data : []byte ("BAD-2" )}},
550+ }},
551+ },
552+ },
553+ }, func () {
554+ close (allMessagesSent )
555+ })
556+
557+ <- allMessagesSent
558+ batch , err := e .reader .ReadMessageBatch (e .ctx , newReadMessageBatchOptions ())
559+ require .NoError (t , err )
560+ require .Same (t , e .partitionSession , topicreadercommon .BatchGetPartitionSession (batch ))
561+ })
562+ })
563+ t .Run ("Merge" , func (t * testing.T ) {
564+ xtest .TestManyTimes (t , func (t testing.TB ) {
565+
566+ e := newTopicReaderTestEnv (t )
567+
568+ // doesn't check sends
569+ e .stream .EXPECT ().Send (gomock .Any ()).Return (nil ).MinTimes (0 )
570+
571+ e .Start ()
572+
573+ activePartitionID := e .partitionSession .PartitionID
574+
575+ e .SendFromServer (& rawtopicreader.ReadResponse {
576+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
577+ PartitionData : []rawtopicreader.PartitionData {
578+ {
579+ PartitionSessionID : e .partitionSessionID ,
580+ Batches : []rawtopicreader.Batch {{
581+ Codec : rawtopiccommon .CodecRaw ,
582+ MessageData : []rawtopicreader.MessageData {{Offset : 1 , Data : []byte ("OK" )}},
583+ }},
584+ },
585+ },
586+ })
587+
588+ e .SendFromServer (& rawtopicreader.EndPartitionSession {
589+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
590+ PartitionSessionID : e .partitionSessionID ,
591+ ChildPartitionIDs : []int64 {activePartitionID + 1 , activePartitionID + 2 },
592+ })
593+
594+ e .SendFromServer (& rawtopicreader.StartPartitionSessionRequest {
595+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
596+ PartitionSession : rawtopicreader.PartitionSession {
597+ PartitionSessionID : e .partitionSessionID + 1 ,
598+ Path : e .partitionSession .Topic ,
599+ PartitionID : activePartitionID + 1 ,
600+ },
601+ })
602+
603+ e .SendFromServer (& rawtopicreader.StartPartitionSessionRequest {
604+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
605+ PartitionSession : rawtopicreader.PartitionSession {
606+ PartitionSessionID : e .partitionSessionID + 2 ,
607+ Path : e .partitionSession .Topic ,
608+ PartitionID : activePartitionID + 2 ,
609+ },
610+ })
611+
612+ e .SendFromServer (& rawtopicreader.ReadResponse {
613+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
614+ PartitionData : []rawtopicreader.PartitionData {
615+ {
616+ PartitionSessionID : e .partitionSessionID + 1 ,
617+ Batches : []rawtopicreader.Batch {{
618+ Codec : rawtopiccommon .CodecRaw ,
619+ MessageData : []rawtopicreader.MessageData {{Offset : 1 , Data : []byte ("BAD-1" )}},
620+ }},
621+ },
622+ },
623+ })
624+
625+ allMessagesSent := make (empty.Chan )
626+ e .SendFromServerAndSetNextCallback (& rawtopicreader.ReadResponse {
627+ ServerMessageMetadata : rawtopiccommon.ServerMessageMetadata {Status : rawydb .StatusSuccess },
628+ PartitionData : []rawtopicreader.PartitionData {
629+ {
630+ PartitionSessionID : e .partitionSessionID + 2 ,
631+ Batches : []rawtopicreader.Batch {{
632+ Codec : rawtopiccommon .CodecRaw ,
633+ MessageData : []rawtopicreader.MessageData {{Offset : 1 , Data : []byte ("BAD-2" )}},
634+ }},
635+ },
636+ },
637+ }, func () {
638+ close (allMessagesSent )
639+ })
640+
641+ <- allMessagesSent
642+ batch , err := e .reader .ReadMessageBatch (e .ctx , newReadMessageBatchOptions ())
643+ require .NoError (t , err )
644+ require .Same (t , e .partitionSession , topicreadercommon .BatchGetPartitionSession (batch ))
645+ })
646+ })
647+ }
648+
478649func TestTopicStreamReaderImpl_ReadMessages (t * testing.T ) {
479650 t .Run ("BufferSize" , func (t * testing.T ) {
480651 waitChangeRestBufferSizeBytes := func (r * topicStreamReaderImpl , old int64 ) {
0 commit comments