use of com.coreos.jetcd.options.GetOption in project jetcd by coreos.
the class KVTest method testGetWithRev.
@Test
public void testGetWithRev() throws Exception {
ByteString sampleKey = ByteString.copyFrom("sample_key3", "UTF-8");
ByteString sampleValue = ByteString.copyFrom("sample_value", "UTF-8");
ByteString sampleValueTwo = ByteString.copyFrom("sample_value2", "UTF-8");
ListenableFuture<PutResponse> feature = kvClient.put(sampleKey, sampleValue);
try {
PutResponse putResp = feature.get();
kvClient.put(sampleKey, sampleValueTwo).get();
GetOption option = GetOption.newBuilder().withRevision(putResp.getHeader().getRevision()).build();
ListenableFuture<RangeResponse> getFeature = kvClient.get(sampleKey, option);
RangeResponse response = getFeature.get();
test.assertEquals(response.getKvsCount(), 1);
test.assertEquals(response.getKvs(0).getValue().toStringUtf8(), "sample_value");
} catch (Exception e) {
// empty
}
}
use of com.coreos.jetcd.options.GetOption in project jetcd by coreos.
the class KVTest method testGetSortedPrefix.
@Test
public void testGetSortedPrefix() throws Exception {
ByteString key = ByteString.copyFrom("test_key", "UTF-8");
ByteString testValue = ByteString.copyFrom("test_value", "UTF-8");
for (int i = 0; i < 3; i++) {
ByteString testKey = ByteString.copyFrom("test_key" + i, "UTF-8");
try {
kvClient.put(testKey, testValue).get();
} catch (Exception e) {
// empty
}
}
ByteString endKey = ByteString.copyFrom("\0", "UTF-8");
GetOption option = GetOption.newBuilder().withSortField(RangeRequest.SortTarget.KEY).withSortOrder(RangeRequest.SortOrder.DESCEND).withRange(endKey).build();
try {
ListenableFuture<RangeResponse> getFeature = kvClient.get(key, option);
RangeResponse response = getFeature.get();
test.assertEquals(response.getKvsCount(), 3);
test.assertEquals(response.getKvs(0).getKey().toStringUtf8(), "test_key2");
test.assertEquals(response.getKvs(0).getValue().toStringUtf8(), "test_value");
test.assertEquals(response.getKvs(1).getKey().toStringUtf8(), "test_key1");
test.assertEquals(response.getKvs(1).getValue().toStringUtf8(), "test_value");
test.assertEquals(response.getKvs(2).getKey().toStringUtf8(), "test_key0");
test.assertEquals(response.getKvs(2).getValue().toStringUtf8(), "test_value");
} catch (Exception e) {
// empty
}
}
Aggregations