offset_commit_request_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 TestOffsetCommitRequest(t *testing.T) {
  50. request := new(OffsetCommitRequest)
  51. request.ConsumerGroup = "foobar"
  52. testEncodable(t, "no blocks v0", request, offsetCommitRequestNoBlocksV0)
  53. request.ConsumerGroupGeneration = 0x1122
  54. request.ConsumerID = "cons"
  55. request.Version = 1
  56. testEncodable(t, "no blocks v1", request, offsetCommitRequestNoBlocksV1)
  57. request.RetentionTime = 0x4433
  58. request.Version = 2
  59. testEncodable(t, "no blocks v2", request, offsetCommitRequestNoBlocksV2)
  60. request.AddBlock("topic", 0x5221, 0xDEADBEEF, ReceiveTime, "metadata")
  61. request.Version = 0
  62. testEncodable(t, "one block v0", request, offsetCommitRequestOneBlockV0)
  63. request.Version = 1
  64. testEncodable(t, "one block v1", request, offsetCommitRequestOneBlockV1)
  65. request.Version = 2
  66. testEncodable(t, "one block v2", request, offsetCommitRequestOneBlockV2)
  67. }