class RoundRobinTest(BaseTest): def setUp(self): self.router = RoundRobinRouter() self.hosts = dict((i, DummyConnection(i)) for i in range(5)) self.cluster = Cluster(router=self.router, hosts=self.hosts) def get_db(self, *args, **kwargs): kwargs.setdefault('cluster', self.cluster) return self.router.get_db(*args, **kwargs) def test_cluster_of_zero_returns_zero(self): self.cluster.hosts = dict() self.assertEquals([], self.get_db()) def test_cluster_of_one_returns_one(self): self.cluster.hosts = {0: DummyConnection('foo')} self.assertEquals([0], self.get_db()) def test_multi_node_cluster_returns_correct_host(self): self.cluster.hosts = { 0: DummyConnection('foo'), 1: DummyConnection('bar') } self.assertEquals([[0], [1], [0], [1]], [ self.get_db(), self.get_db(), self.get_db(), self.get_db(), ])
class RoundRobinRouterTest(BaseTest): def setUp(self): self.router = RoundRobinRouter() self.hosts = dict((i, DummyConnection(i)) for i in range(5)) self.cluster = Cluster(router=self.router, hosts=self.hosts) def get_db(self, *args, **kwargs): kwargs.setdefault('cluster', self.cluster) return self.router.get_db(*args, **kwargs)
class RoundRobinTest(BaseTest): def setUp(self): self.router = RoundRobinRouter() self.hosts = dict((i, DummyConnection(i)) for i in range(5)) self.cluster = Cluster(router=self.router, hosts=self.hosts) def get_db(self, *args, **kwargs): kwargs.setdefault('cluster', self.cluster) return self.router.get_db(*args, **kwargs) def test_cluster_of_zero_returns_zero(self): self.cluster.hosts = dict() self.assertEquals([], self.get_db()) def test_cluster_of_one_returns_one(self): self.cluster.hosts = {0: DummyConnection('foo')} self.assertEquals([0], self.get_db()) def test_multi_node_cluster_returns_correct_host(self): self.cluster.hosts = {0: DummyConnection('foo'), 1: DummyConnection('bar')} self.assertEquals([[0], [1], [0], [1]], [self.get_db(), self.get_db(), self.get_db(), self.get_db(), ])