Search in sources :

Example 1 with GetRequest

use of com.scalar.db.rpc.GetRequest in project scalardb by scalar-labs.

the class DistributedStorageServiceTest method get_GateKeeperReturnsFalse_ShouldThrowUnavailableError.

@Test
public void get_GateKeeperReturnsFalse_ShouldThrowUnavailableError() {
    // Arrange
    GetRequest request = GetRequest.newBuilder().build();
    @SuppressWarnings("unchecked") StreamObserver<GetResponse> responseObserver = mock(StreamObserver.class);
    when(gateKeeper.letIn()).thenReturn(false);
    // Act
    storageService.get(request, responseObserver);
    // Assert
    verify(responseObserver).onError(exceptionCaptor.capture());
    assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Code.UNAVAILABLE);
}
Also used : GetRequest(com.scalar.db.rpc.GetRequest) GetResponse(com.scalar.db.rpc.GetResponse) Test(org.junit.jupiter.api.Test)

Example 2 with GetRequest

use of com.scalar.db.rpc.GetRequest in project scalardb by scalar-labs.

the class DistributedStorageServiceTest method get_IsCalledWithProperArguments_StorageShouldBeCalledProperly.

@Test
public void get_IsCalledWithProperArguments_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    GetRequest request = GetRequest.newBuilder().build();
    @SuppressWarnings("unchecked") StreamObserver<GetResponse> responseObserver = mock(StreamObserver.class);
    // Act
    storageService.get(request, responseObserver);
    // Assert
    verify(storage).get(any());
    verify(responseObserver).onNext(any());
    verify(responseObserver).onCompleted();
}
Also used : GetRequest(com.scalar.db.rpc.GetRequest) GetResponse(com.scalar.db.rpc.GetResponse) Test(org.junit.jupiter.api.Test)

Example 3 with GetRequest

use of com.scalar.db.rpc.GetRequest in project scalardb by scalar-labs.

the class DistributedStorageServiceTest method get_StorageThrowsExecutionException_ShouldThrowInternalError.

@Test
public void get_StorageThrowsExecutionException_ShouldThrowInternalError() throws ExecutionException {
    // Arrange
    GetRequest request = GetRequest.newBuilder().build();
    @SuppressWarnings("unchecked") StreamObserver<GetResponse> responseObserver = mock(StreamObserver.class);
    when(storage.get(any())).thenThrow(ExecutionException.class);
    // Act
    storageService.get(request, responseObserver);
    // Assert
    verify(responseObserver).onError(exceptionCaptor.capture());
    assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Status.Code.INTERNAL);
}
Also used : GetRequest(com.scalar.db.rpc.GetRequest) GetResponse(com.scalar.db.rpc.GetResponse) Test(org.junit.jupiter.api.Test)

Example 4 with GetRequest

use of com.scalar.db.rpc.GetRequest in project scalardb by scalar-labs.

the class DistributedStorageServiceTest method get_StorageThrowsIllegalArgumentException_ShouldThrowInvalidArgumentError.

@Test
public void get_StorageThrowsIllegalArgumentException_ShouldThrowInvalidArgumentError() throws ExecutionException {
    // Arrange
    GetRequest request = GetRequest.newBuilder().build();
    @SuppressWarnings("unchecked") StreamObserver<GetResponse> responseObserver = mock(StreamObserver.class);
    when(storage.get(any())).thenThrow(IllegalArgumentException.class);
    // Act
    storageService.get(request, responseObserver);
    // Assert
    verify(responseObserver).onError(exceptionCaptor.capture());
    assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Status.Code.INVALID_ARGUMENT);
}
Also used : GetRequest(com.scalar.db.rpc.GetRequest) GetResponse(com.scalar.db.rpc.GetResponse) Test(org.junit.jupiter.api.Test)

Aggregations

GetRequest (com.scalar.db.rpc.GetRequest)4 GetResponse (com.scalar.db.rpc.GetResponse)4 Test (org.junit.jupiter.api.Test)4