offset_fetch_response_test.go 1.4 KB

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