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])
def run( keys: List[Key], exist_ok: bool = False, ): consul = Consul() if not exist_ok and multi_get(consul, keys): raise TribunError("Existing keys")
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
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
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)
def get(keys: List[Key]) -> List[Key]: full_keys = get_full_keys(keys) return multi_get(consul, full_keys)