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

Function TestCustomPartitionerWithConsistentHashing

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

Source from the content-addressed store, hash-verified

246}
247
248func TestCustomPartitionerWithConsistentHashing(t *testing.T) {
249 // Setting both `hashUnsigned` and the hash function to `crc32.NewIEEE` is equivalent to using `NewConsistentCRCHashPartitioner`
250 partitioner := NewCustomPartitioner(
251 WithHashUnsigned(),
252 WithCustomHashFunction(crc32.NewIEEE),
253 )("mytopic")
254
255 // See above re: why `SheetJS`
256 msg := ProducerMessage{
257 Key: StringEncoder("SheetJS"),
258 }
259
260 choice, err := partitioner.Partition(&msg, 100)
261 if err != nil {
262 t.Error(partitioner, err)
263 }
264 expectedPartition := int32(26)
265 if choice != expectedPartition {
266 t.Error(partitioner, "returned partition", choice, "but expected", expectedPartition, ".")
267 }
268}
269
270func TestManualPartitioner(t *testing.T) {
271 partitioner := NewManualPartitioner("mytopic")

Callers

nothing calls this directly

Calls 6

NewCustomPartitionerFunction · 0.85
WithHashUnsignedFunction · 0.85
WithCustomHashFunctionFunction · 0.85
StringEncoderTypeAlias · 0.85
PartitionMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected