| 320 | } |
| 321 | |
| 322 | func TestMurmur2(t *testing.T) { |
| 323 | // expected values verified against the Apache Kafka Java client's |
| 324 | // org.apache.kafka.common.utils.Utils.murmur2() implementation |
| 325 | testCases := []struct { |
| 326 | input string |
| 327 | expected uint32 |
| 328 | }{ |
| 329 | {"foo", 597841616}, |
| 330 | {"bar", 988958145}, |
| 331 | {"baz", 1973573280}, |
| 332 | {"", 275646681}, |
| 333 | {"kafka", 3496464228}, |
| 334 | {"sarama", 770765511}, |
| 335 | } |
| 336 | for _, tc := range testCases { |
| 337 | t.Run(fmt.Sprintf("input=%q", tc.input), func(t *testing.T) { |
| 338 | got := murmur2([]byte(tc.input)) |
| 339 | if got != tc.expected { |
| 340 | t.Errorf("murmur2(%q) = %d, want %d", tc.input, got, tc.expected) |
| 341 | } |
| 342 | }) |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | func TestMurmur2Partitioner(t *testing.T) { |
| 347 | partitioner := NewMurmur2Partitioner("mytopic") |