Search in sources :

Example 1 with MutateRequest

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

the class DistributedStorageServiceTest method mutate_StorageThrowsIllegalArgumentException_ShouldThrowInvalidArgumentError.

@Test
public void mutate_StorageThrowsIllegalArgumentException_ShouldThrowInvalidArgumentError() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Put(partitionKey))).build();
    @SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
    doThrow(IllegalArgumentException.class).when(storage).mutate(anyList());
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(responseObserver).onError(exceptionCaptor.capture());
    assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Status.Code.INVALID_ARGUMENT);
}
Also used : Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 2 with MutateRequest

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

the class DistributedStorageServiceTest method mutate_IsCalledWithSingleDelete_StorageShouldBeCalledProperly.

@Test
public void mutate_IsCalledWithSingleDelete_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Delete(partitionKey))).build();
    @SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(storage).mutate(anyList());
    verify(responseObserver).onNext(any());
    verify(responseObserver).onCompleted();
}
Also used : Delete(com.scalar.db.api.Delete) Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 3 with MutateRequest

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

the class DistributedStorageServiceTest method mutate_IsCalledWithMixedPutAndDelete_StorageShouldBeCalledProperly.

@Test
public void mutate_IsCalledWithMixedPutAndDelete_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addAllMutation(Arrays.asList(ProtoUtils.toMutation(new Put(partitionKey)), ProtoUtils.toMutation(new Delete(partitionKey)))).build();
    @SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(storage).mutate(anyList());
    verify(responseObserver).onNext(any());
    verify(responseObserver).onCompleted();
}
Also used : Delete(com.scalar.db.api.Delete) Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 4 with MutateRequest

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

the class DistributedStorageServiceTest method mutate_IsCalledWithSinglePut_StorageShouldBeCalledProperly.

@Test
public void mutate_IsCalledWithSinglePut_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Put(partitionKey))).build();
    @SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(storage).mutate(anyList());
    verify(responseObserver).onNext(any());
    verify(responseObserver).onCompleted();
}
Also used : Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 5 with MutateRequest

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

the class DistributedStorageServiceTest method mutate_StorageThrowsExecutionException_ShouldThrowInternalError.

@Test
public void mutate_StorageThrowsExecutionException_ShouldThrowInternalError() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Put(partitionKey))).build();
    @SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
    doThrow(ExecutionException.class).when(storage).mutate(anyList());
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(responseObserver).onError(exceptionCaptor.capture());
    assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Status.Code.INTERNAL);
}
Also used : Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Aggregations

Empty (com.google.protobuf.Empty)9 Key (com.scalar.db.io.Key)9 MutateRequest (com.scalar.db.rpc.MutateRequest)9 Test (org.junit.jupiter.api.Test)9 Put (com.scalar.db.api.Put)7 Delete (com.scalar.db.api.Delete)3