示例#1
0
    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'])
示例#2
0
 def test_disconnect(self):
     c = Mock()
     p = Cluster(
         hosts={0: c},
     )
     p.disconnect()
     c.disconnect.assert_called_once()
示例#3
0
    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'])
示例#4
0
    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])
示例#5
0
    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'])
示例#6
0
    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])
示例#7
0
    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'])
示例#8
0
 def test_proxy(self):
     c = DummyConnection(num=1, resp='bar')
     p = Cluster(
         hosts={0: c},
     )
     self.assertEquals(p.foo(), 'bar')
示例#9
0
文件: tests.py 项目: diorahman/nydus
 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)
示例#10
0
 def test_disconnect(self):
     c = Mock()
     p = Cluster(hosts={0: c}, )
     p.disconnect()
     c.disconnect.assert_called_once()
示例#11
0
 def test_proxy(self):
     c = DummyConnection(num=1, resp='bar')
     p = Cluster(hosts={0: c}, )
     self.assertEquals(p.foo(), 'bar')
示例#12
0
 def test_init(self):
     c = Cluster(hosts={0: BaseConnection(num=1)}, )
     self.assertEquals(len(c), 1)
示例#13
0
文件: tests.py 项目: diorahman/nydus
 def test_with_cluster(self):
     p = Cluster(
         hosts={0: self.db},
     )
     cursor = p.execute('SELECT 1')
     self.assertEquals(cursor.fetchone(), (1,))
示例#14
0
 def test_with_cluster(self):
     p = Cluster(hosts={0: self.db}, )
     cursor = p.execute('SELECT 1')
     self.assertEquals(cursor.fetchone(), (1, ))
示例#15
0
文件: tests.py 项目: diorahman/nydus
 def test_with_cluster(self):
     p = Cluster(hosts={0: self.redis}, )
     self.assertEquals(p.incr('RedisTest_with_cluster'), 1)
示例#16
0
 def test_with_cluster(self):
     p = Cluster(
         hosts={0: self.redis},
     )
     self.assertEquals(p.incr('RedisTest_with_cluster'), 1)
示例#17
0
文件: tests.py 项目: diorahman/nydus
 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)