offset_fetch_response_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. t.Fatal("Decoding produced wrong number of blocks.")
  37. }
  38. if len(response.Blocks["m"]) != 0 {
  39. t.Error("Decoding produced partitions for topic 'm' where there were none.")
  40. }
  41. if len(response.Blocks["t"]) != 1 {
  42. t.Fatal("Decoding produced wrong number of blocks for topic 't'.")
  43. }
  44. if response.Blocks["t"][0].Offset != 0 {
  45. t.Error("Decoding produced wrong offset for topic 't' partition 0.")
  46. }
  47. if response.Blocks["t"][0].Metadata != "md" {
  48. t.Error("Decoding produced wrong metadata for topic 't' partition 0.")
  49. }
  50. if response.Blocks["t"][0].Err != RequestTimedOut {
  51. t.Error("Decoding produced wrong error for topic 't' partition 0.")
  52. }
  53. }