@@ -519,3 +519,52 @@ func TestSyncResponse(t *testing.T) {
519
519
require .NoError (t , err )
520
520
assert .Equal (t , "hello world c" , string (data ))
521
521
}
522
+
523
+ func TestSyncResponseBatched (t * testing.T ) {
524
+ batchA := MessageBatch {
525
+ NewMessage ([]byte ("hello world a 1" )),
526
+ NewMessage ([]byte ("hello world a 2" )),
527
+ NewMessage ([]byte ("hello world a 3" )),
528
+ }
529
+
530
+ batchB , storeB := batchA .WithSyncResponseStore ()
531
+ batchB [0 ].SetBytes ([]byte ("hello world b 1" ))
532
+ batchB [1 ].SetBytes ([]byte ("hello world b 2" ))
533
+ batchB [2 ].SetBytes ([]byte ("hello world b 3" ))
534
+
535
+ require .Error (t , batchA .AddSyncResponse ())
536
+ require .NoError (t , batchB .AddSyncResponse ())
537
+
538
+ batchC := batchB .Copy ()
539
+ batchC [1 ].SetBytes ([]byte ("hello world c 2" ))
540
+ require .NoError (t , batchC .AddSyncResponse ())
541
+
542
+ batchD := batchA .Copy ()
543
+ batchD [1 ].SetBytes ([]byte ("hello world d 2" ))
544
+ require .Error (t , batchD .AddSyncResponse ())
545
+
546
+ resBatches := storeB .Read ()
547
+ require .Len (t , resBatches , 2 )
548
+ require .Len (t , resBatches [0 ], 3 )
549
+ require .Len (t , resBatches [1 ], 3 )
550
+
551
+ for i , c := range []string {
552
+ "hello world b 1" ,
553
+ "hello world b 2" ,
554
+ "hello world b 3" ,
555
+ } {
556
+ data , err := resBatches [0 ][i ].AsBytes ()
557
+ require .NoError (t , err )
558
+ assert .Equal (t , c , string (data ))
559
+ }
560
+
561
+ for i , c := range []string {
562
+ "hello world b 1" ,
563
+ "hello world c 2" ,
564
+ "hello world b 3" ,
565
+ } {
566
+ data , err := resBatches [1 ][i ].AsBytes ()
567
+ require .NoError (t , err )
568
+ assert .Equal (t , c , string (data ))
569
+ }
570
+ }
0 commit comments