partitioner_test.go 794 B

1234567891011121314151617181920212223242526272829303132333435
  1. package sarama
  2. import "testing"
  3. func TestRandomPartitioner(t *testing.T) {
  4. partitioner := RandomPartitioner{}
  5. choice := partitioner.Partition(nil, 1)
  6. if choice != 0 {
  7. t.Error("Returned non-zero partition when only one available.")
  8. }
  9. for i := 1; i < 50; i++ {
  10. choice := partitioner.Partition(nil, 50)
  11. if choice < 0 || choice >= 50 {
  12. t.Fatal("Returned partition", choice, "outside of range.")
  13. }
  14. }
  15. }
  16. func TestRoundRobinPartitioner(t *testing.T) {
  17. partitioner := RoundRobinPartitioner{}
  18. choice := partitioner.Partition(nil, 1)
  19. if choice != 0 {
  20. t.Error("Returned non-zero partition when only one available.")
  21. }
  22. for i := 1; i < 50; i++ {
  23. choice := partitioner.Partition(nil, 7)
  24. if choice != i%7 {
  25. t.Fatal("Returned partition", choice, "expecting", i%7)
  26. }
  27. }
  28. }