join_group_request_test.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package sarama
  2. import "testing"
  3. var (
  4. joinGroupRequestV0_NoProtocols = []byte{
  5. 0, 9, 'T', 'e', 's', 't', 'G', 'r', 'o', 'u', 'p', // Group ID
  6. 0, 0, 0, 100, // Session timeout
  7. 0, 0, // Member ID
  8. 0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // Protocol Type
  9. 0, 0, 0, 0, // 0 protocol groups
  10. }
  11. joinGroupRequestV0_OneProtocol = []byte{
  12. 0, 9, 'T', 'e', 's', 't', 'G', 'r', 'o', 'u', 'p', // Group ID
  13. 0, 0, 0, 100, // Session timeout
  14. 0, 11, 'O', 'n', 'e', 'P', 'r', 'o', 't', 'o', 'c', 'o', 'l', // Member ID
  15. 0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // Protocol Type
  16. 0, 0, 0, 1, // 1 group protocol
  17. 0, 3, 'o', 'n', 'e', // Protocol name
  18. 0, 0, 0, 3, 0x01, 0x02, 0x03, // protocol metadata
  19. }
  20. joinGroupRequestV1 = []byte{
  21. 0, 9, 'T', 'e', 's', 't', 'G', 'r', 'o', 'u', 'p', // Group ID
  22. 0, 0, 0, 100, // Session timeout
  23. 0, 0, 0, 200, // Rebalance timeout
  24. 0, 11, 'O', 'n', 'e', 'P', 'r', 'o', 't', 'o', 'c', 'o', 'l', // Member ID
  25. 0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // Protocol Type
  26. 0, 0, 0, 1, // 1 group protocol
  27. 0, 3, 'o', 'n', 'e', // Protocol name
  28. 0, 0, 0, 3, 0x01, 0x02, 0x03, // protocol metadata
  29. }
  30. )
  31. func TestJoinGroupRequest(t *testing.T) {
  32. request := new(JoinGroupRequest)
  33. request.GroupID = "TestGroup"
  34. request.SessionTimeout = 100
  35. request.ProtocolType = "consumer"
  36. testRequest(t, "V0: no protocols", request, joinGroupRequestV0_NoProtocols)
  37. }
  38. func TestJoinGroupRequestV0_OneProtocol(t *testing.T) {
  39. request := new(JoinGroupRequest)
  40. request.GroupID = "TestGroup"
  41. request.SessionTimeout = 100
  42. request.MemberID = "OneProtocol"
  43. request.ProtocolType = "consumer"
  44. request.AddGroupProtocol("one", []byte{0x01, 0x02, 0x03})
  45. packet := testRequestEncode(t, "V0: one protocol", request, joinGroupRequestV0_OneProtocol)
  46. request.GroupProtocols = make(map[string][]byte)
  47. request.GroupProtocols["one"] = []byte{0x01, 0x02, 0x03}
  48. testRequestDecode(t, "V0: one protocol", request, packet)
  49. }
  50. func TestJoinGroupRequestDeprecatedEncode(t *testing.T) {
  51. request := new(JoinGroupRequest)
  52. request.GroupID = "TestGroup"
  53. request.SessionTimeout = 100
  54. request.MemberID = "OneProtocol"
  55. request.ProtocolType = "consumer"
  56. request.GroupProtocols = make(map[string][]byte)
  57. request.GroupProtocols["one"] = []byte{0x01, 0x02, 0x03}
  58. packet := testRequestEncode(t, "V0: one protocol", request, joinGroupRequestV0_OneProtocol)
  59. request.AddGroupProtocol("one", []byte{0x01, 0x02, 0x03})
  60. testRequestDecode(t, "V0: one protocol", request, packet)
  61. }
  62. func TestJoinGroupRequestV1(t *testing.T) {
  63. request := new(JoinGroupRequest)
  64. request.Version = 1
  65. request.GroupID = "TestGroup"
  66. request.SessionTimeout = 100
  67. request.RebalanceTimeout = 200
  68. request.MemberID = "OneProtocol"
  69. request.ProtocolType = "consumer"
  70. request.AddGroupProtocol("one", []byte{0x01, 0x02, 0x03})
  71. packet := testRequestEncode(t, "V1", request, joinGroupRequestV1)
  72. request.GroupProtocols = make(map[string][]byte)
  73. request.GroupProtocols["one"] = []byte{0x01, 0x02, 0x03}
  74. testRequestDecode(t, "V1", request, packet)
  75. }