コード例 #1
0
ファイル: test_multi.py プロジェクト: aubustou/tribun
def test_multi_delete(
    consul: Consul,
    is_large_set: bool,
    large_key_set: List[Key],
    configuration_keys: List[Key],
    key_set_size: int,
):
    if is_large_set:
        key_set = large_key_set
    else:
        key_set = configuration_keys

    multi_put(consul, key_set)
    multi_delete(consul, key_set)

    assert not multi_get(consul, key_set)

    multi_put(consul, key_set)
    deleted_index = random.randrange(0, len(key_set))
    multi_delete(consul, [key_set[deleted_index]])
    assert not set(multi_get(consul, key_set)) & {key_set[deleted_index]}
    multi_delete(consul, key_set)

    if is_large_set:
        left = key_set_size // 3
        multi_delete(consul, key_set[left:key_set_size])
        assert not set(multi_get(consul, key_set)) & set(
            key_set[left:key_set_size])
コード例 #2
0
def run(
    keys: List[Key],
    exist_ok: bool = False,
):
    consul = Consul()

    if not exist_ok and multi_get(consul, keys):
        raise TribunError("Existing keys")
コード例 #3
0
def put(keys: List[Key]) -> List[Key]:
    full_keys = get_full_keys(keys)

    unalterable_keys = [x for x in full_keys if not x.alterable]
    if unalterable_keys:
        found_keys = multi_get(consul, unalterable_keys)
        if found_keys:
            raise TribunError("Keys could not be modified")

    multi_put(consul, full_keys)

    return full_keys
コード例 #4
0
ファイル: test_multi.py プロジェクト: aubustou/tribun
def test_multi_get(
    consul: Consul,
    is_large_set: bool,
    large_key_set: List[Key],
    configuration_keys: List[Key],
):
    if is_large_set:
        key_set = large_key_set
    else:
        key_set = configuration_keys

    assert not multi_get(consul, key_set)

    returned_keys = key_set.copy()
    to_add_key = returned_keys.pop(100 if is_large_set else 0)

    consul.kv.put(to_add_key.key, to_add_key.value)
    assert not (set(multi_get(consul, key_set)) & set(returned_keys))

    hand_modified_value = "toto"
    consul.kv.put(to_add_key.key, hand_modified_value)
    assert multi_get(consul, key_set)[0].value == hand_modified_value
コード例 #5
0
ファイル: test_multi.py プロジェクト: aubustou/tribun
def test_multi_put(
    consul: Consul,
    is_large_set: bool,
    large_key_set: List[Key],
    configuration_keys: List[Key],
):
    if is_large_set:
        key_set = large_key_set
    else:
        key_set = configuration_keys

    multi_put(consul, key_set)

    assert set(multi_get(consul, key_set)) == set(key_set)
コード例 #6
0
def get(keys: List[Key]) -> List[Key]:
    full_keys = get_full_keys(keys)

    return multi_get(consul, full_keys)