github.com/QuangHoangHao/kafka-go@v0.4.36/protocol/joingroup/joingroup_test.go (about)

     1  package joingroup_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/QuangHoangHao/kafka-go/protocol/joingroup"
     7  	"github.com/QuangHoangHao/kafka-go/protocol/prototest"
     8  )
     9  
    10  func TestJoinGroupReq(t *testing.T) {
    11  	for _, version := range []int16{0} {
    12  		prototest.TestRequest(t, version, &joingroup.Request{
    13  			GroupID:          "group-id",
    14  			SessionTimeoutMS: 10,
    15  			MemberID:         "member-id",
    16  			ProtocolType:     "protocol-type",
    17  			Protocols: []joingroup.RequestProtocol{
    18  				{
    19  					Name:     "protocol-1",
    20  					Metadata: []byte{0, 1, 2, 3, 4},
    21  				},
    22  			},
    23  		})
    24  	}
    25  
    26  	// Version 1 added
    27  	// RebalanceTimeoutMS
    28  	for _, version := range []int16{1, 2, 3, 4} {
    29  		prototest.TestRequest(t, version, &joingroup.Request{
    30  			GroupID:            "group-id",
    31  			SessionTimeoutMS:   10,
    32  			RebalanceTimeoutMS: 10,
    33  			MemberID:           "member-id",
    34  			ProtocolType:       "protocol-type",
    35  			Protocols: []joingroup.RequestProtocol{
    36  				{
    37  					Name:     "protocol-1",
    38  					Metadata: []byte{0, 1, 2, 3, 4},
    39  				},
    40  			},
    41  		})
    42  	}
    43  
    44  	// Version 5 added
    45  	// GroupInstanceID
    46  	for _, version := range []int16{5, 6, 7} {
    47  		prototest.TestRequest(t, version, &joingroup.Request{
    48  			GroupID:            "group-id",
    49  			SessionTimeoutMS:   10,
    50  			RebalanceTimeoutMS: 10,
    51  			MemberID:           "member-id",
    52  			ProtocolType:       "protocol-type",
    53  			GroupInstanceID:    "group-instance-id",
    54  			Protocols: []joingroup.RequestProtocol{
    55  				{
    56  					Name:     "protocol-1",
    57  					Metadata: []byte{0, 1, 2, 3, 4},
    58  				},
    59  			},
    60  		})
    61  	}
    62  }
    63  
    64  func TestJoinGroupResp(t *testing.T) {
    65  	for _, version := range []int16{0, 1} {
    66  		prototest.TestResponse(t, version, &joingroup.Response{
    67  			ErrorCode:    10,
    68  			GenerationID: 10,
    69  			ProtocolName: "protocol-name",
    70  			LeaderID:     "leader",
    71  			MemberID:     "member-id-1",
    72  			Members: []joingroup.ResponseMember{
    73  				{
    74  					MemberID: "member-id-2",
    75  					Metadata: []byte{0, 1, 2, 3, 4},
    76  				},
    77  			},
    78  		})
    79  	}
    80  
    81  	// Version 2 added
    82  	// ThrottleTimeMS
    83  	for _, version := range []int16{2, 3, 4} {
    84  		prototest.TestResponse(t, version, &joingroup.Response{
    85  			ErrorCode:      10,
    86  			GenerationID:   10,
    87  			ThrottleTimeMS: 100,
    88  			ProtocolName:   "protocol-name",
    89  			LeaderID:       "leader",
    90  			MemberID:       "member-id-1",
    91  			Members: []joingroup.ResponseMember{
    92  				{
    93  					MemberID: "member-id-2",
    94  					Metadata: []byte{0, 1, 2, 3, 4},
    95  				},
    96  			},
    97  		})
    98  	}
    99  
   100  	// Version 5 added
   101  	// ResponseMember.GroupInstanceID
   102  	for _, version := range []int16{5, 6} {
   103  		prototest.TestResponse(t, version, &joingroup.Response{
   104  			ErrorCode:      10,
   105  			GenerationID:   10,
   106  			ThrottleTimeMS: 100,
   107  			ProtocolName:   "protocol-name",
   108  			LeaderID:       "leader",
   109  			MemberID:       "member-id-1",
   110  			Members: []joingroup.ResponseMember{
   111  				{
   112  					MemberID:        "member-id-2",
   113  					Metadata:        []byte{0, 1, 2, 3, 4},
   114  					GroupInstanceID: "group-instance-id",
   115  				},
   116  			},
   117  		})
   118  	}
   119  
   120  	// Version 7 added
   121  	// ProtocolType
   122  	for _, version := range []int16{7} {
   123  		prototest.TestResponse(t, version, &joingroup.Response{
   124  			ErrorCode:      10,
   125  			GenerationID:   10,
   126  			ThrottleTimeMS: 100,
   127  			ProtocolName:   "protocol-name",
   128  			ProtocolType:   "protocol-type",
   129  			LeaderID:       "leader",
   130  			MemberID:       "member-id-1",
   131  			Members: []joingroup.ResponseMember{
   132  				{
   133  					MemberID:        "member-id-2",
   134  					Metadata:        []byte{0, 1, 2, 3, 4},
   135  					GroupInstanceID: "group-instance-id",
   136  				},
   137  			},
   138  		})
   139  	}
   140  }