use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class ScalarDbUtilsTest method copyAndSetTargetToIfNot_MutationsGiven_ShouldReturnDifferentInstance.
@Test
public void copyAndSetTargetToIfNot_MutationsGiven_ShouldReturnDifferentInstance() {
// Arrange
Put put = new Put(new Key("c1", "v1"));
Delete delete = new Delete(new Key("c1", "v1"));
List<Mutation> mutations = Arrays.asList(put, delete);
// Act
List<Mutation> actual = ScalarDbUtils.copyAndSetTargetToIfNot(mutations, NAMESPACE, TABLE);
// Assert
assertThat(actual == mutations).isFalse();
assertThat(actual.get(0) == put).isFalse();
assertThat(actual.get(1) == delete).isFalse();
assertThat(put.forNamespace()).isNotPresent();
assertThat(put.forTable()).isNotPresent();
assertThat(delete.forNamespace()).isNotPresent();
assertThat(delete.forTable()).isNotPresent();
assertThat(actual.get(0).forNamespace()).isEqualTo(NAMESPACE);
assertThat(actual.get(0).forTable()).isEqualTo(TABLE);
assertThat(actual.get(1).forNamespace()).isEqualTo(NAMESPACE);
assertThat(actual.get(1).forTable()).isEqualTo(TABLE);
}
use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class DistributedStorageService method mutate.
@Override
public void mutate(MutateRequest request, StreamObserver<Empty> responseObserver) {
execute(() -> {
List<Mutation> mutations;
if (request.getMutationCount() > 0) {
TableMetadata metadata = tableMetadataManager.getTableMetadata(request.getMutationList().get(0).getNamespace(), request.getMutationList().get(0).getTable());
if (metadata == null) {
throw new IllegalArgumentException("the specified table is not found");
}
mutations = new ArrayList<>(request.getMutationCount());
for (com.scalar.db.rpc.Mutation mutation : request.getMutationList()) {
mutations.add(ProtoUtils.toMutation(mutation, metadata));
}
} else {
mutations = Collections.emptyList();
}
storage.mutate(mutations);
responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onCompleted();
}, responseObserver, "mutate");
}
use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class GrpcStorageTest method mutate_StubThrowInternalError_ShouldThrowExecutionException.
@Test
public void mutate_StubThrowInternalError_ShouldThrowExecutionException() {
// Arrange
Key partitionKey = new Key("col1", 1);
List<Mutation> mutations = Arrays.asList(new Put(partitionKey), new Delete(partitionKey));
when(blockingStub.mutate(any())).thenThrow(Status.INTERNAL.asRuntimeException());
// Act
assertThatThrownBy(() -> storage.mutate(mutations)).isInstanceOf(ExecutionException.class);
}
use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class GrpcStorageTest method mutate_isCalledWithProperArguments_StubShouldBeCalledProperly.
@Test
public void mutate_isCalledWithProperArguments_StubShouldBeCalledProperly() throws ExecutionException {
// Arrange
Key partitionKey = new Key("col1", 1);
List<Mutation> mutations = Arrays.asList(new Put(partitionKey), new Delete(partitionKey));
// Act
storage.mutate(mutations);
// Assert
verify(blockingStub).mutate(any());
}
use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class GrpcStorageTest method mutate_StubThrowInvalidArgumentError_ShouldThrowIllegalArgumentException.
@Test
public void mutate_StubThrowInvalidArgumentError_ShouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key("col1", 1);
List<Mutation> mutations = Arrays.asList(new Put(partitionKey), new Delete(partitionKey));
when(blockingStub.mutate(any())).thenThrow(Status.INVALID_ARGUMENT.asRuntimeException());
// Act Assert
assertThatThrownBy(() -> storage.mutate(mutations)).isInstanceOf(IllegalArgumentException.class);
}
Aggregations