use of io.etcd.jetcd.ByteSequence in project jetcd by coreos.
the class ElectionImpl method observe.
@Override
public void observe(ByteSequence electionName, Listener listener) {
checkNotNull(electionName, "election name should not be null");
checkNotNull(listener, "listener should not be null");
LeaderRequest request = LeaderRequest.newBuilder().setName(ByteString.copyFrom(electionName.getBytes())).build();
stub.observe(request).handler(value -> listener.onNext(new LeaderResponse(value, namespace))).endHandler(ignored -> listener.onCompleted()).exceptionHandler(error -> listener.onError(EtcdExceptionFactory.toEtcdException(error)));
}
use of io.etcd.jetcd.ByteSequence in project jetcd by coreos.
the class AuthRoleGetResponse method toPermission.
private static Permission toPermission(io.etcd.jetcd.api.Permission perm) {
ByteSequence key = ByteSequence.from(perm.getKey());
ByteSequence rangeEnd = ByteSequence.from(perm.getRangeEnd());
Permission.Type type;
switch(perm.getPermType()) {
case READ:
type = Permission.Type.READ;
break;
case WRITE:
type = Permission.Type.WRITE;
break;
case READWRITE:
type = Permission.Type.READWRITE;
break;
default:
type = Permission.Type.UNRECOGNIZED;
}
return new Permission(type, key, rangeEnd);
}
use of io.etcd.jetcd.ByteSequence in project jetcd by coreos.
the class Requests method defineRangeRequestEnd.
private static void defineRangeRequestEnd(ByteSequence key, Optional<ByteSequence> endKeyOptional, boolean hasPrefix, ByteSequence namespace, Consumer<ByteString> setRangeEndConsumer) {
if (endKeyOptional.isPresent()) {
setRangeEndConsumer.accept(Util.prefixNamespaceToRangeEnd(ByteString.copyFrom(endKeyOptional.get().getBytes()), namespace));
} else {
if (hasPrefix) {
ByteSequence endKey = OptionsUtil.prefixEndOf(key);
setRangeEndConsumer.accept(Util.prefixNamespaceToRangeEnd(ByteString.copyFrom(endKey.getBytes()), namespace));
}
}
}
use of io.etcd.jetcd.ByteSequence in project jetcd by coreos.
the class WatchTest method testWatchCompacted.
@ParameterizedTest
@MethodSource("parameters")
public void testWatchCompacted(final Client client) throws Exception {
final ByteSequence key = randomByteSequence();
final AtomicReference<Throwable> ref = new AtomicReference<>();
// Try to listen from previous revision on
final WatchOption options = WatchOption.newBuilder().withRevision(getCompactedRevision(client, key)).build();
final Watch wc = client.getWatchClient();
try (Watcher watcher = wc.watch(key, options, Watch.listener(TestUtil::noOpWatchResponseConsumer, ref::set))) {
await().atMost(TIME_OUT_SECONDS, TimeUnit.SECONDS).untilAsserted(() -> assertThat(ref.get()).isNotNull());
assertThat(ref.get().getClass()).isEqualTo(CompactedException.class);
}
}
use of io.etcd.jetcd.ByteSequence in project dubbo by alibaba.
the class JEtcdClientTest method test_watch_when_modify.
@Test
public void test_watch_when_modify() {
String path = "/dubbo/config/jetcd-client-unit-test/configurators";
String endpoint = "http://127.0.0.1:2379";
CountDownLatch latch = new CountDownLatch(1);
ByteSequence key = ByteSequence.from(path, UTF_8);
Watch.Listener listener = Watch.listener(response -> {
for (WatchEvent event : response.getEvents()) {
Assertions.assertEquals("PUT", event.getEventType().toString());
Assertions.assertEquals(path, event.getKeyValue().getKey().toString(UTF_8));
Assertions.assertEquals("Hello", event.getKeyValue().getValue().toString(UTF_8));
latch.countDown();
}
});
try (Client client = Client.builder().endpoints(endpoint).build();
Watch watch = client.getWatchClient();
Watch.Watcher watcher = watch.watch(key, listener)) {
// try to modify the key
client.getKVClient().put(ByteSequence.from(path, UTF_8), ByteSequence.from("Hello", UTF_8));
latch.await();
} catch (Exception e) {
Assertions.fail(e.getMessage());
}
}
Aggregations