offset_commit_request_test.go 3.0 KB

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