def test_with_cluster(self, get): p = BaseCluster( backend=Memcache, hosts={0: {}}, ) result = p.get('MemcacheTest_with_cluster') get.assert_called_once_with('MemcacheTest_with_cluster') self.assertEqual(result, get.return_value)
def test_proxy(self): p = BaseCluster( backend=DummyConnection, hosts={0: { 'resp': 'bar' }}, ) self.assertEquals(p.foo(), 'bar')
def test_with_cluster(self): p = BaseCluster( backend=Redis, hosts={0: { 'db': 1 }}, ) self.assertEquals(p.incr('RedisTest_with_cluster'), 1)
def test_disconnect(self): c = mock.Mock() p = BaseCluster( backend=c, hosts={0: {'resp': 'bar'}}, ) p.disconnect() c.disconnect.assert_called_once()
def test_disconnect(self): c = mock.Mock() p = BaseCluster( backend=c, hosts={0: { 'resp': 'bar' }}, ) p.disconnect() c.disconnect.assert_called_once()
def test_default_routing_with_multiple_hosts(self): p = BaseCluster( backend=DummyConnection, hosts={ 0: {'resp': 'foo'}, 1: {'resp': 'bar'}, }, ) self.assertEqual(p.foo(), ['foo', 'bar']) self.assertEqual(p.foo('foo'), ['foo', 'bar'])
def test_get_conn_default_routing_with_multiple_hosts(self): # test default routing behavior p = BaseCluster( backend=DummyConnection, hosts={ 0: {'resp': 'foo'}, 1: {'resp': 'bar'}, }, ) self.assertEqual(list(map(lambda x: x.num, p.get_conn())), [0, 1]) self.assertEqual(list(map(lambda x: x.num, p.get_conn('foo'))), [0, 1])
def test_with_split_router(self): p = BaseCluster( router=DummyRouter, backend=DummyConnection, hosts={ 0: {'resp': 'foo'}, 1: {'resp': 'bar'}, }, ) self.assertEqual(p.foo(), 'foo') self.assertEqual(p.foo('foo'), 'bar')
def test_get_conn_with_split_router(self): # test dummy router p = BaseCluster( backend=DummyConnection, hosts={ 0: {'resp': 'foo'}, 1: {'resp': 'bar'}, }, router=DummyRouter, ) self.assertEqual(p.get_conn().num, 0) self.assertEqual(p.get_conn('foo').num, 1)
def test_default_routing_with_multiple_hosts(self): p = BaseCluster( backend=DummyConnection, hosts={ 0: { 'resp': 'foo' }, 1: { 'resp': 'bar' }, }, ) self.assertEquals(p.foo(), ['foo', 'bar']) self.assertEquals(p.foo('foo'), ['foo', 'bar'])
def test_with_split_router(self): p = BaseCluster( router=DummyRouter, backend=DummyConnection, hosts={ 0: { 'resp': 'foo' }, 1: { 'resp': 'bar' }, }, ) self.assertEquals(p.foo(), 'foo') self.assertEquals(p.foo('foo'), 'bar')
def test_get_conn_default_routing_with_multiple_hosts(self): # test default routing behavior p = BaseCluster( backend=DummyConnection, hosts={ 0: { 'resp': 'foo' }, 1: { 'resp': 'bar' }, }, ) self.assertEquals(map(lambda x: x.num, p.get_conn()), [0, 1]) self.assertEquals(map(lambda x: x.num, p.get_conn('foo')), [0, 1])
def test_get_conn_with_split_router(self): # test dummy router p = BaseCluster( backend=DummyConnection, hosts={ 0: { 'resp': 'foo' }, 1: { 'resp': 'bar' }, }, router=DummyRouter, ) self.assertEquals(p.get_conn().num, 0) self.assertEquals(p.get_conn('foo').num, 1)
def cluster(self): return BaseCluster( backend=DummyConnection, hosts={ 0: { 'resp': 'foo' }, 1: { 'resp': 'bar' }, }, )
def cluster(self): return BaseCluster( backend=DummyErroringConnection, hosts={ 0: { 'resp': 'foo' }, 1: { 'resp': 'error' }, }, router=DummyRouter, )
def test_len_returns_num_backends(self): p = BaseCluster( backend=BaseConnection, hosts={0: {}}, ) self.assertEquals(len(p), 1)
def test_proxy(self): p = BaseCluster( backend=DummyConnection, hosts={0: {'resp': 'bar'}}, ) self.assertEqual(p.foo(), 'bar')
def test_with_cluster(self): p = BaseCluster( hosts={0: self.redis}, ) self.assertEquals(p.incr('RedisTest_with_cluster'), 1)
def test_with_cluster(self): p = BaseCluster( backend=Redis, hosts={0: {'db': 1}}, ) self.assertEquals(p.incr('RedisTest_with_cluster'), 1)
def setUp(self): self.hosts = dict((i, {}) for i in xrange(5)) self.cluster = BaseCluster(router=self.Router, hosts=self.hosts, backend=DummyConnection) self.router = self.cluster.router
def test_with_cluster(self): p = BaseCluster(hosts={0: self.memcache}) self.assertEquals(p.get('MemcacheTest_with_cluster'), None)