Search in sources :

Example 1 with LeaseKeepAliveResponse

use of io.etcd.jetcd.api.LeaseKeepAliveResponse in project jetcd by coreos.

the class LeaseUnitTest method testKeepAliveResetOnStreamErrors.

/*
    // TODO: sometime this.responseObserverRef.get().onNext(lrp) blocks even though client has received msg;
    // seems like a bug in grpc test framework.
    @Ignore
    @Test
    public void testKeepAliveReceivesExpiredLease() {
    KeepAliveListener listener = this.leaseCli.keepAlive(LEASE_ID_1);
    LeaseKeepAliveResponse lrp = LeaseKeepAliveResponse
        .newBuilder()
        .setID(LEASE_ID_1)
        .setTTL(0)
        .build();
    this.responseObserverRef.get().onNext(lrp);
    
    // expect lease expired exception.
    assertThatThrownBy(() -> listener.listen())
        .hasCause(new IllegalStateException("Lease " + LEASE_ID_1 + " expired"));
    
    // expect no more keep alive requests for LEASE_ID after receiving lease expired response.
    verify(this.requestStreamObserverMock, after(1000).atMost(1))
        .onNext(argThat(hasLeaseID(LEASE_ID_1)));
    
    listener.close();
    }
    */
@Test
public void testKeepAliveResetOnStreamErrors() {
    final StreamObserver<io.etcd.jetcd.lease.LeaseKeepAliveResponse> observer = Observers.observer(response -> {
    });
    try (CloseableClient client = this.leaseCli.keepAlive(LEASE_ID_1, observer)) {
        Throwable t = Status.ABORTED.asRuntimeException();
        // onError triggers reset() to be executed.
        // scheduler will execute reset() in 500 ms.
        responseObserverRef.get().onError(t);
        // expect keep alive requests are still sending even with reset.
        verify(this.requestStreamObserverMock, timeout(2000).atLeast(3)).onNext(argThat(hasLeaseID(LEASE_ID_1)));
    }
}
Also used : LeaseKeepAliveResponse(io.etcd.jetcd.api.LeaseKeepAliveResponse) CloseableClient(io.etcd.jetcd.support.CloseableClient) Test(org.junit.jupiter.api.Test)

Example 2 with LeaseKeepAliveResponse

use of io.etcd.jetcd.api.LeaseKeepAliveResponse in project jetcd by coreos.

the class LeaseUnitTest method testKeepAliveOnce.

@Test
public void testKeepAliveOnce() throws ExecutionException, InterruptedException {
    CompletableFuture<io.etcd.jetcd.lease.LeaseKeepAliveResponse> lrpFuture = this.leaseCli.keepAliveOnce(LEASE_ID_1);
    LeaseKeepAliveResponse lrp = LeaseKeepAliveResponse.newBuilder().setID(LEASE_ID_1).build();
    this.responseObserverRef.get().onNext(lrp);
    io.etcd.jetcd.lease.LeaseKeepAliveResponse lrpActual = lrpFuture.get();
    assertThat(lrpActual.getID()).isEqualTo(lrp.getID());
}
Also used : LeaseKeepAliveResponse(io.etcd.jetcd.api.LeaseKeepAliveResponse) Test(org.junit.jupiter.api.Test)

Example 3 with LeaseKeepAliveResponse

use of io.etcd.jetcd.api.LeaseKeepAliveResponse in project jetcd by coreos.

the class LeaseUnitTest method testKeepAliveOnceStreamCloseOnSuccess.

@Test
public void testKeepAliveOnceStreamCloseOnSuccess() throws ExecutionException, InterruptedException {
    CompletableFuture<io.etcd.jetcd.lease.LeaseKeepAliveResponse> lrpFuture = this.leaseCli.keepAliveOnce(LEASE_ID_1);
    LeaseKeepAliveResponse lrp = LeaseKeepAliveResponse.newBuilder().setID(LEASE_ID_1).build();
    this.responseObserverRef.get().onNext(lrp);
    lrpFuture.get();
    verify(this.requestStreamObserverMock, timeout(100).times(1)).onCompleted();
}
Also used : LeaseKeepAliveResponse(io.etcd.jetcd.api.LeaseKeepAliveResponse) Test(org.junit.jupiter.api.Test)

Aggregations

LeaseKeepAliveResponse (io.etcd.jetcd.api.LeaseKeepAliveResponse)3 Test (org.junit.jupiter.api.Test)3 CloseableClient (io.etcd.jetcd.support.CloseableClient)1