def test_map(self): c = DummyConnection(num=0, resp='foo') c2 = DummyConnection(num=1, resp='bar') # test dummy router r = DummyRouter p = Cluster( hosts={0: c, 1: c2}, router=r, ) with p.map() as conn: foo = conn.foo() bar = conn.foo('foo') self.assertEquals(foo, None) self.assertEquals(bar, None) self.assertEquals(bar, 'bar') self.assertEquals(foo, 'foo') # test default routing behavior p = Cluster( hosts={0: c, 1: c2}, ) with p.map() as conn: foo = conn.foo() bar = conn.foo('foo') self.assertEquals(foo, None) self.assertEquals(bar, None) self.assertEquals(foo, ['foo', 'bar']) self.assertEquals(bar, ['foo', 'bar'])
def test_disconnect(self): c = Mock() p = Cluster( hosts={0: c}, ) p.disconnect() c.disconnect.assert_called_once()
def test_map(self): c = DummyConnection(num=0, resp='foo') c2 = DummyConnection(num=1, resp='bar') # test dummy router r = DummyRouter() p = Cluster( hosts={ 0: c, 1: c2 }, router=r, ) with p.map() as conn: foo = conn.foo() bar = conn.foo('foo') self.assertEquals(foo, None) self.assertEquals(bar, None) self.assertEquals(bar, 'bar') self.assertEquals(foo, 'foo') # test default routing behavior p = Cluster(hosts={0: c, 1: c2}, ) with p.map() as conn: foo = conn.foo() bar = conn.foo('foo') self.assertEquals(foo, None) self.assertEquals(bar, None) self.assertEquals(foo, ['foo', 'bar']) self.assertEquals(bar, ['foo', 'bar'])
def test_get_conn(self): c = DummyConnection(alias='foo', num=0, resp='foo') c2 = DummyConnection(alias='foo', num=1, resp='bar') # test dummy router r = DummyRouter() p = Cluster( hosts={ 0: c, 1: c2 }, router=r, ) self.assertEquals(p.get_conn(), c) self.assertEquals(p.get_conn('foo'), c2) # test default routing behavior p = Cluster(hosts={0: c, 1: c2}, ) self.assertEquals(p.get_conn(), [c, c2]) self.assertEquals(p.get_conn('foo'), [c, c2])
def test_with_router(self): c = DummyConnection(num=0, resp='foo') c2 = DummyConnection(num=1, resp='bar') # test dummy router r = DummyRouter() p = Cluster( hosts={ 0: c, 1: c2 }, router=r, ) self.assertEquals(p.foo(), 'foo') self.assertEquals(p.foo('foo'), 'bar') # test default routing behavior p = Cluster(hosts={0: c, 1: c2}, ) self.assertEquals(p.foo(), ['foo', 'bar']) self.assertEquals(p.foo('foo'), ['foo', 'bar'])
def test_get_conn(self): c = DummyConnection(alias='foo', num=0, resp='foo') c2 = DummyConnection(alias='foo', num=1, resp='bar') # test dummy router r = DummyRouter p = Cluster( hosts={0: c, 1: c2}, router=r, ) self.assertEquals(p.get_conn(), c) self.assertEquals(p.get_conn('foo'), c2) # test default routing behavior p = Cluster( hosts={0: c, 1: c2}, ) self.assertEquals(p.get_conn(), [c, c2]) self.assertEquals(p.get_conn('foo'), [c, c2])
def test_with_router(self): c = DummyConnection(num=0, resp='foo') c2 = DummyConnection(num=1, resp='bar') # test dummy router r = DummyRouter p = Cluster( hosts={0: c, 1: c2}, router=r, ) self.assertEquals(p.foo(), 'foo') self.assertEquals(p.foo('foo'), 'bar') # test default routing behavior p = Cluster( hosts={0: c, 1: c2}, ) self.assertEquals(p.foo(), ['foo', 'bar']) self.assertEquals(p.foo('foo'), ['foo', 'bar'])
def test_proxy(self): c = DummyConnection(num=1, resp='bar') p = Cluster( hosts={0: c}, ) self.assertEquals(p.foo(), 'bar')
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 test_disconnect(self): c = Mock() p = Cluster(hosts={0: c}, ) p.disconnect() c.disconnect.assert_called_once()
def test_proxy(self): c = DummyConnection(num=1, resp='bar') p = Cluster(hosts={0: c}, ) self.assertEquals(p.foo(), 'bar')
def test_init(self): c = Cluster(hosts={0: BaseConnection(num=1)}, ) self.assertEquals(len(c), 1)
def test_with_cluster(self): p = Cluster( hosts={0: self.db}, ) cursor = p.execute('SELECT 1') self.assertEquals(cursor.fetchone(), (1,))
def test_with_cluster(self): p = Cluster(hosts={0: self.db}, ) cursor = p.execute('SELECT 1') self.assertEquals(cursor.fetchone(), (1, ))
def test_with_cluster(self): p = Cluster(hosts={0: self.redis}, ) self.assertEquals(p.incr('RedisTest_with_cluster'), 1)
def test_with_cluster(self): p = Cluster( hosts={0: self.redis}, ) self.assertEquals(p.incr('RedisTest_with_cluster'), 1)
def setUp(self): self.router = ConsistentHashingRouter() self.hosts = dict((i, DummyConnection(i)) for i in range(5)) self.cluster = Cluster(router=self.router, hosts=self.hosts)