EtcdRepository implements ConfigurationRepository, RegistryRepository { @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override public List<String> getChildrenKeys(final String key) { String prefix = key + PATH_SEPARATOR; ByteSequence prefixByteSequence = ByteSequence.from(prefix, Charsets.UTF_8); GetOption getOption = GetOption.newBuilder().withPrefix(prefixByteSequence).withSortField(GetOption.SortTarget.KEY).withSortOrder(GetOption.SortOrder.ASCEND).build(); List<KeyValue> keyValues = client.getKVClient().get(prefixByteSequence, getOption).get().getKvs(); return keyValues.stream().map(e -> getSubNodeKeyName(prefix, e.getKey().toString(Charsets.UTF_8))).distinct().collect(Collectors.toList()); }  @Override void init(final String name, final GovernanceCenterConfiguration config); @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override String get(final String key); @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override List<String> getChildrenKeys(final String key); @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override void persist(final String key, final String value); @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override void persistEphemeral(final String key, final String value); @Override void delete(final String key); @Override void watch(final String key, final DataChangedEventListener dataChangedEventListener); @Override void close(); @Override String getType();  }
@Test public void assertGetChildrenKeys() { io.etcd.jetcd.api.KeyValue keyValue1 = io.etcd.jetcd.api.KeyValue.newBuilder() .setKey(ByteString.copyFromUtf8("/key/key1/key1-1")) .setValue(ByteString.copyFromUtf8("value1")).build(); io.etcd.jetcd.api.KeyValue keyValue2 = io.etcd.jetcd.api.KeyValue.newBuilder() .setKey(ByteString.copyFromUtf8("/key/key2")) .setValue(ByteString.copyFromUtf8("value3")).build(); List<KeyValue> keyValues = Arrays.asList(new KeyValue(keyValue1, ByteSequence.EMPTY), new KeyValue(keyValue2, ByteSequence.EMPTY), new KeyValue(keyValue1, ByteSequence.EMPTY)); when(getResponse.getKvs()).thenReturn(keyValues); List<String> actual = repository.getChildrenKeys("/key"); assertThat(actual.size(), is(2)); Iterator<String> iterator = actual.iterator(); assertThat(iterator.next(), is("key1")); assertThat(iterator.next(), is("key2")); }