Skip to content

Instantly share code, notes, and snippets.

@WrathOfChris
Created November 2, 2014 16:25
Show Gist options
  • Save WrathOfChris/bb434a3f0115b843f1f8 to your computer and use it in GitHub Desktop.
Save WrathOfChris/bb434a3f0115b843f1f8 to your computer and use it in GitHub Desktop.
quick test of carbon ConsistentHashingRouter order
#!/usr/local/bin/python
import carbon.routers
from pprint import pprint
import string
import random
this = carbon.routers.ConsistentHashingRouter()
this.addDestination(("4.4.4.4", 2003, 1))
this.addDestination(("3.3.3.3", 2003, 1))
this.addDestination(("2.2.2.2", 2003, 1))
this.addDestination(("1.1.1.1", 2003, 1))
this.addDestination(("::1", 2003, 1))
this.addDestination(("unresolvedhostname", 2003, 1))
that = carbon.routers.ConsistentHashingRouter()
that.addDestination(("unresolvedhostname", 2003, 1))
that.addDestination(("::1", 2003, 1))
that.addDestination(("1.1.1.1", 2003, 1))
that.addDestination(("2.2.2.2", 2003, 1))
that.addDestination(("3.3.3.3", 2003, 1))
that.addDestination(("4.4.4.4", 2003, 1))
def str_gen(size=4, chars=string.ascii_lowercase):
return ''.join(random.choice(chars) for _ in range(size))
for n in range(100):
metric = str_gen()
for server, port, instance in this.getDestinations(metric):
thishost = server
for server, port, instance in that.getDestinations(metric):
thathost = server
if thishost != thathost:
print "failed %s != %s" % (thishost, thathost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment