Search in sources :

Example 66 with Get

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

the class JdbcTransactionManagerTest method whenRollbackFails_shouldThrowAbortException.

@Test
public void whenRollbackFails_shouldThrowAbortException() throws Exception {
    // Arrange
    doThrow(sqlException).when(connection).rollback();
    // Act Assert
    assertThatThrownBy(() -> {
        JdbcTransaction transaction = manager.start();
        Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
        transaction.get(get);
        Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
        transaction.put(put);
        transaction.abort();
    }).isInstanceOf(AbortException.class);
    verify(connection).close();
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 67 with Get

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

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

the class JdbcTransactionManagerTest method whenGetOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException.

@Test
public void whenGetOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException() throws Exception {
    // Arrange
    when(jdbcService.get(any(), any())).thenThrow(sqlException);
    // Act Assert
    assertThatThrownBy(() -> {
        JdbcTransaction transaction = manager.start();
        Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
        transaction.get(get);
    }).isInstanceOf(CrudException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 69 with Get

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

the class JdbcTransactionManagerTest method get_withConflictError_shouldThrowCrudConflictException.

@Test
public void get_withConflictError_shouldThrowCrudConflictException() throws SQLException, ExecutionException {
    // Arrange
    when(jdbcService.get(any(), any())).thenThrow(sqlException);
    when(sqlException.getErrorCode()).thenReturn(1213);
    // Act Assert
    assertThatThrownBy(() -> {
        JdbcTransaction transaction = manager.start();
        Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
        transaction.get(get);
    }).isInstanceOf(CrudConflictException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 70 with Get

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

the class ScalarDbUtilsTest method copyAndSetTargetToIfNot_GetGiven_ShouldReturnDifferentInstance.

@Test
public void copyAndSetTargetToIfNot_GetGiven_ShouldReturnDifferentInstance() {
    // Arrange
    Get get = new Get(new Key("c1", "v1"));
    // Act
    Get actual = ScalarDbUtils.copyAndSetTargetToIfNot(get, NAMESPACE, TABLE);
    // Assert
    assertThat(actual == get).isFalse();
    assertThat(get.forNamespace()).isNotPresent();
    assertThat(get.forTable()).isNotPresent();
    assertThat(actual.forNamespace()).isEqualTo(NAMESPACE);
    assertThat(actual.forTable()).isEqualTo(TABLE);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Aggregations

Get (com.scalar.db.api.Get)286 Test (org.junit.jupiter.api.Test)130 Result (com.scalar.db.api.Result)129 Key (com.scalar.db.io.Key)126 Test (org.junit.Test)88 Put (com.scalar.db.api.Put)86 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)32 Delete (com.scalar.db.api.Delete)28 IntValue (com.scalar.db.io.IntValue)28 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)21 TextValue (com.scalar.db.io.TextValue)16 ConditionalExpression (com.scalar.db.api.ConditionalExpression)13 PartitionKey (com.azure.cosmos.models.PartitionKey)12 TableMetadata (com.scalar.db.api.TableMetadata)10 BooleanValue (com.scalar.db.io.BooleanValue)10 PutIf (com.scalar.db.api.PutIf)8 BigIntValue (com.scalar.db.io.BigIntValue)7 HashMap (java.util.HashMap)7 BlobValue (com.scalar.db.io.BlobValue)6 DistributedTransactionServiceWithConsensusCommitIntegrationTest.prepareGet (com.scalar.db.server.DistributedTransactionServiceWithConsensusCommitIntegrationTest.prepareGet)6