sticky_assignor_user_data_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package sarama
  2. import (
  3. "encoding/base64"
  4. "testing"
  5. )
  6. func TestStickyAssignorUserDataV0(t *testing.T) {
  7. // Single topic with deterministic ordering across encode-decode
  8. req := &StickyAssignorUserDataV0{}
  9. data := decodeUserDataBytes(t, "AAAAAQADdDAzAAAAAQAAAAU=")
  10. testDecodable(t, "", req, data)
  11. testEncodable(t, "", req, data)
  12. // Multiple partitions
  13. req = &StickyAssignorUserDataV0{}
  14. data = decodeUserDataBytes(t, "AAAAAQADdDE4AAAAEgAAAAAAAAABAAAAAgAAAAMAAAAEAAAABQAAAAYAAAAHAAAACAAAAAkAAAAKAAAACwAAAAwAAAANAAAADgAAAA8AAAAQAAAAEQ==")
  15. testDecodable(t, "", req, data)
  16. // Multiple topics and partitions
  17. req = &StickyAssignorUserDataV0{}
  18. data = decodeUserDataBytes(t, "AAAABQADdDEyAAAAAgAAAAIAAAAKAAN0MTEAAAABAAAABAADdDE0AAAAAQAAAAgAA3QxMwAAAAEAAAANAAN0MDkAAAABAAAABQ==")
  19. testDecodable(t, "", req, data)
  20. }
  21. func TestStickyAssignorUserDataV1(t *testing.T) {
  22. // Single topic with deterministic ordering across encode-decode
  23. req := &StickyAssignorUserDataV1{}
  24. data := decodeUserDataBytes(t, "AAAAAQADdDA2AAAAAgAAAAAAAAAE/////w==")
  25. testDecodable(t, "", req, data)
  26. testEncodable(t, "", req, data)
  27. // Multiple topics and partitions
  28. req = &StickyAssignorUserDataV1{}
  29. data = decodeUserDataBytes(t, "AAAABgADdDEwAAAAAgAAAAIAAAAJAAN0MTIAAAACAAAAAwAAAAsAA3QxNAAAAAEAAAAEAAN0MTMAAAABAAAACwADdDE1AAAAAQAAAAwAA3QwOQAAAAEAAAAG/////w==")
  30. testDecodable(t, "", req, data)
  31. // Generation is populated
  32. req = &StickyAssignorUserDataV1{}
  33. data = decodeUserDataBytes(t, "AAAAAQAHdG9waWMwMQAAAAMAAAAAAAAAAQAAAAIAAAAB")
  34. testDecodable(t, "", req, data)
  35. }
  36. func decodeUserDataBytes(t *testing.T, base64Data string) []byte {
  37. data, err := base64.StdEncoding.DecodeString(base64Data)
  38. if err != nil {
  39. t.Errorf("Error decoding data: %v", err)
  40. t.FailNow()
  41. }
  42. return data
  43. }