offset_fetch_response_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package protocol
  2. import "testing"
  3. import "sarama/types"
  4. var (
  5. emptyOffsetFetchResponse = []byte{
  6. 0xFF, 0xFF,
  7. 0x00, 0x00, 0x00, 0x00}
  8. normalOffsetFetchResponse = []byte{
  9. 0x00, 0x02, 'z', 'a',
  10. 0x00, 0x00, 0x00, 0x02,
  11. 0x00, 0x01, 'm',
  12. 0x00, 0x00, 0x00, 0x00,
  13. 0x00, 0x01, 't',
  14. 0x00, 0x00, 0x00, 0x01,
  15. 0x00, 0x00, 0x00, 0x00,
  16. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  17. 0x00, 0x02, 'm', 'd',
  18. 0x00, 0x07}
  19. )
  20. func TestEmptyOffsetFetchResponse(t *testing.T) {
  21. response := OffsetFetchResponse{}
  22. testDecodable(t, "empty", &response, emptyOffsetFetchResponse)
  23. if response.ClientID != "" {
  24. t.Error("Decoding produced client ID where there was none.")
  25. }
  26. if len(response.Blocks) != 0 {
  27. t.Error("Decoding produced topic blocks where there were none.")
  28. }
  29. }
  30. func TestNormalOffsetFetchResponse(t *testing.T) {
  31. response := OffsetFetchResponse{}
  32. testDecodable(t, "normal", &response, normalOffsetFetchResponse)
  33. if response.ClientID != "za" {
  34. t.Error("Decoding produced wrong client ID.")
  35. }
  36. if len(response.Blocks) == 2 {
  37. if len(response.Blocks["m"]) != 0 {
  38. t.Error("Decoding produced partitions for topic 'm' where there were none.")
  39. }
  40. if len(response.Blocks["t"]) == 1 {
  41. if response.Blocks["t"][0].Offset != 0 {
  42. t.Error("Decoding produced wrong offset for topic 't' partition 0.")
  43. }
  44. if response.Blocks["t"][0].Metadata != "md" {
  45. t.Error("Decoding produced wrong metadata for topic 't' partition 0.")
  46. }
  47. if response.Blocks["t"][0].Err != types.REQUEST_TIMED_OUT {
  48. t.Error("Decoding produced wrong error for topic 't' partition 0.")
  49. }
  50. } else {
  51. t.Error("Decoding produced wrong number of blocks for topic 't'.")
  52. }
  53. } else {
  54. t.Error("Decoding produced wrong number of blocks.")
  55. }
  56. }