find_coordinator_response_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package sarama
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestFindCoordinatorResponse(t *testing.T) {
  7. errMsg := "kaboom"
  8. brokerRack := "foo"
  9. for _, tc := range []struct {
  10. desc string
  11. response *FindCoordinatorResponse
  12. encoded []byte
  13. }{{
  14. desc: "version 0 - no error",
  15. response: &FindCoordinatorResponse{
  16. Version: 0,
  17. Err: ErrNoError,
  18. Coordinator: &Broker{
  19. id: 7,
  20. addr: "host:9092",
  21. },
  22. },
  23. encoded: []byte{
  24. 0, 0, // Err
  25. 0, 0, 0, 7, // Coordinator.ID
  26. 0, 4, 'h', 'o', 's', 't', // Coordinator.Host
  27. 0, 0, 35, 132, // Coordinator.Port
  28. },
  29. }, {
  30. desc: "version 1 - no error",
  31. response: &FindCoordinatorResponse{
  32. Version: 1,
  33. ThrottleTime: 100 * time.Millisecond,
  34. Err: ErrNoError,
  35. Coordinator: &Broker{
  36. id: 7,
  37. addr: "host:9092",
  38. rack: &brokerRack,
  39. },
  40. },
  41. encoded: []byte{
  42. 0, 0, 0, 100, // ThrottleTime
  43. 0, 0, // Err
  44. 255, 255, // ErrMsg: empty
  45. 0, 0, 0, 7, // Coordinator.ID
  46. 0, 4, 'h', 'o', 's', 't', // Coordinator.Host
  47. 0, 0, 35, 132, // Coordinator.Port
  48. 0, 3, 'f', 'o', 'o', // Coordinator.Rack
  49. },
  50. }, {
  51. desc: "version 0 - error",
  52. response: &FindCoordinatorResponse{
  53. Version: 0,
  54. Err: ErrConsumerCoordinatorNotAvailable,
  55. Coordinator: NoNode,
  56. },
  57. encoded: []byte{
  58. 0, 15, // Err
  59. 255, 255, 255, 255, // Coordinator.ID: -1
  60. 0, 0, // Coordinator.Host: ""
  61. 255, 255, 255, 255, // Coordinator.Port: -1
  62. },
  63. }, {
  64. desc: "version 1 - error",
  65. response: &FindCoordinatorResponse{
  66. Version: 1,
  67. ThrottleTime: 100 * time.Millisecond,
  68. Err: ErrConsumerCoordinatorNotAvailable,
  69. ErrMsg: &errMsg,
  70. Coordinator: NoNode,
  71. },
  72. encoded: []byte{
  73. 0, 0, 0, 100, // ThrottleTime
  74. 0, 15, // Err
  75. 0, 6, 'k', 'a', 'b', 'o', 'o', 'm', // ErrMsg
  76. 255, 255, 255, 255, // Coordinator.ID: -1
  77. 0, 0, // Coordinator.Host: ""
  78. 255, 255, 255, 255, // Coordinator.Port: -1
  79. 255, 255, // Coordinator.Rack: empty
  80. },
  81. }} {
  82. testResponse(t, tc.desc, tc.response, tc.encoded)
  83. }
  84. }