mirror of
https://github.com/turnstonelabs/turnstone.git
synced 2026-08-27 14:24:47 -06:00
0cfe521ce7
Move the consistent hash ring implementation (FNV-1a, virtual nodes, bisect lookup) from code to docs/design/consistent-hash-ring.md as a forward-looking reference for future scalability work. The current rebalancer uses weight-proportional distribution (simpler, exact splits, no hash variance). The ring algorithm is documented with test vectors, stability properties, and a comparison table for when the ring approach becomes advantageous (large clusters, decentralized routing, cross-language determinism). hash_ring.py retains: RING_SIZE, bucket_of(), RingNode, NoAvailableNodeError (all actively used by router and rebalancer).
16 lines
512 B
Python
16 lines
512 B
Python
"""Tests for turnstone.core.hash_ring."""
|
|
|
|
from turnstone.core.hash_ring import bucket_of
|
|
|
|
|
|
class TestBucketOf:
|
|
def test_known_vectors(self):
|
|
assert bucket_of("a3f1" + "0" * 28) == 0xA3F1
|
|
assert bucket_of("0000" + "a" * 28) == 0
|
|
assert bucket_of("ffff" + "b" * 28) == 65535
|
|
|
|
def test_hex_prefix(self):
|
|
# Only the first 4 hex chars matter — the rest is ignored.
|
|
assert bucket_of("abcd0000") == bucket_of("abcdffff")
|
|
assert bucket_of("abcd0000") == 0xABCD
|