MCPcopy
hub / github.com/IBM/sarama / TestNewHashPartitionerWithHasher

Function TestNewHashPartitionerWithHasher

partitioner_test.go:100–129  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

98}
99
100func 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
131func TestHashPartitionerWithHasherMinInt32(t *testing.T) {
132 // use the current default hasher fnv.New32a()

Callers

nothing calls this directly

Calls 6

NewCustomHashPartitionerFunction · 0.85
ByteEncoderTypeAlias · 0.85
ReadMethod · 0.80
PartitionMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected