use of com.coreos.jetcd.Lease.LeaseHandler in project jetcd by coreos.
the class LeaseTest method testkeepAlive.
@Test(dependsOnMethods = "testRevoke")
public void testkeepAlive() throws Exception {
long leaseID = leaseClient.grant(5).get().getID();
PutResponse putRep = kvClient.put(testKey, testName, PutOption.newBuilder().withLeaseId(leaseID).build()).get();
test.assertEquals(kvClient.get(testKey).get().getCount(), 1);
leaseClient.startKeepAliveService();
leaseClient.keepAlive(leaseID, new LeaseHandler() {
@Override
public void onKeepAliveRespond(LeaseKeepAliveResponse keepAliveResponse) {
}
@Override
public void onLeaseExpired(long leaseId) {
}
@Override
public void onError(Throwable throwable) {
}
});
Thread.sleep(6000);
test.assertEquals(kvClient.get(testKey).get().getCount(), 1);
leaseClient.cancelKeepAlive(leaseID);
test.assertEquals(kvClient.get(testKey).get().getCount(), 0);
}
Aggregations