offset_fetch_response_test.go 1.7 KB

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