Search in sources :

Example 56 with Put

use of com.scalar.db.api.Put in project scalardb by scalar-labs.

the class TwoPhaseConsensusCommitTest method put_TwoPutsGiven_ShouldCallCrudHandlerPutTwice.

@Test
public void put_TwoPutsGiven_ShouldCallCrudHandlerPutTwice() {
    // Arrange
    Put put = preparePut();
    TwoPhaseConsensusCommit transaction = new TwoPhaseConsensusCommit(crud, commit, recovery, false);
    when(crud.getSnapshot()).thenReturn(snapshot);
    // Act
    transaction.put(Arrays.asList(put, put));
    // Assert
    verify(crud, times(2)).put(put);
}
Also used : Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 57 with Put

use of com.scalar.db.api.Put 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);
}
Also used : Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put)

Example 58 with Put

use of com.scalar.db.api.Put in project scalardb by scalar-labs.

the class TwoPhaseConsensusCommitTest method mutate_PutAndDeleteGiven_ShouldCallCrudHandlerPutAndDelete.

@Test
public void mutate_PutAndDeleteGiven_ShouldCallCrudHandlerPutAndDelete() {
    // Arrange
    Put put = preparePut();
    Delete delete = prepareDelete();
    TwoPhaseConsensusCommit transaction = new TwoPhaseConsensusCommit(crud, commit, recovery, false);
    when(crud.getSnapshot()).thenReturn(snapshot);
    // Act
    transaction.mutate(Arrays.asList(put, delete));
    // Assert
    verify(crud).put(put);
    verify(crud).delete(delete);
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 59 with Put

use of com.scalar.db.api.Put 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);
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 60 with Put

use of com.scalar.db.api.Put in project scalardb by scalar-labs.

the class JdbcTransactionManagerTest method whenMutateOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException.

@Test
public void whenMutateOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException() throws Exception {
    // Arrange
    when(jdbcService.put(any(), any())).thenThrow(sqlException);
    // 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(CrudException.class);
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Aggregations

Put (com.scalar.db.api.Put)374 Key (com.scalar.db.io.Key)216 Test (org.junit.jupiter.api.Test)209 Result (com.scalar.db.api.Result)108 Get (com.scalar.db.api.Get)93 Test (org.junit.Test)67 Delete (com.scalar.db.api.Delete)64 IntValue (com.scalar.db.io.IntValue)63 TextValue (com.scalar.db.io.TextValue)48 Scan (com.scalar.db.api.Scan)44 Value (com.scalar.db.io.Value)37 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)35 BooleanValue (com.scalar.db.io.BooleanValue)33 ConditionalExpression (com.scalar.db.api.ConditionalExpression)30 PutIfNotExists (com.scalar.db.api.PutIfNotExists)29 PutIf (com.scalar.db.api.PutIf)28 DoubleValue (com.scalar.db.io.DoubleValue)26 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)19 ExecutionException (com.scalar.db.exception.storage.ExecutionException)17 Mutation (com.scalar.db.api.Mutation)16