create_topics_request_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package sarama
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. var (
  7. createTopicsRequestV0 = []byte{
  8. 0, 0, 0, 1,
  9. 0, 5, 't', 'o', 'p', 'i', 'c',
  10. 255, 255, 255, 255,
  11. 255, 255,
  12. 0, 0, 0, 1, // 1 replica assignment
  13. 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2,
  14. 0, 0, 0, 1, // 1 config
  15. 0, 12, 'r', 'e', 't', 'e', 'n', 't', 'i', 'o', 'n', '.', 'm', 's',
  16. 0, 2, '-', '1',
  17. 0, 0, 0, 100,
  18. }
  19. createTopicsRequestV1 = append(createTopicsRequestV0, byte(1))
  20. )
  21. func TestCreateTopicsRequest(t *testing.T) {
  22. retention := "-1"
  23. req := &CreateTopicsRequest{
  24. TopicDetails: map[string]*TopicDetail{
  25. "topic": {
  26. NumPartitions: -1,
  27. ReplicationFactor: -1,
  28. ReplicaAssignment: map[int32][]int32{
  29. 0: {0, 1, 2},
  30. },
  31. ConfigEntries: map[string]*string{
  32. "retention.ms": &retention,
  33. },
  34. },
  35. },
  36. Timeout: 100 * time.Millisecond,
  37. }
  38. testRequest(t, "version 0", req, createTopicsRequestV0)
  39. req.Version = 1
  40. req.ValidateOnly = true
  41. testRequest(t, "version 1", req, createTopicsRequestV1)
  42. }