offset_commit_request_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package sarama
  2. import "testing"
  3. var (
  4. offsetCommitRequestNoBlocksV0 = []byte{
  5. 0x00, 0x06, 'f', 'o', 'o', 'b', 'a', 'r',
  6. 0x00, 0x00, 0x00, 0x00}
  7. offsetCommitRequestNoBlocksV1 = []byte{
  8. 0x00, 0x06, 'f', 'o', 'o', 'b', 'a', 'r',
  9. 0x00, 0x00, 0x11, 0x22,
  10. 0x00, 0x04, 'c', 'o', 'n', 's',
  11. 0x00, 0x00, 0x00, 0x00}
  12. offsetCommitRequestNoBlocksV2 = []byte{
  13. 0x00, 0x06, 'f', 'o', 'o', 'b', 'a', 'r',
  14. 0x00, 0x00, 0x11, 0x22,
  15. 0x00, 0x04, 'c', 'o', 'n', 's',
  16. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x33,
  17. 0x00, 0x00, 0x00, 0x00}
  18. offsetCommitRequestOneBlockV0 = []byte{
  19. 0x00, 0x06, 'f', 'o', 'o', 'b', 'a', 'r',
  20. 0x00, 0x00, 0x00, 0x01,
  21. 0x00, 0x05, 't', 'o', 'p', 'i', 'c',
  22. 0x00, 0x00, 0x00, 0x01,
  23. 0x00, 0x00, 0x52, 0x21,
  24. 0x00, 0x00, 0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF,
  25. 0x00, 0x08, 'm', 'e', 't', 'a', 'd', 'a', 't', 'a'}
  26. offsetCommitRequestOneBlockV1 = []byte{
  27. 0x00, 0x06, 'f', 'o', 'o', 'b', 'a', 'r',
  28. 0x00, 0x00, 0x11, 0x22,
  29. 0x00, 0x04, 'c', 'o', 'n', 's',
  30. 0x00, 0x00, 0x00, 0x01,
  31. 0x00, 0x05, 't', 'o', 'p', 'i', 'c',
  32. 0x00, 0x00, 0x00, 0x01,
  33. 0x00, 0x00, 0x52, 0x21,
  34. 0x00, 0x00, 0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF,
  35. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  36. 0x00, 0x08, 'm', 'e', 't', 'a', 'd', 'a', 't', 'a'}
  37. offsetCommitRequestOneBlockV2 = []byte{
  38. 0x00, 0x06, 'f', 'o', 'o', 'b', 'a', 'r',
  39. 0x00, 0x00, 0x11, 0x22,
  40. 0x00, 0x04, 'c', 'o', 'n', 's',
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x33,
  42. 0x00, 0x00, 0x00, 0x01,
  43. 0x00, 0x05, 't', 'o', 'p', 'i', 'c',
  44. 0x00, 0x00, 0x00, 0x01,
  45. 0x00, 0x00, 0x52, 0x21,
  46. 0x00, 0x00, 0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF,
  47. 0x00, 0x08, 'm', 'e', 't', 'a', 'd', 'a', 't', 'a'}
  48. )
  49. func TestOffsetCommitRequestV0(t *testing.T) {
  50. request := new(OffsetCommitRequest)
  51. request.Version = 0
  52. request.ConsumerGroup = "foobar"
  53. testRequest(t, "no blocks v0", request, offsetCommitRequestNoBlocksV0)
  54. request.AddBlock("topic", 0x5221, 0xDEADBEEF, 0, "metadata")
  55. testRequest(t, "one block v0", request, offsetCommitRequestOneBlockV0)
  56. }
  57. func TestOffsetCommitRequestV1(t *testing.T) {
  58. request := new(OffsetCommitRequest)
  59. request.ConsumerGroup = "foobar"
  60. request.ConsumerID = "cons"
  61. request.ConsumerGroupGeneration = 0x1122
  62. request.Version = 1
  63. testRequest(t, "no blocks v1", request, offsetCommitRequestNoBlocksV1)
  64. request.AddBlock("topic", 0x5221, 0xDEADBEEF, ReceiveTime, "metadata")
  65. testRequest(t, "one block v1", request, offsetCommitRequestOneBlockV1)
  66. }
  67. func TestOffsetCommitRequestV2(t *testing.T) {
  68. request := new(OffsetCommitRequest)
  69. request.ConsumerGroup = "foobar"
  70. request.ConsumerID = "cons"
  71. request.ConsumerGroupGeneration = 0x1122
  72. request.RetentionTime = 0x4433
  73. request.Version = 2
  74. testRequest(t, "no blocks v2", request, offsetCommitRequestNoBlocksV2)
  75. request.AddBlock("topic", 0x5221, 0xDEADBEEF, 0, "metadata")
  76. testRequest(t, "one block v2", request, offsetCommitRequestOneBlockV2)
  77. }