fetch_request_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. )
  25. func TestFetchRequest(t *testing.T) {
  26. t.Run("no blocks", func(t *testing.T) {
  27. request := new(FetchRequest)
  28. testRequest(t, "no blocks", request, fetchRequestNoBlocks)
  29. })
  30. t.Run("with properties", func(t *testing.T) {
  31. request := new(FetchRequest)
  32. request.MaxWaitTime = 0x20
  33. request.MinBytes = 0xEF
  34. testRequest(t, "with properties", request, fetchRequestWithProperties)
  35. })
  36. t.Run("one block", func(t *testing.T) {
  37. request := new(FetchRequest)
  38. request.MaxWaitTime = 0
  39. request.MinBytes = 0
  40. request.AddBlock("topic", 0x12, 0x34, 0x56)
  41. testRequest(t, "one block", request, fetchRequestOneBlock)
  42. })
  43. t.Run("one block v4", func(t *testing.T) {
  44. request := new(FetchRequest)
  45. request.Version = 4
  46. request.MaxBytes = 0xFF
  47. request.Isolation = ReadCommitted
  48. request.AddBlock("topic", 0x12, 0x34, 0x56)
  49. testRequest(t, "one block v4", request, fetchRequestOneBlockV4)
  50. })
  51. }