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();
}
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);
}
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);
}
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)));
}
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);
}
Aggregations