find_coordinator_response_test.go 856 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package sarama
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. var (
  7. findCoordinatorResponse = []byte{
  8. 0, 0, 0, 100,
  9. 0, 0,
  10. 255, 255, // empty ErrMsg
  11. 0, 0, 0, 1,
  12. 0, 4, 'h', 'o', 's', 't',
  13. 0, 0, 35, 132,
  14. }
  15. findCoordinatorResponseError = []byte{
  16. 0, 0, 0, 100,
  17. 0, 15,
  18. 0, 3, 'm', 's', 'g',
  19. 0, 0, 0, 1,
  20. 0, 4, 'h', 'o', 's', 't',
  21. 0, 0, 35, 132,
  22. }
  23. )
  24. func TestFindCoordinatorResponse(t *testing.T) {
  25. broker := NewBroker("host:9092")
  26. broker.id = 1
  27. resp := &FindCoordinatorResponse{
  28. Version: 1,
  29. ThrottleTime: 100 * time.Millisecond,
  30. Err: ErrNoError,
  31. ErrMsg: nil,
  32. Coordinator: broker,
  33. }
  34. testResponse(t, "version 1 - no error", resp, findCoordinatorResponse)
  35. msg := "msg"
  36. resp.Err = ErrConsumerCoordinatorNotAvailable
  37. resp.ErrMsg = &msg
  38. testResponse(t, "version 1 - error", resp, findCoordinatorResponseError)
  39. }