fetch_request_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. request := new(FetchRequest)
  27. testRequest(t, "no blocks", request, fetchRequestNoBlocks)
  28. request.MaxWaitTime = 0x20
  29. request.MinBytes = 0xEF
  30. testRequest(t, "with properties", request, fetchRequestWithProperties)
  31. request.MaxWaitTime = 0
  32. request.MinBytes = 0
  33. request.AddBlock("topic", 0x12, 0x34, 0x56)
  34. testRequest(t, "one block", request, fetchRequestOneBlock)
  35. request.Version = 4
  36. request.MaxBytes = 0xFF
  37. request.Isolation = ReadCommitted
  38. testRequest(t, "one block v4", request, fetchRequestOneBlockV4)
  39. }