create_partitions_request_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package sarama
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. var (
  7. createPartitionRequestNoAssignment = []byte{
  8. 0, 0, 0, 1, // one topic
  9. 0, 5, 't', 'o', 'p', 'i', 'c',
  10. 0, 0, 0, 3, // 3 partitions
  11. 255, 255, 255, 255, // no assignments
  12. 0, 0, 0, 100, // timeout
  13. 0, // validate only = false
  14. }
  15. createPartitionRequestAssignment = []byte{
  16. 0, 0, 0, 1,
  17. 0, 5, 't', 'o', 'p', 'i', 'c',
  18. 0, 0, 0, 3, // 3 partitions
  19. 0, 0, 0, 2,
  20. 0, 0, 0, 2,
  21. 0, 0, 0, 2, 0, 0, 0, 3,
  22. 0, 0, 0, 2,
  23. 0, 0, 0, 3, 0, 0, 0, 1,
  24. 0, 0, 0, 100,
  25. 1, // validate only = true
  26. }
  27. )
  28. func TestCreatePartitionsRequest(t *testing.T) {
  29. req := &CreatePartitionsRequest{
  30. TopicPartitions: map[string]*TopicPartition{
  31. "topic": {
  32. Count: 3,
  33. },
  34. },
  35. Timeout: 100 * time.Millisecond,
  36. }
  37. buf := testRequestEncode(t, "no assignment", req, createPartitionRequestNoAssignment)
  38. testRequestDecode(t, "no assignment", req, buf)
  39. req.ValidateOnly = true
  40. req.TopicPartitions["topic"].Assignment = [][]int32{{2, 3}, {3, 1}}
  41. buf = testRequestEncode(t, "assignment", req, createPartitionRequestAssignment)
  42. testRequestDecode(t, "assignment", req, buf)
  43. }