Search in sources :

Example 1 with GetResponse

use of com.scalar.db.rpc.GetResponse 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 GetResponse

use of com.scalar.db.rpc.GetResponse 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 GetResponse

use of com.scalar.db.rpc.GetResponse 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 GetResponse

use of com.scalar.db.rpc.GetResponse 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)

Example 5 with GetResponse

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

the class DistributedStorageService method get.

@Override
public void get(GetRequest request, StreamObserver<GetResponse> responseObserver) {
    execute(() -> {
        TableMetadata metadata = tableMetadataManager.getTableMetadata(request.getGet().getNamespace(), request.getGet().getTable());
        if (metadata == null) {
            throw new IllegalArgumentException("the specified table is not found");
        }
        Get get = ProtoUtils.toGet(request.getGet(), metadata);
        Optional<Result> result = storage.get(get);
        GetResponse.Builder builder = GetResponse.newBuilder();
        result.ifPresent(r -> builder.setResult(ProtoUtils.toResult(r)));
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }, responseObserver, "get");
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Get(com.scalar.db.api.Get) GetResponse(com.scalar.db.rpc.GetResponse) Result(com.scalar.db.api.Result)

Aggregations

GetResponse (com.scalar.db.rpc.GetResponse)5 GetRequest (com.scalar.db.rpc.GetRequest)4 Test (org.junit.jupiter.api.Test)4 Get (com.scalar.db.api.Get)1 Result (com.scalar.db.api.Result)1 TableMetadata (com.scalar.db.api.TableMetadata)1