Skip to content

Commit

Permalink
Add test for #1132
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Burgazzoli <lburgazzoli@gmail.com>
  • Loading branch information
lburgazzoli committed Jun 10, 2023
1 parent a203276 commit dbd35a5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions jetcd-core/src/test/java/io/etcd/jetcd/impl/LeaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.etcd.jetcd.support.CloseableClient;
import io.etcd.jetcd.support.Observers;
import io.etcd.jetcd.test.EtcdClusterExtension;
import io.grpc.stub.StreamObserver;

import com.google.common.base.Charsets;

Expand Down Expand Up @@ -166,6 +167,42 @@ public void testKeepAlive() throws ExecutionException, InterruptedException {
});
}

@Test
public void testKeepAliveClose() throws ExecutionException, InterruptedException {
try (Client c = TestUtil.client(cluster).build()) {
Lease lc = c.getLeaseClient();

AtomicReference<LeaseKeepAliveResponse> resp = new AtomicReference<>();
AtomicReference<Throwable> error = new AtomicReference<>();

StreamObserver<LeaseKeepAliveResponse> observer = Observers.<LeaseKeepAliveResponse> builder()
.onNext(resp::set)
.onError(error::set)
.build();

long leaseID = lc.grant(5, 10, TimeUnit.SECONDS).get().getID();

kvClient.put(KEY, VALUE, PutOption.newBuilder().withLeaseId(leaseID).build()).get();
assertThat(kvClient.get(KEY).get().getCount()).isEqualTo(1);

try (CloseableClient lcc = lc.keepAlive(leaseID, observer)) {
await().pollInterval(250, TimeUnit.MILLISECONDS).untilAsserted(() -> {
LeaseKeepAliveResponse response = resp.get();
assertThat(response).isNotNull();
assertThat(response.getTTL()).isGreaterThan(0);
});

assertThatNoException()
.isThrownBy(c::close);

await().pollInterval(250, TimeUnit.MILLISECONDS).untilAsserted(() -> {
Throwable response = error.get();
assertThat(response).isNotNull();
});
}
}
}

@Test
public void testTimeToLive() throws ExecutionException, InterruptedException {
long ttl = 5;
Expand Down

0 comments on commit dbd35a5

Please sign in to comment.