Search in sources :

Example 6 with GetOption

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));
    }
}
Also used : GetOption(io.etcd.jetcd.options.GetOption) TestUtil.randomString(io.etcd.jetcd.impl.TestUtil.randomString) GetResponse(io.etcd.jetcd.kv.GetResponse) Test(org.junit.jupiter.api.Test)

Aggregations

GetOption (io.etcd.jetcd.options.GetOption)6 Test (org.junit.jupiter.api.Test)6 ByteSequence (io.etcd.jetcd.ByteSequence)4 TestUtil.randomByteSequence (io.etcd.jetcd.impl.TestUtil.randomByteSequence)4 KeyValue (io.etcd.jetcd.KeyValue)3 CampaignResponse (io.etcd.jetcd.election.CampaignResponse)3 LeaderResponse (io.etcd.jetcd.election.LeaderResponse)2 NotLeaderException (io.etcd.jetcd.election.NotLeaderException)2 GetResponse (io.etcd.jetcd.kv.GetResponse)2 ExecutionException (java.util.concurrent.ExecutionException)2 Client (io.etcd.jetcd.Client)1 Election (io.etcd.jetcd.Election)1 LeaderKey (io.etcd.jetcd.election.LeaderKey)1 NoLeaderException (io.etcd.jetcd.election.NoLeaderException)1 TestUtil.randomString (io.etcd.jetcd.impl.TestUtil.randomString)1 PutResponse (io.etcd.jetcd.kv.PutResponse)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1