@@ -2902,15 +2902,24 @@ func TestJetStreamFastBatchPublish(t *testing.T) {
29022902 _ , err := jsStreamCreate (t , nc , cfg )
29032903 require_NoError (t , err )
29042904
2905- reply := nats .NewInbox ()
2906- sub , err := nc .SubscribeSync (reply )
2905+ inbox := nats .NewInbox ()
2906+ generateReply := func (batchId string , batchSeq uint64 , flow uint64 , gap string , v int ) string {
2907+ return fmt .Sprintf ("%s.%d.%s.%s.%d.%d.$FI" , inbox , flow , gap , batchId , batchSeq , v )
2908+ }
2909+ generateNormalReply := func (batchId string , batchSeq uint64 , gap string ) string {
2910+ return generateReply (batchId , batchSeq , 0 , gap , 0 )
2911+ }
2912+ generateCommitReply := func (batchId string , batchSeq uint64 , gap string ) string {
2913+ return generateReply (batchId , batchSeq , 0 , gap , 1 )
2914+ }
2915+
2916+ sub , err := nc .SubscribeSync (fmt .Sprintf ("%s.>" , inbox ))
29072917 require_NoError (t , err )
29082918 defer sub .Drain ()
29092919
29102920 m := nats .NewMsg ("foo.0" )
2911- m .Reply = reply
2921+ m .Reply = generateNormalReply ( "uuid" , 0 , JSFastBatchGapFail )
29122922 m .Data = []byte ("foo.0" )
2913- m .Header .Set ("Nats-Fast-Batch-Id" , "uuid" )
29142923
29152924 // Publish with batch publish disabled.
29162925 require_NoError (t , nc .PublishMsg (m ))
@@ -2925,17 +2934,18 @@ func TestJetStreamFastBatchPublish(t *testing.T) {
29252934 _ , err = jsStreamUpdate (t , nc , cfg )
29262935 require_NoError (t , err )
29272936
2928- // Publish without batch sequence errors.
2937+ // Publish with incorrect batch sequence errors.
2938+ m .Reply = generateNormalReply ("uuid" , 0 , JSFastBatchGapFail )
29292939 require_NoError (t , nc .PublishMsg (m ))
29302940 rmsg , err = sub .NextMsg (time .Second )
29312941 require_NoError (t , err )
29322942 pubAck = JSPubAckResponse {}
29332943 require_NoError (t , json .Unmarshal (rmsg .Data , & pubAck ))
2934- require_Error (t , pubAck .Error , NewJSBatchPublishMissingSeqError ())
2944+ require_Error (t , pubAck .Error , NewJSBatchPublishInvalidPatternError ())
29352945
29362946 // A batch ID must not exceed the maximum length.
29372947 longBatchId := strings .Repeat ("A" , 65 )
2938- m .Header . Set ( "Nats-Fast-Batch-Id" , longBatchId )
2948+ m .Reply = generateNormalReply ( longBatchId , 1 , JSFastBatchGapFail )
29392949 require_NoError (t , nc .PublishMsg (m ))
29402950 rmsg , err = sub .NextMsg (time .Second )
29412951 require_NoError (t , err )
@@ -2945,8 +2955,7 @@ func TestJetStreamFastBatchPublish(t *testing.T) {
29452955 require_Error (t , pubAck .Error , NewJSBatchPublishInvalidBatchIDError ())
29462956
29472957 // Publish a batch, misses start.
2948- m .Header .Set ("Nats-Fast-Batch-Id" , "uuid" )
2949- m .Header .Set ("Nats-Batch-Sequence" , "2" )
2958+ m .Reply = generateNormalReply ("uuid" , 2 , JSFastBatchGapFail )
29502959 require_NoError (t , nc .PublishMsg (m ))
29512960 rmsg , err = sub .NextMsg (time .Second )
29522961 require_NoError (t , err )
@@ -2955,9 +2964,7 @@ func TestJetStreamFastBatchPublish(t *testing.T) {
29552964 require_Error (t , pubAck .Error , NewJSBatchPublishUnknownBatchIDError ())
29562965
29572966 // Publish a "batch" which immediately commits.
2958- m .Header .Set ("Nats-Fast-Batch-Id" , "uuid" )
2959- m .Header .Set ("Nats-Batch-Sequence" , "1" )
2960- m .Header .Set ("Nats-Batch-Commit" , "1" )
2967+ m .Reply = generateCommitReply ("uuid" , 1 , JSFastBatchGapFail )
29612968 require_NoError (t , nc .PublishMsg (m ))
29622969 rmsg , err = sub .NextMsg (time .Second )
29632970 require_NoError (t , err )
@@ -2973,13 +2980,13 @@ func TestJetStreamFastBatchPublish(t *testing.T) {
29732980 require_Equal (t , pubAck .BatchSize , 1 )
29742981
29752982 // Publish a batch of N messages.
2976- m .Header .Del ("Nats-Batch-Commit" )
29772983 for seq , batch := uint64 (1 ), uint64 (5 ); seq <= batch ; seq ++ {
29782984 m .Subject = fmt .Sprintf ("foo.%d" , seq )
29792985 m .Data = []byte (m .Subject )
2980- m .Header .Set ("Nats-Batch-Sequence" , strconv .FormatUint (seq , 10 ))
29812986 if seq == batch {
2982- m .Header .Set ("Nats-Batch-Commit" , "1" )
2987+ m .Reply = generateCommitReply ("uuid" , seq , JSFastBatchGapFail )
2988+ } else {
2989+ m .Reply = generateNormalReply ("uuid" , seq , JSFastBatchGapFail )
29832990 }
29842991 require_NoError (t , nc .PublishMsg (m ))
29852992
0 commit comments