use of io.etcd.jetcd.ClientBuilder in project jetcd by coreos.
the class ClientBuilderTest method testNamespace.
@ParameterizedTest
@MethodSource("namespaceProvider")
public void testNamespace(ByteSequence namespaceSetting, ByteSequence expectedNamespace) throws URISyntaxException {
final ClientBuilder builder = Client.builder().endpoints(new URI("http://127.0.0.1:2379")).namespace(namespaceSetting);
final ClientConnectionManager connectionManager = new ClientConnectionManager(builder);
assertThat(connectionManager.getNamespace()).isEqualTo(expectedNamespace);
}
use of io.etcd.jetcd.ClientBuilder in project jetcd by coreos.
the class ClientConnectionManagerTest method testHeaders.
@Test
public void testHeaders() throws InterruptedException, ExecutionException {
final CountDownLatch latch = new CountDownLatch(1);
final ClientBuilder builder = TestUtil.client(cluster).header("MyHeader1", "MyHeaderVal1").header("MyHeader2", "MyHeaderVal2").interceptor(new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
super.start(responseListener, headers);
assertThat(headers.get(Metadata.Key.of("MyHeader1", Metadata.ASCII_STRING_MARSHALLER))).isEqualTo("MyHeaderVal1");
assertThat(headers.get(Metadata.Key.of("MyHeader2", Metadata.ASCII_STRING_MARSHALLER))).isEqualTo("MyHeaderVal2");
latch.countDown();
}
};
}
});
try (Client client = builder.build()) {
CompletableFuture<PutResponse> future = client.getKVClient().put(bytesOf("sample_key"), bytesOf("sample_key"));
latch.await(1, TimeUnit.MINUTES);
future.get();
}
}
use of io.etcd.jetcd.ClientBuilder in project jetcd by coreos.
the class ClientConnectionManagerTest method testAuthHeaders.
@Test
public void testAuthHeaders() throws InterruptedException, ExecutionException {
final CountDownLatch latch = new CountDownLatch(1);
Auth authClient = TestUtil.client(cluster).build().getAuthClient();
authClient.userAdd(root, rootPass).get();
ByteSequence role = TestUtil.bytesOf("root");
authClient.userGrantRole(root, role).get();
authClient.authEnable().get();
final ClientBuilder builder = TestUtil.client(cluster).authHeader("MyAuthHeader", "MyAuthHeaderVal").header("MyHeader2", "MyHeaderVal2").user(root).password(rootPass);
assertThat(builder.authHeaders().get(Metadata.Key.of("MyAuthHeader", Metadata.ASCII_STRING_MARSHALLER))).isEqualTo("MyAuthHeaderVal");
try (Client client = builder.build()) {
CompletableFuture<AuthDisableResponse> future = client.getAuthClient().authDisable();
latch.await(10, TimeUnit.SECONDS);
future.get();
}
authClient.userRevokeRole(root, role).get();
authClient.userDelete(root).get();
}
use of io.etcd.jetcd.ClientBuilder in project jetcd by coreos.
the class LoadBalancerTest method testPickFirstBalancerFactory.
@Test
public void testPickFirstBalancerFactory() throws Exception {
final List<URI> endpoints = cluster.clientEndpoints();
final ClientBuilder builder = Client.builder().endpoints(endpoints).loadBalancerPolicy("pick_first");
try (Client client = builder.build();
KV kv = client.getKVClient()) {
long lastMemberId = 0;
final String allEndpoints = endpoints.stream().map(URI::toString).collect(Collectors.joining(","));
for (int i = 0; i < allEndpoints.length() * 2; i++) {
Response response = kv.put(TestUtil.randomByteSequence(), TestUtil.randomByteSequence()).get();
if (i == 0) {
lastMemberId = response.getHeader().getMemberId();
}
assertThat(response.getHeader().getMemberId()).isEqualTo(lastMemberId);
}
}
}
use of io.etcd.jetcd.ClientBuilder in project jetcd by coreos.
the class LoadBalancerTest method testRoundRobinLoadBalancerFactory.
@Test
public void testRoundRobinLoadBalancerFactory() throws Exception {
final List<URI> endpoints = cluster.clientEndpoints();
final ClientBuilder builder = Client.builder().endpoints(endpoints).loadBalancerPolicy("round_robin");
try (Client client = builder.build();
KV kv = client.getKVClient()) {
long lastMemberId = 0;
long differences = 0;
final String allEndpoints = endpoints.stream().map(URI::toString).collect(Collectors.joining(","));
for (int i = 0; i < allEndpoints.length(); i++) {
PutResponse response = kv.put(TestUtil.randomByteSequence(), TestUtil.randomByteSequence()).get();
if (i > 0 && lastMemberId != response.getHeader().getMemberId()) {
differences++;
}
lastMemberId = response.getHeader().getMemberId();
}
assertThat(differences).isNotEqualTo(lastMemberId);
}
}
Aggregations