use of com.scalar.db.io.Key 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();
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitTest method preparePut.
private Put preparePut() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
return new Put(partitionKey, clusteringKey).withValue(ANY_NAME_3, ANY_TEXT_3).forNamespace(ANY_NAMESPACE).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitTest method prepareGet.
private Get prepareGet() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
return new Get(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method mutate_withConflictError_shouldThrowCrudConflictException.
@Test
public void mutate_withConflictError_shouldThrowCrudConflictException() throws SQLException, ExecutionException {
// Arrange
when(jdbcService.put(any(), any())).thenThrow(sqlException);
when(sqlException.getErrorCode()).thenReturn(1213);
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.mutate(Arrays.asList(put, delete));
}).isInstanceOf(CrudConflictException.class);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method scan_withConflictError_shouldThrowCrudConflictException.
@Test
public void scan_withConflictError_shouldThrowCrudConflictException() throws SQLException, ExecutionException {
// Arrange
when(jdbcService.scan(any(), any())).thenThrow(sqlException);
when(sqlException.getErrorCode()).thenReturn(1213);
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
Scan scan = new Scan(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.scan(scan);
}).isInstanceOf(CrudConflictException.class);
}
Aggregations