package event import "testing" func TestPartitionOf_DeterministicInRange(t *testing.T) { const n = 16 for _, key := range []string{"0", "1", "42", "9007199254740993", "sendA", "list-7"} { first := PartitionOf(key, n) if first < 0 || first >= n { t.Fatalf("PartitionOf(%q, %d) = %d, out of range", key, n, first) } if again := PartitionOf(key, n); again != first { t.Fatalf("PartitionOf(%q, %d) not deterministic: %d vs %d", key, n, first, again) } } } func TestPartitionOf_SameKeySamePartition(t *testing.T) { // A session's sessionId must pin every beacon to one partition (per-session // FIFO): the same key always hashes to the same partition across callers. if PartitionOf("123456789", 32) != PartitionOf("123456789", 32) { t.Fatal("same key mapped to different partitions") } } func TestPartitionOf_SinglePartition(t *testing.T) { if PartitionOf("anything", 1) != 0 || PartitionOf("anything", 0) != 0 { t.Fatal("n <= 1 must collapse to partition 0") } } func TestPartitionRoutingKey(t *testing.T) { if got := PartitionRoutingKey(7); got != "track.partition.7" { t.Fatalf("PartitionRoutingKey(7) = %q", got) } }