offset_response_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package protocol
  2. import "testing"
  3. import "sarama/types"
  4. var (
  5. emptyOffsetResponse = []byte{
  6. 0x00, 0x00, 0x00, 0x00}
  7. normalOffsetResponse = []byte{
  8. 0x00, 0x00, 0x00, 0x02,
  9. 0x00, 0x01, 'a',
  10. 0x00, 0x00, 0x00, 0x00,
  11. 0x00, 0x01, 'z',
  12. 0x00, 0x00, 0x00, 0x01,
  13. 0x00, 0x00, 0x00, 0x02,
  14. 0x00, 0x00,
  15. 0x00, 0x00, 0x00, 0x02,
  16. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
  17. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06}
  18. )
  19. func TestEmptyOffsetResponse(t *testing.T) {
  20. response := OffsetResponse{}
  21. testDecodable(t, "empty", &response, emptyOffsetResponse)
  22. if len(response.Blocks) != 0 {
  23. t.Error("Decoding produced", len(response.Blocks), "topics where there were none.")
  24. }
  25. }
  26. func TestNormalOffsetResponse(t *testing.T) {
  27. response := OffsetResponse{}
  28. testDecodable(t, "normal", &response, normalOffsetResponse)
  29. if len(response.Blocks) == 2 {
  30. if len(response.Blocks["a"]) != 0 {
  31. t.Error("Decoding produced", len(response.Blocks["a"]), "partitions for topic 'a' where there were none.")
  32. }
  33. if len(response.Blocks["z"]) == 1 {
  34. if response.Blocks["z"][2].Err != types.NO_ERROR {
  35. t.Error("Decoding produced invalid error for topic z partition 2.")
  36. }
  37. if len(response.Blocks["z"][2].Offsets) == 2 {
  38. if response.Blocks["z"][2].Offsets[0] != 5 || response.Blocks["z"][2].Offsets[1] != 6 {
  39. t.Error("Decoding produced invalid offsets for topic z partition 2.")
  40. }
  41. } else {
  42. t.Error("Decoding produced invalid number of offsets for topic z partition 2.")
  43. }
  44. } else {
  45. t.Error("Decoding produced", len(response.Blocks["z"]), "partitions for topic 'z' where there was one.")
  46. }
  47. } else {
  48. t.Error("Decoding produced", len(response.Blocks), "topics where there were two.")
  49. }
  50. }