produce_request_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package sarama
  2. import (
  3. "testing"
  4. )
  5. var (
  6. produceRequestEmpty = []byte{
  7. 0x00, 0x00,
  8. 0x00, 0x00, 0x00, 0x00,
  9. 0x00, 0x00, 0x00, 0x00}
  10. produceRequestHeader = []byte{
  11. 0x01, 0x23,
  12. 0x00, 0x00, 0x04, 0x44,
  13. 0x00, 0x00, 0x00, 0x00}
  14. produceRequestOneMessage = []byte{
  15. 0x01, 0x23,
  16. 0x00, 0x00, 0x04, 0x44,
  17. 0x00, 0x00, 0x00, 0x01,
  18. 0x00, 0x05, 't', 'o', 'p', 'i', 'c',
  19. 0x00, 0x00, 0x00, 0x01,
  20. 0x00, 0x00, 0x00, 0xAD,
  21. 0x00, 0x00, 0x00, 0x1C,
  22. // messageSet
  23. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  24. 0x00, 0x00, 0x00, 0x10,
  25. // message
  26. 0x23, 0x96, 0x4a, 0xf7, // CRC
  27. 0x00,
  28. 0x00,
  29. 0xFF, 0xFF, 0xFF, 0xFF,
  30. 0x00, 0x00, 0x00, 0x02, 0x00, 0xEE}
  31. )
  32. func TestProduceRequest(t *testing.T) {
  33. request := new(ProduceRequest)
  34. testRequest(t, "empty", request, produceRequestEmpty)
  35. request.RequiredAcks = 0x123
  36. request.Timeout = 0x444
  37. testRequest(t, "header", request, produceRequestHeader)
  38. request.AddMessage("topic", 0xAD, &Message{Codec: CompressionNone, Key: nil, Value: []byte{0x00, 0xEE}})
  39. testRequest(t, "one message", request, produceRequestOneMessage)
  40. }