Search in sources :

Example 1 with LeaseKeepAliveResponse

use of com.coreos.jetcd.api.LeaseKeepAliveResponse 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);
}
Also used : LeaseKeepAliveResponse(com.coreos.jetcd.api.LeaseKeepAliveResponse) LeaseHandler(com.coreos.jetcd.Lease.LeaseHandler) PutResponse(com.coreos.jetcd.api.PutResponse) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Aggregations

LeaseHandler (com.coreos.jetcd.Lease.LeaseHandler)1 LeaseKeepAliveResponse (com.coreos.jetcd.api.LeaseKeepAliveResponse)1 PutResponse (com.coreos.jetcd.api.PutResponse)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1