| 229 | } |
| 230 | |
| 231 | func TestMurmur2Balancer(t *testing.T) { |
| 232 | // These tests are taken from the "murmur2_random" partitioner from |
| 233 | // https://github.com/edenhill/librdkafka/blob/master/tests/0048-partitioner.c |
| 234 | partitionCount := 17 |
| 235 | librdkafkaPartitions := make([]int, partitionCount) |
| 236 | for i := 0; i < partitionCount; i++ { |
| 237 | librdkafkaPartitions[i] = i * i |
| 238 | } |
| 239 | |
| 240 | // These tests are taken from the Murmur2Partitioner Python class from |
| 241 | // https://github.com/dpkp/kafka-python/blob/master/test/test_partitioner.py |
| 242 | pythonPartitions := make([]int, 1000) |
| 243 | for i := 0; i < 1000; i++ { |
| 244 | pythonPartitions[i] = i |
| 245 | } |
| 246 | |
| 247 | testCases := map[string]struct { |
| 248 | Key []byte |
| 249 | Partitions []int |
| 250 | Partition int |
| 251 | }{ |
| 252 | "librdkafka-nil": { |
| 253 | Key: nil, |
| 254 | Partitions: librdkafkaPartitions, |
| 255 | Partition: 123, |
| 256 | }, |
| 257 | "librdkafka-empty": { |
| 258 | Key: []byte{}, |
| 259 | Partitions: librdkafkaPartitions, |
| 260 | Partition: librdkafkaPartitions[0x106e08d9%partitionCount], |
| 261 | }, |
| 262 | "librdkafka-unaligned": { |
| 263 | Key: []byte("23456"), |
| 264 | Partitions: librdkafkaPartitions, |
| 265 | Partition: librdkafkaPartitions[0x058d780f%partitionCount], |
| 266 | }, |
| 267 | "librdkafka-long key": { |
| 268 | Key: []byte("this is another string with more length to it perhaps"), |
| 269 | Partitions: librdkafkaPartitions, |
| 270 | Partition: librdkafkaPartitions[0x4f7703da%partitionCount], |
| 271 | }, |
| 272 | "librdkafka-short key": { |
| 273 | Key: []byte("hejsan"), |
| 274 | Partitions: librdkafkaPartitions, |
| 275 | Partition: librdkafkaPartitions[0x5ec19395%partitionCount], |
| 276 | }, |
| 277 | "python-empty": { |
| 278 | Key: []byte(""), |
| 279 | Partitions: pythonPartitions, |
| 280 | Partition: 681, |
| 281 | }, |
| 282 | "python-a": { |
| 283 | Key: []byte("a"), |
| 284 | Partitions: pythonPartitions, |
| 285 | Partition: 524, |
| 286 | }, |
| 287 | "python-ab": { |
| 288 | Key: []byte("ab"), |