@@ -419,7 +419,7 @@ func TestConsumeMessageDirectlyResult_MarshalJSON(t *testing.T) {
419419}
420420
421421func TestRestOffsetBody_MarshalJSON (t * testing.T ) {
422- Convey ("test ResetOffset Body Decode" , t , func () {
422+ Convey ("test ResetOffset Body Decode gson json schema " , t , func () {
423423 body := "{\" offsetTable\" :[[{\" topic\" :\" zx_tst\" ,\" brokerName\" :\" tjwqtst-common-rocketmq-raft0\" ,\" queueId\" :5},23354233],[{\" topic\" :\" zx_tst\" ,\" brokerName\" :\" tjwqtst-common-rocketmq-raft0\" ,\" queueId\" :4},23354245],[{\" topic\" :\" zx_tst\" ,\" brokerName\" :\" tjwqtst-common-rocketmq-raft0\" ,\" queueId\" :7},23354203],[{\" topic\" :\" zx_tst\" ,\" brokerName\" :\" tjwqtst-common-rocketmq-raft0\" ,\" queueId\" :6},23354312],[{\" topic\" :\" zx_tst\" ,\" brokerName\" :\" tjwqtst-common-rocketmq-raft0\" ,\" queueId\" :1},23373517],[{\" topic\" :\" zx_tst\" ,\" brokerName\" :\" tjwqtst-common-rocketmq-raft0\" ,\" queueId\" :0},23373350],[{\" topic\" :\" zx_tst\" ,\" brokerName\" :\" tjwqtst-common-rocketmq-raft0\" ,\" queueId\" :3},23373424],[{\" topic\" :\" zx_tst\" ,\" brokerName\" :\" tjwqtst-common-rocketmq-raft0\" ,\" queueId\" :2},23373382]]}"
424424 resetOffsetBody := new (ResetOffsetBody )
425425 resetOffsetBody .Decode ([]byte (body ))
@@ -433,4 +433,52 @@ func TestRestOffsetBody_MarshalJSON(t *testing.T) {
433433 }
434434 So (offsetTable [messageQueue ], ShouldEqual , 23354233 )
435435 })
436+
437+ Convey ("test ResetOffset Body Decode fast json schema" , t , func () {
438+ body := "{\" offsetTable\" :{{\" brokerName\" :\" RaftNode00\" ,\" queueId\" :0,\" topic\" :\" topicB\" }:11110,{\" brokerName\" :\" RaftNode00\" ,\" queueId\" :1,\" topic\" :\" topicB\" }:0,{\" brokerName\" :\" RaftNode00\" ,\" queueId\" :2,\" topic\" :\" topicB\" }:0,{\" brokerName\" :\" RaftNode00\" ,\" queueId\" :3,\" topic\" :\" topicB\" }:0}}"
439+ resetOffsetBody := new (ResetOffsetBody )
440+ resetOffsetBody .Decode ([]byte (body ))
441+ offsetTable := resetOffsetBody .OffsetTable
442+ So (offsetTable , ShouldNotBeNil )
443+ So (len (offsetTable ), ShouldEqual , 4 )
444+ messageQueue := primitive.MessageQueue {
445+ Topic : "topicB" ,
446+ BrokerName : "RaftNode00" ,
447+ QueueId : 0 ,
448+ }
449+ So (offsetTable [messageQueue ], ShouldEqual , 11110 )
450+ })
451+
452+ Convey ("test ResetOffset Body Decode fast json schema with one item" , t , func () {
453+ body := "{\" offsetTable\" :{{\" brokerName\" :\" RaftNode00\" ,\" queueId\" :0,\" topic\" :\" topicB\" }:11110}}"
454+ resetOffsetBody := new (ResetOffsetBody )
455+ resetOffsetBody .Decode ([]byte (body ))
456+ offsetTable := resetOffsetBody .OffsetTable
457+ So (offsetTable , ShouldNotBeNil )
458+ So (len (offsetTable ), ShouldEqual , 1 )
459+ messageQueue := primitive.MessageQueue {
460+ Topic : "topicB" ,
461+ BrokerName : "RaftNode00" ,
462+ QueueId : 0 ,
463+ }
464+ So (offsetTable [messageQueue ], ShouldEqual , 11110 )
465+ })
466+
467+ Convey ("test ResetOffset Body Decode empty fast json " , t , func () {
468+ body := "{\" offsetTable\" :{}}"
469+ resetOffsetBody := new (ResetOffsetBody )
470+ resetOffsetBody .Decode ([]byte (body ))
471+ offsetTable := resetOffsetBody .OffsetTable
472+ So (offsetTable , ShouldNotBeNil )
473+ So (len (offsetTable ), ShouldEqual , 0 )
474+ })
475+
476+ Convey ("test ResetOffset Body Decode empty gson json " , t , func () {
477+ body := "{\" offsetTable\" :[]}"
478+ resetOffsetBody := new (ResetOffsetBody )
479+ resetOffsetBody .Decode ([]byte (body ))
480+ offsetTable := resetOffsetBody .OffsetTable
481+ So (offsetTable , ShouldNotBeNil )
482+ So (len (offsetTable ), ShouldEqual , 0 )
483+ })
436484}
0 commit comments