EtcdRepository implements ConfigurationRepository, RegistryRepository { @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override public void persistEphemeral(final String key, final String value) { long leaseId = client.getLeaseClient().grant(etcdProperties.getValue(EtcdPropertyKey.TIME_TO_LIVE_SECONDS)).get().getID(); client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> { })); client.getKVClient().put(ByteSequence.from(key, Charsets.UTF_8), ByteSequence.from(value, Charsets.UTF_8), PutOption.newBuilder().withLeaseId(leaseId).build()).get(); }  @Override void init(final String name, final GovernanceCenterConfiguration config); @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override String get(final String key); @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override List<String> getChildrenKeys(final String key); @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override void persist(final String key, final String value); @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override void persistEphemeral(final String key, final String value); @Override void delete(final String key); @Override void watch(final String key, final DataChangedEventListener dataChangedEventListener); @Override void close(); @Override String getType();  }
@Test @SuppressWarnings("unchecked") public void assertPersistEphemeral() { repository.persistEphemeral("key1", "value1"); verify(lease).grant(anyLong()); verify(lease).keepAlive(anyLong(), any(StreamObserver.class)); verify(kv).put(any(ByteSequence.class), any(ByteSequence.class), any(PutOption.class)); }