Search in sources :

Example 76 with Put

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

the class OperationCheckerTest method whenCheckingPutOperationWithNullValue_shouldNotThrowAnyException.

@Test
public void whenCheckingPutOperationWithNullValue_shouldNotThrowAnyException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    MutationCondition condition = new PutIfNotExists();
    Put put = new Put(partitionKey, clusteringKey).withValue(COL1, 1).withValue(COL2, 0.1D).withBooleanValue(COL3, null).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException();
}
Also used : PutIfNotExists(com.scalar.db.api.PutIfNotExists) MutationCondition(com.scalar.db.api.MutationCondition) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 77 with Put

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

the class JdbcDatabaseTest method whenPutOperationExecutedAndJdbcServiceThrowsSQLException_shouldThrowExecutionException.

@Test
public void whenPutOperationExecutedAndJdbcServiceThrowsSQLException_shouldThrowExecutionException() throws Exception {
    // Arrange
    when(jdbcService.put(any(), any())).thenThrow(sqlException);
    // Act Assert
    assertThatThrownBy(() -> {
        Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
        jdbcDatabase.put(put);
    }).isInstanceOf(ExecutionException.class);
    verify(connection).close();
}
Also used : Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 78 with Put

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

the class JdbcDatabaseTest method whenPutOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException.

@Test
public void whenPutOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException() throws Exception {
    // Arrange
    when(jdbcService.put(any(), any())).thenReturn(false);
    // Act Assert
    assertThatThrownBy(() -> {
        Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfNotExists()).forNamespace(NAMESPACE).forTable(TABLE);
        jdbcDatabase.put(put);
    }).isInstanceOf(NoMutationException.class);
    verify(connection).close();
}
Also used : PutIfNotExists(com.scalar.db.api.PutIfNotExists) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 79 with Put

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

the class JdbcDatabaseTest method whenPutOperationExecuted_shouldCallJdbcService.

@Test
public void whenPutOperationExecuted_shouldCallJdbcService() throws Exception {
    // Arrange
    when(jdbcService.put(any(), any())).thenReturn(true);
    // Act
    Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
    jdbcDatabase.put(put);
    // Assert
    verify(jdbcService).put(any(), any());
    verify(connection).close();
}
Also used : Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 80 with Put

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

the class JdbcDatabaseTest method mutate_withConflictError_shouldThrowRetriableExecutionException.

@Test
public void mutate_withConflictError_shouldThrowRetriableExecutionException() throws SQLException, ExecutionException {
    // Arrange
    when(jdbcService.mutate(any(), any())).thenThrow(sqlException);
    when(sqlException.getErrorCode()).thenReturn(1213);
    // Act Assert
    assertThatThrownBy(() -> {
        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);
        jdbcDatabase.mutate(Arrays.asList(put, delete));
    }).isInstanceOf(RetriableExecutionException.class);
    verify(connection).close();
}
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