use of io.etcd.jetcd.options.GetOption in project jetcd by coreos.
the class KVTest method testGetSortedPrefix.
@Test
public void testGetSortedPrefix() throws Exception {
String prefix = randomString();
int numPrefix = 3;
putKeysWithPrefix(prefix, numPrefix);
GetOption option = GetOption.newBuilder().withSortField(SortTarget.KEY).withSortOrder(SortOrder.DESCEND).isPrefix(true).build();
CompletableFuture<GetResponse> getFeature = kvClient.get(bytesOf(prefix), option);
GetResponse response = getFeature.get();
assertThat(response.getKvs()).hasSize(numPrefix);
for (int i = 0; i < numPrefix; i++) {
assertThat(response.getKvs().get(i).getKey().toString(UTF_8)).isEqualTo(prefix + (numPrefix - i - 1));
assertThat(response.getKvs().get(i).getValue().toString(UTF_8)).isEqualTo(String.valueOf(numPrefix - i - 1));
}
}
Aggregations