MCPcopy
hub / github.com/segmentio/kafka-go / TestMurmur2

Function TestMurmur2

balancer_test.go:200–229  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

198}
199
200func TestMurmur2(t *testing.T) {
201 // These tests are taken from the "murmur2" implementation from
202 // https://github.com/edenhill/librdkafka/blob/master/src/rdmurmur2.c
203 testCases := []struct {
204 Key []byte
205 JavaMurmur2Result uint32
206 }{
207 {Key: []byte("kafka"), JavaMurmur2Result: 0xd067cf64},
208 {Key: []byte("giberish123456789"), JavaMurmur2Result: 0x8f552b0c},
209 {Key: []byte("1234"), JavaMurmur2Result: 0x9fc97b14},
210 {Key: []byte("234"), JavaMurmur2Result: 0xe7c009ca},
211 {Key: []byte("34"), JavaMurmur2Result: 0x873930da},
212 {Key: []byte("4"), JavaMurmur2Result: 0x5a4b5ca1},
213 {Key: []byte("PreAmbleWillBeRemoved,ThePrePartThatIs"), JavaMurmur2Result: 0x78424f1c},
214 {Key: []byte("reAmbleWillBeRemoved,ThePrePartThatIs"), JavaMurmur2Result: 0x4a62b377},
215 {Key: []byte("eAmbleWillBeRemoved,ThePrePartThatIs"), JavaMurmur2Result: 0xe0e4e09e},
216 {Key: []byte("AmbleWillBeRemoved,ThePrePartThatIs"), JavaMurmur2Result: 0x62b8b43f},
217 {Key: []byte(""), JavaMurmur2Result: 0x106e08d9},
218 {Key: nil, JavaMurmur2Result: 0x106e08d9},
219 }
220
221 for _, test := range testCases {
222 t.Run(fmt.Sprintf("key:%s", test.Key), func(t *testing.T) {
223 got := murmur2(test.Key)
224 if got != test.JavaMurmur2Result {
225 t.Errorf("expected %v; got %v", test.JavaMurmur2Result, got)
226 }
227 })
228 }
229}
230
231func TestMurmur2Balancer(t *testing.T) {
232 // These tests are taken from the "murmur2_random" partitioner from

Callers

nothing calls this directly

Calls 1

murmur2Function · 0.85

Tested by

no test coverage detected