find_coordinator_response_test.go 1.9 KB

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