Beispiel #1
0
def test_host_validation():
    cluster = Cluster(hosts={1: {}})
    try:
        cluster.get_router()
    except BadHostSetup as e:
        assert 'Expected host with ID "0"' in str(e)
    else:
        raise Exception('Expected runtime error')
Beispiel #2
0
def test_host_validation():
    cluster = Cluster(hosts={
        1: {}
    })
    try:
        cluster.get_router()
    except BadHostSetup as e:
        assert 'Expected host with ID "0"' in str(e)
    else:
        raise Exception('Expected runtime error')
Beispiel #3
0
def test_router_basics():
    cluster = Cluster({0: {"db": 0}, 1: {"db": 1}, 2: {"db": 2},})

    router = cluster.get_router()
    assert router.get_host_for_command("INCR", ["foo"]) == 1
    assert router.get_host_for_command("INCR", ["bar"]) == 2
    assert router.get_host_for_command("INCR", ["baz"]) == 0

    assert router.get_host_for_key("foo") == 1
    assert router.get_host_for_key("bar") == 2
    assert router.get_host_for_key("baz") == 0
Beispiel #4
0
def test_router_key_routing():
    cluster = Cluster({0: {"db": 0},})

    router = cluster.get_router()
    assert router.get_key("INCR", ["foo"]) == "foo"
    assert router.get_key("GET", ["bar"]) == "bar"

    with pytest.raises(UnroutableCommand):
        router.get_key("MGET", ["foo", "bar", "baz"])

    with pytest.raises(UnroutableCommand):
        router.get_key("UNKNOWN", [])
Beispiel #5
0
def test_router_key_routing():
    cluster = Cluster({
        0: {'db': 0},
    })

    router = cluster.get_router()
    assert router.get_key('INCR', ['foo']) == 'foo'
    assert router.get_key('GET', ['bar']) == 'bar'

    with pytest.raises(UnroutableCommand):
        router.get_key('MGET', ['foo', 'bar', 'baz'])

    with pytest.raises(UnroutableCommand):
        router.get_key('UNKNOWN', [])
Beispiel #6
0
def test_router_basics():
    cluster = Cluster({
        0: {'db': 0},
        1: {'db': 1},
        2: {'db': 2},
    })

    router = cluster.get_router()
    assert router.get_host_for_command('INCR', ['foo']) == 1
    assert router.get_host_for_command('INCR', ['bar']) == 2
    assert router.get_host_for_command('INCR', ['baz']) == 0

    assert router.get_host_for_key('foo') == 1
    assert router.get_host_for_key('bar') == 2
    assert router.get_host_for_key('baz') == 0
Beispiel #7
0
def test_router_key_routing():
    cluster = Cluster({
        0: {
            'db': 0
        },
    })

    router = cluster.get_router()
    assert router.get_key('INCR', ['foo']) == 'foo'
    assert router.get_key('GET', ['bar']) == 'bar'

    with pytest.raises(UnroutableCommand):
        router.get_key('MGET', ['foo', 'bar', 'baz'])

    with pytest.raises(UnroutableCommand):
        router.get_key('UNKNOWN', [])
Beispiel #8
0
def test_basic_interface():
    cluster = Cluster({
        0: {
            'db': 0
        },
        1: {
            'db': 2
        },
        2: {
            'db': 4,
            'host': '127.0.0.1'
        },
    })

    assert len(cluster.hosts) == 3

    assert cluster.hosts[0].host_id == 0
    assert cluster.hosts[0].db == 0
    assert cluster.hosts[0].host == 'localhost'
    assert cluster.hosts[0].port == 6379

    assert cluster.hosts[1].host_id == 1
    assert cluster.hosts[1].db == 2
    assert cluster.hosts[1].host == 'localhost'
    assert cluster.hosts[1].port == 6379

    assert cluster.hosts[2].host_id == 2
    assert cluster.hosts[2].db == 4
    assert cluster.hosts[2].host == '127.0.0.1'
    assert cluster.hosts[2].port == 6379
Beispiel #9
0
def test_router_basics():
    cluster = Cluster({
        0: {
            'db': 0
        },
        1: {
            'db': 1
        },
        2: {
            'db': 2
        },
    })

    router = cluster.get_router()
    assert router.get_host_for_command('INCR', ['foo']) == 1
    assert router.get_host_for_command('INCR', ['bar']) == 2
    assert router.get_host_for_command('INCR', ['baz']) == 0

    assert router.get_host_for_key('foo') == 1
    assert router.get_host_for_key('bar') == 2
    assert router.get_host_for_key('baz') == 0
Beispiel #10
0
def test_router_access():
    cluster = Cluster({
        0: {'db': 0},
    })

    router = cluster.get_router()
    assert router.cluster is cluster
    assert cluster.get_router() is router

    cluster.add_host(1, {'db': 1})
    new_router = cluster.get_router()
    assert new_router is not router
Beispiel #11
0
def test_router_access():
    cluster = Cluster({0: {"db": 0}})

    router = cluster.get_router()
    assert router.cluster is cluster
    assert cluster.get_router() is router

    cluster.add_host(1, {"db": 1})
    new_router = cluster.get_router()
    assert new_router is not router
Beispiel #12
0
 def make_cluster(self):
     """Creates a correctly configured cluster from the servers
     spawned.  This also automatically waits for the servers to be up.
     """
     self.wait_for_servers()
     hosts = []
     host_id = 0
     for server in self.servers:
         for x in range(self.databases_each):
             hosts.append({
                 "host_id": host_id,
                 "unix_socket_path": server.socket_path,
                 "db": x,
             })
             host_id += 1
     return Cluster(hosts)
Beispiel #13
0
def test_router_access():
    cluster = Cluster({
        0: {
            "db": 0
        },
    },
                      pool_options={
                          "encoding": "utf-8",
                          "decode_responses": True
                      })

    router = cluster.get_router()
    assert router.cluster is cluster
    assert cluster.get_router() is router

    cluster.add_host(1, {"db": 1})
    new_router = cluster.get_router()
    assert new_router is not router
Beispiel #14
0
def test_basic_interface():
    cluster = Cluster(
        {
            0: {
                "db": 0
            },
            1: {
                "db": 2
            },
            2: {
                "db": 4,
                "host": "127.0.0.1"
            },
        },
        host_defaults={
            "password": "******",
        },
        pool_options={
            "encoding": "utf-8",
            "decode_responses": True
        },
    )

    assert len(cluster.hosts) == 3

    assert cluster.hosts[0].host_id == 0
    assert cluster.hosts[0].db == 0
    assert cluster.hosts[0].host == "localhost"
    assert cluster.hosts[0].port == 6379
    assert cluster.hosts[0].password == "pass"

    assert cluster.hosts[1].host_id == 1
    assert cluster.hosts[1].db == 2
    assert cluster.hosts[1].host == "localhost"
    assert cluster.hosts[1].port == 6379
    assert cluster.hosts[1].password == "pass"

    assert cluster.hosts[2].host_id == 2
    assert cluster.hosts[2].db == 4
    assert cluster.hosts[2].host == "127.0.0.1"
    assert cluster.hosts[2].port == 6379
    assert cluster.hosts[2].password == "pass"
Beispiel #15
0
def test_basic_interface():
    cluster = Cluster(
        {
            0: {
                "db": 0
            },
            1: {
                "db": 2
            },
            2: {
                "db": 4,
                "host": "127.0.0.1"
            },
        },
        host_defaults={
            "password": "******",
        },
    )

    assert len(cluster.hosts) == 3

    assert cluster.hosts[0].host_id == 0
    assert cluster.hosts[0].db == 0
    assert cluster.hosts[0].host == "localhost"
    assert cluster.hosts[0].port == 6379
    assert cluster.hosts[0].password == "pass"

    assert cluster.hosts[1].host_id == 1
    assert cluster.hosts[1].db == 2
    assert cluster.hosts[1].host == "localhost"
    assert cluster.hosts[1].port == 6379
    assert cluster.hosts[1].password == "pass"

    assert cluster.hosts[2].host_id == 2
    assert cluster.hosts[2].db == 4
    assert cluster.hosts[2].host == "127.0.0.1"
    assert cluster.hosts[2].port == 6379
    assert cluster.hosts[2].password == "pass"