Ejemplo n.º 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')
Ejemplo n.º 2
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
Ejemplo n.º 3
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')
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 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
Ejemplo n.º 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", [])
Ejemplo n.º 8
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', [])
Ejemplo n.º 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
Ejemplo n.º 10
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', [])
Ejemplo n.º 11
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