Search in sources :

Example 41 with TextValue

use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.

the class DistributedStorageIntegrationTestBase method delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationException.

@Test
public void delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationException() throws ExecutionException {
    // Arrange
    populateRecords();
    int pKey = 0;
    int cKey = 0;
    Key partitionKey = new Key(COL_NAME1, pKey);
    Key clusteringKey = new Key(COL_NAME4, cKey);
    // Act
    Delete delete = prepareDelete(pKey, cKey);
    delete.withCondition(new DeleteIf(new ConditionalExpression(COL_NAME2, new TextValue(Integer.toString(Integer.MAX_VALUE)), ConditionalExpression.Operator.EQ)));
    assertThatThrownBy(() -> storage.delete(delete)).isInstanceOf(NoMutationException.class);
    // Assert
    Optional<Result> actual = storage.get(new Get(partitionKey, clusteringKey));
    assertThat(actual.isPresent()).isTrue();
}
Also used : TextValue(com.scalar.db.io.TextValue) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 42 with TextValue

use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.

the class DistributedStorageIntegrationTestBase method delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly.

@Test
public void delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly() throws IOException, ExecutionException {
    // Arrange
    List<Put> puts = preparePuts();
    List<Delete> deletes = prepareDeletes();
    storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)));
    deletes.get(0).withCondition(new DeleteIfExists());
    deletes.get(1).withCondition(new DeleteIf(new ConditionalExpression(COL_NAME2, new TextValue("1"), ConditionalExpression.Operator.EQ)));
    // Act
    assertThatCode(() -> storage.delete(Arrays.asList(deletes.get(0), deletes.get(1), deletes.get(2)))).doesNotThrowAnyException();
    // Assert
    List<Result> results = scanAll(new Scan(new Key(COL_NAME1, 0)));
    assertThat(results.size()).isEqualTo(0);
}
Also used : TextValue(com.scalar.db.io.TextValue) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 43 with TextValue

use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.

the class DistributedStorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndMultiplePutWithDifferentConditionsGiven_ShouldStoreProperly.

@Test
public void put_WithReservedKeywordAndMultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() throws IOException, ExecutionException {
    // Arrange
    List<Put> puts = preparePuts();
    storage.put(puts.get(1));
    puts.get(0).withCondition(new PutIfNotExists());
    puts.get(1).withCondition(new PutIf(new ConditionalExpression(columnName2, new TextValue("1"), ConditionalExpression.Operator.EQ)));
    // Act
    assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1)))).doesNotThrowAnyException();
    // Assert
    List<Result> results = scanAll(new Scan(new Key(columnName1, 0)));
    assertThat(results.size()).isEqualTo(2);
    assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(1);
}
Also used : TextValue(com.scalar.db.io.TextValue) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 44 with TextValue

use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.

the class DistributedStorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndSinglePutGiven_ShouldStoreProperly.

@Test
public void put_WithReservedKeywordAndSinglePutGiven_ShouldStoreProperly() throws ExecutionException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    Key partitionKey = new Key(columnName1, pKey);
    Key clusteringKey = new Key(columnName4, cKey);
    Get get = new Get(partitionKey, clusteringKey);
    // Act
    storage.put(puts.get(pKey * 2 + cKey));
    // Assert
    Optional<Result> actual = storage.get(get);
    assertThat(actual.isPresent()).isTrue();
    assertThat(actual.get().getValue(columnName1)).isEqualTo(Optional.of(new IntValue(columnName1, pKey)));
    assertThat(actual.get().getValue(columnName2)).isEqualTo(Optional.of(new TextValue(columnName2, Integer.toString(pKey + cKey))));
    assertThat(actual.get().getValue(columnName3)).isEqualTo(Optional.of(new IntValue(columnName3, pKey + cKey)));
    assertThat(actual.get().getValue(columnName4)).isEqualTo(Optional.of(new IntValue(columnName4, cKey)));
    assertThat(actual.get().getValue(columnName5)).isEqualTo(Optional.of(new BooleanValue(columnName5, cKey % 2 == 0)));
}
Also used : TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 45 with TextValue

use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.

the class DistributedStorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly.

@Test
public void delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly() throws IOException, ExecutionException {
    // Arrange
    List<Put> puts = preparePuts();
    List<Delete> deletes = prepareDeletes();
    storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)));
    deletes.get(0).withCondition(new DeleteIfExists());
    deletes.get(1).withCondition(new DeleteIf(new ConditionalExpression(columnName2, new TextValue("1"), ConditionalExpression.Operator.EQ)));
    // Act
    assertThatCode(() -> storage.delete(Arrays.asList(deletes.get(0), deletes.get(1), deletes.get(2)))).doesNotThrowAnyException();
    // Assert
    List<Result> results = scanAll(new Scan(new Key(columnName1, 0)));
    assertThat(results.size()).isEqualTo(0);
}
Also used : TextValue(com.scalar.db.io.TextValue) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Aggregations

TextValue (com.scalar.db.io.TextValue)89 Key (com.scalar.db.io.Key)60 IntValue (com.scalar.db.io.IntValue)51 Test (org.junit.jupiter.api.Test)47 Test (org.junit.Test)38 BooleanValue (com.scalar.db.io.BooleanValue)36 Put (com.scalar.db.api.Put)27 BigIntValue (com.scalar.db.io.BigIntValue)27 DoubleValue (com.scalar.db.io.DoubleValue)26 BlobValue (com.scalar.db.io.BlobValue)25 FloatValue (com.scalar.db.io.FloatValue)24 Result (com.scalar.db.api.Result)23 ConditionalExpression (com.scalar.db.api.ConditionalExpression)21 Get (com.scalar.db.api.Get)17 Value (com.scalar.db.io.Value)15 DeleteIf (com.scalar.db.api.DeleteIf)11 Delete (com.scalar.db.api.Delete)8 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)8 PutIf (com.scalar.db.api.PutIf)6 PreparedStatement (java.sql.PreparedStatement)6