use of io.etcd.jetcd.kv.GetResponse in project jetcd by coreos.
the class KVNamespaceTest method assertExistentKVs.
private static void assertExistentKVs(KV kvClient, ByteSequence key, ByteSequence end, List<TestKeyValue> expectedKVs) throws Exception {
CompletableFuture<GetResponse> getFuture = kvClient.get(key, GetOption.newBuilder().withRange(end).build());
GetResponse getResponse = getFuture.get();
assertThat(getResponse.getKvs().size()).isEqualTo(expectedKVs.size());
for (KeyValue keyValue : getResponse.getKvs()) {
boolean exist = false;
for (TestKeyValue expectedKV : expectedKVs) {
if (expectedKV.key.equals(keyValue.getKey())) {
exist = true;
assertThat(keyValue.getValue()).isEqualTo(expectedKV.value);
break;
}
}
assertThat(exist).isTrue();
}
}
use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.
the class EtcdMetadataReportTest method testDoSaveMetadata.
@Test
public void testDoSaveMetadata() throws ExecutionException, InterruptedException {
String version = "1.0.0";
String group = null;
String application = "etc-metadata-report-consumer-test";
String revision = "90980";
String protocol = "xxx";
URL url = generateURL(TEST_SERVICE, version, group, application);
ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(TEST_SERVICE, version, group, "provider", revision, protocol);
etcdMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(serviceMetadataIdentifier), StandardCharsets.UTF_8));
String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
Assertions.assertNotNull(fileContent);
Assertions.assertEquals(fileContent, URL.encode(url.toFullString()));
}
use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.
the class EtcdMetadataReportTest method testDoGetSubscribedURLs.
@Test
public void testDoGetSubscribedURLs() throws ExecutionException, InterruptedException {
String version = "1.0.0";
String group = null;
String application = "etc-metadata-report-consumer-test";
String revision = "90980";
String protocol = "xxx";
URL url = generateURL(TEST_SERVICE, version, group, application);
SubscriberMetadataIdentifier subscriberMetadataIdentifier = new SubscriberMetadataIdentifier(application, revision);
Gson gson = new Gson();
String r = gson.toJson(Arrays.asList(url));
etcdMetadataReport.doSaveSubscriberData(subscriberMetadataIdentifier, r);
CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(subscriberMetadataIdentifier), StandardCharsets.UTF_8));
String fileContent = etcdMetadataReport.doGetSubscribedURLs(subscriberMetadataIdentifier);
Assertions.assertNotNull(fileContent);
Assertions.assertEquals(fileContent, r);
}
use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.
the class EtcdMetadataReportTest method testDoRemoveMetadata.
@Test
public void testDoRemoveMetadata() throws ExecutionException, InterruptedException {
String version = "1.0.0";
String group = null;
String application = "etc-metadata-report-consumer-test";
String revision = "90980";
String protocol = "xxx";
URL url = generateURL(TEST_SERVICE, version, group, application);
ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(TEST_SERVICE, version, group, "provider", revision, protocol);
etcdMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(serviceMetadataIdentifier), StandardCharsets.UTF_8));
String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
Assertions.assertNotNull(fileContent);
etcdMetadataReport.doRemoveMetadata(serviceMetadataIdentifier);
response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(serviceMetadataIdentifier), StandardCharsets.UTF_8));
Assertions.assertTrue(response.get().getKvs().isEmpty());
}
use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.
the class EtcdMetadataReportTest method testDoSaveSubscriberData.
@Test
public void testDoSaveSubscriberData() throws ExecutionException, InterruptedException {
String version = "1.0.0";
String group = null;
String application = "etc-metadata-report-consumer-test";
String revision = "90980";
String protocol = "xxx";
URL url = generateURL(TEST_SERVICE, version, group, application);
SubscriberMetadataIdentifier subscriberMetadataIdentifier = new SubscriberMetadataIdentifier(application, revision);
Gson gson = new Gson();
String r = gson.toJson(Arrays.asList(url));
etcdMetadataReport.doSaveSubscriberData(subscriberMetadataIdentifier, r);
CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(subscriberMetadataIdentifier), StandardCharsets.UTF_8));
String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
Assertions.assertNotNull(fileContent);
Assertions.assertEquals(fileContent, r);
}
Aggregations