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 = Dingus() p = Cluster( hosts={0: c}, ) p.disconnect() calls = dingus_calls_to_dict(c.calls) self.assertTrue('disconnect' in calls)
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_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_proxy(self): c = DummyConnection(num=1, resp="bar") p = Cluster(hosts={0: c}) self.assertEquals(p.foo(), "bar")