use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class PutTest method withValue_ProperValuesGiven_ShouldReturnWhatsSet.
@Test
public void withValue_ProperValuesGiven_ShouldReturnWhatsSet() {
// Arrange
Put put = preparePut();
// Act
put.withValue("val1", true).withValue("val2", 5678).withValue("val3", 1234L).withValue("val4", 4.56f).withValue("val5", 1.23).withValue("val6", "string_value").withValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)).withValue("val8", ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
// Assert
Map<String, Value<?>> values = put.getValues();
assertThat(values.size()).isEqualTo(8);
assertThat(values.get("val1")).isEqualTo(new BooleanValue("val1", true));
assertThat(values.get("val2")).isEqualTo(new IntValue("val2", 5678));
assertThat(values.get("val3")).isEqualTo(new BigIntValue("val3", 1234L));
assertThat(values.get("val4")).isEqualTo(new FloatValue("val4", 4.56f));
assertThat(values.get("val5")).isEqualTo(new DoubleValue("val5", 1.23));
assertThat(values.get("val6")).isEqualTo(new TextValue("val6", "string_value"));
assertThat(values.get("val7")).isEqualTo(new BlobValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(values.get("val8")).isEqualTo(new BlobValue("val8", "blob_value2".getBytes(StandardCharsets.UTF_8)));
Map<String, Column<?>> columns = put.getColumns();
assertThat(columns.size()).isEqualTo(8);
assertThat(columns.get("val1")).isEqualTo(BooleanColumn.of("val1", true));
assertThat(columns.get("val2")).isEqualTo(IntColumn.of("val2", 5678));
assertThat(columns.get("val3")).isEqualTo(BigIntColumn.of("val3", 1234L));
assertThat(columns.get("val4")).isEqualTo(FloatColumn.of("val4", 4.56f));
assertThat(columns.get("val5")).isEqualTo(DoubleColumn.of("val5", 1.23));
assertThat(columns.get("val6")).isEqualTo(TextColumn.of("val6", "string_value"));
assertThat(columns.get("val7")).isEqualTo(BlobColumn.of("val7", "blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(columns.get("val8")).isEqualTo(BlobColumn.of("val8", "blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getContainedColumnNames()).isEqualTo(ImmutableSet.of("val1", "val2", "val3", "val4", "val5", "val6", "val7", "val8"));
assertThat(put.containsColumn("val1")).isTrue();
assertThat(put.isNullValue("val1")).isFalse();
assertThat(put.getBooleanValue("val1")).isTrue();
assertThat(put.getValueAsObject("val1")).isEqualTo(true);
assertThat(put.containsColumn("val2")).isTrue();
assertThat(put.isNullValue("val2")).isFalse();
assertThat(put.getIntValue("val2")).isEqualTo(5678);
assertThat(put.getValueAsObject("val2")).isEqualTo(5678);
assertThat(put.containsColumn("val3")).isTrue();
assertThat(put.isNullValue("val3")).isFalse();
assertThat(put.getBigIntValue("val3")).isEqualTo(1234L);
assertThat(put.getValueAsObject("val3")).isEqualTo(1234L);
assertThat(put.containsColumn("val4")).isTrue();
assertThat(put.isNullValue("val4")).isFalse();
assertThat(put.getFloatValue("val4")).isEqualTo(4.56f);
assertThat(put.getValueAsObject("val4")).isEqualTo(4.56f);
assertThat(put.containsColumn("val5")).isTrue();
assertThat(put.isNullValue("val5")).isFalse();
assertThat(put.getDoubleValue("val5")).isEqualTo(1.23);
assertThat(put.getValueAsObject("val5")).isEqualTo(1.23);
assertThat(put.containsColumn("val6")).isTrue();
assertThat(put.isNullValue("val6")).isFalse();
assertThat(put.getTextValue("val6")).isEqualTo("string_value");
assertThat(put.getValueAsObject("val6")).isEqualTo("string_value");
assertThat(put.containsColumn("val7")).isTrue();
assertThat(put.isNullValue("val7")).isFalse();
assertThat(put.getBlobValue("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsByteBuffer("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsBytes("val7")).isEqualTo("blob_value".getBytes(StandardCharsets.UTF_8));
assertThat(put.getValueAsObject("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.containsColumn("val8")).isTrue();
assertThat(put.isNullValue("val8")).isFalse();
assertThat(put.getBlobValue("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsByteBuffer("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsBytes("val8")).isEqualTo("blob_value2".getBytes(StandardCharsets.UTF_8));
assertThat(put.getValueAsObject("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class ResultImplTest method getPartitionKey_RequiredValuesGiven_ShouldReturnPartitionKey.
@Test
public void getPartitionKey_RequiredValuesGiven_ShouldReturnPartitionKey() {
// Arrange
ResultImpl result = new ResultImpl(columns, TABLE_METADATA);
// Act
Optional<Key> key = result.getPartitionKey();
// Assert
assertThat(key.isPresent()).isTrue();
assertThat(key.get().get().size()).isEqualTo(1);
assertThat(key.get().get().get(0)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class ResultImplTest method getValues_TryToModifyReturned_ShouldThrowException.
@Test
public void getValues_TryToModifyReturned_ShouldThrowException() {
// Arrange
ResultImpl result = new ResultImpl(columns, TABLE_METADATA);
Map<String, Value<?>> values = result.getValues();
// Act Assert
assertThatThrownBy(() -> values.put("new", new TextValue(ANY_NAME_1, ANY_TEXT_1))).isInstanceOf(UnsupportedOperationException.class);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class ResultImplTest method getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet.
@Test
public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() {
// Arrange
ResultImpl result = new ResultImpl(columns, TABLE_METADATA);
// Act
Map<String, Value<?>> actual = result.getValues();
// Assert
assertThat(actual.get(ANY_NAME_1)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
assertThat(actual.get(ANY_NAME_2)).isEqualTo(new TextValue(ANY_NAME_2, ANY_TEXT_2));
assertThat(actual.get(ANY_COLUMN_NAME_1)).isEqualTo(new BooleanValue(ANY_COLUMN_NAME_1, true));
assertThat(actual.get(ANY_COLUMN_NAME_7)).isEqualTo(new BlobValue(ANY_COLUMN_NAME_7, "bytes".getBytes(StandardCharsets.UTF_8)));
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_MultiplePutWithDifferentConditionsGiven_ShouldStoreProperly.
@Test
public void put_MultiplePutWithDifferentConditionsGiven_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(COL_NAME2, 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(COL_NAME1, 0)));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1);
}
Aggregations