(t *testing.T)
| 98 | } |
| 99 | |
| 100 | func TestNewHashPartitionerWithHasher(t *testing.T) { |
| 101 | // use the current default hasher fnv.New32a() |
| 102 | partitioner := NewCustomHashPartitioner(fnv.New32a)("mytopic") |
| 103 | |
| 104 | choice, err := partitioner.Partition(&ProducerMessage{}, 1) |
| 105 | if err != nil { |
| 106 | t.Error(partitioner, err) |
| 107 | } |
| 108 | if choice != 0 { |
| 109 | t.Error("Returned non-zero partition when only one available.") |
| 110 | } |
| 111 | |
| 112 | for i := 1; i < 50; i++ { |
| 113 | choice, err := partitioner.Partition(&ProducerMessage{}, 50) |
| 114 | if err != nil { |
| 115 | t.Error(partitioner, err) |
| 116 | } |
| 117 | if choice < 0 || choice >= 50 { |
| 118 | t.Error("Returned partition", choice, "outside of range for nil key.") |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | buf := make([]byte, 256) |
| 123 | for i := 1; i < 50; i++ { |
| 124 | if _, err := rand.Read(buf); err != nil { |
| 125 | t.Error(err) |
| 126 | } |
| 127 | assertPartitioningConsistent(t, partitioner, &ProducerMessage{Key: ByteEncoder(buf)}, 50) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | func TestHashPartitionerWithHasherMinInt32(t *testing.T) { |
| 132 | // use the current default hasher fnv.New32a() |
nothing calls this directly
no test coverage detected