fetch_request_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package sarama
  2. import "testing"
  3. var (
  4. fetchRequestNoBlocks = []byte{
  5. 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  6. 0x00, 0x00, 0x00, 0x00}
  7. fetchRequestWithProperties = []byte{
  8. 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xEF,
  9. 0x00, 0x00, 0x00, 0x00}
  10. fetchRequestOneBlock = []byte{
  11. 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12. 0x00, 0x00, 0x00, 0x01,
  13. 0x00, 0x05, 't', 'o', 'p', 'i', 'c',
  14. 0x00, 0x00, 0x00, 0x01,
  15. 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x56}
  16. fetchRequestOneBlockV4 = []byte{
  17. 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18. 0x00, 0x00, 0x00, 0xFF,
  19. 0x01,
  20. 0x00, 0x00, 0x00, 0x01,
  21. 0x00, 0x05, 't', 'o', 'p', 'i', 'c',
  22. 0x00, 0x00, 0x00, 0x01,
  23. 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x56}
  24. fetchRequestOneBlockV11 = []byte{
  25. 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  26. 0x00, 0x00, 0x00, 0xFF,
  27. 0x01,
  28. 0x00, 0x00, 0x00, 0xAA, // sessionID
  29. 0x00, 0x00, 0x00, 0xEE, // sessionEpoch
  30. 0x00, 0x00, 0x00, 0x01,
  31. 0x00, 0x05, 't', 'o', 'p', 'i', 'c',
  32. 0x00, 0x00, 0x00, 0x01,
  33. 0x00, 0x00, 0x00, 0x12, // partitionID
  34. 0xFF, 0xFF, 0xFF, 0xFF, // currentLeaderEpoch
  35. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, // fetchOffset
  36. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // logStartOffset
  37. 0x00, 0x00, 0x00, 0x56, // maxBytes
  38. 0x00, 0x00, 0x00, 0x00,
  39. 0x00, 0x06, 'r', 'a', 'c', 'k', '0', '1', // rackID
  40. }
  41. )
  42. func TestFetchRequest(t *testing.T) {
  43. t.Run("no blocks", func(t *testing.T) {
  44. request := new(FetchRequest)
  45. testRequest(t, "no blocks", request, fetchRequestNoBlocks)
  46. })
  47. t.Run("with properties", func(t *testing.T) {
  48. request := new(FetchRequest)
  49. request.MaxWaitTime = 0x20
  50. request.MinBytes = 0xEF
  51. testRequest(t, "with properties", request, fetchRequestWithProperties)
  52. })
  53. t.Run("one block", func(t *testing.T) {
  54. request := new(FetchRequest)
  55. request.MaxWaitTime = 0
  56. request.MinBytes = 0
  57. request.AddBlock("topic", 0x12, 0x34, 0x56)
  58. testRequest(t, "one block", request, fetchRequestOneBlock)
  59. })
  60. t.Run("one block v4", func(t *testing.T) {
  61. request := new(FetchRequest)
  62. request.Version = 4
  63. request.MaxBytes = 0xFF
  64. request.Isolation = ReadCommitted
  65. request.AddBlock("topic", 0x12, 0x34, 0x56)
  66. testRequest(t, "one block v4", request, fetchRequestOneBlockV4)
  67. })
  68. t.Run("one block v11 rackid", func(t *testing.T) {
  69. request := new(FetchRequest)
  70. request.Version = 11
  71. request.MaxBytes = 0xFF
  72. request.Isolation = ReadCommitted
  73. request.SessionID = 0xAA
  74. request.SessionEpoch = 0xEE
  75. request.AddBlock("topic", 0x12, 0x34, 0x56)
  76. request.RackID = "rack01"
  77. testRequest(t, "one block v11 rackid", request, fetchRequestOneBlockV11)
  78. })
  79. }