Search in sources :

Example 26 with Delete

use of com.scalar.db.api.Delete 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 27 with Delete

use of com.scalar.db.api.Delete 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 28 with Delete

use of com.scalar.db.api.Delete 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)

Example 29 with Delete

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

the class JdbcTransactionManagerTest method whenSomeOperationsExecutedAndCommit_shouldCallJdbcService.

@Test
public void whenSomeOperationsExecutedAndCommit_shouldCallJdbcService() throws Exception {
    // Arrange
    when(jdbcService.scan(any(), any())).thenReturn(Collections.emptyList());
    when(jdbcService.put(any(), any())).thenReturn(true);
    when(jdbcService.delete(any(), any())).thenReturn(true);
    // Act
    JdbcTransaction transaction = manager.start();
    Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
    transaction.get(get);
    Scan scan = new Scan(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
    transaction.scan(scan);
    Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
    transaction.put(put);
    Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
    transaction.delete(delete);
    transaction.mutate(Arrays.asList(put, delete));
    transaction.commit();
    // Assert
    verify(jdbcService).get(any(), any());
    verify(jdbcService).scan(any(), any());
    verify(jdbcService, times(2)).put(any(), any());
    verify(jdbcService, times(2)).delete(any(), any());
    verify(connection).commit();
    verify(connection).close();
}
Also used : Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 30 with Delete

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

Aggregations

Delete (com.scalar.db.api.Delete)174 Key (com.scalar.db.io.Key)112 Test (org.junit.jupiter.api.Test)111 Put (com.scalar.db.api.Put)59 Get (com.scalar.db.api.Get)29 Result (com.scalar.db.api.Result)29 Test (org.junit.Test)25 DeleteIfExists (com.scalar.db.api.DeleteIfExists)24 ConditionalExpression (com.scalar.db.api.ConditionalExpression)16 DeleteIf (com.scalar.db.api.DeleteIf)15 Mutation (com.scalar.db.api.Mutation)14 MutationCondition (com.scalar.db.api.MutationCondition)11 Scan (com.scalar.db.api.Scan)11 PutIfNotExists (com.scalar.db.api.PutIfNotExists)10 TextValue (com.scalar.db.io.TextValue)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)8 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)6 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)6 DeleteItemRequest (software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest)6 PartitionKey (com.azure.cosmos.models.PartitionKey)5