Search in sources :

Example 21 with Put

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

the class StorageColumnValueIntegrationTestBase method put_WithMaxValues_ShouldPutCorrectly.

@Test
public void put_WithMaxValues_ShouldPutCorrectly() throws ExecutionException {
    // Arrange
    IntValue partitionKeyValue = (IntValue) getMaxValue(PARTITION_KEY, DataType.INT);
    BooleanValue col1Value = (BooleanValue) getMaxValue(COL_NAME1, DataType.BOOLEAN);
    IntValue col2Value = (IntValue) getMaxValue(COL_NAME2, DataType.INT);
    BigIntValue col3Value = (BigIntValue) getMaxValue(COL_NAME3, DataType.BIGINT);
    FloatValue col4Value = (FloatValue) getMaxValue(COL_NAME4, DataType.FLOAT);
    DoubleValue col5Value = (DoubleValue) getMaxValue(COL_NAME5, DataType.DOUBLE);
    TextValue col6Value = (TextValue) getMaxValue(COL_NAME6, DataType.TEXT);
    BlobValue col7Value = (BlobValue) getMaxValue(COL_NAME7, DataType.BLOB);
    Put put = new Put(new Key(partitionKeyValue)).withValue(col1Value).withValue(col2Value).withValue(col3Value).withValue(col4Value).withValue(col5Value).withValue(col6Value).withValue(col7Value).forNamespace(namespace).forTable(TABLE);
    // Act
    storage.put(put);
    // Assert
    Optional<Result> actual = storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE));
    assertThat(actual).isPresent();
    assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue();
    assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue);
    assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value);
    assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value);
    assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value);
    assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value);
    assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value);
    assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value);
    assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value);
    assertThat(actual.get().getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(PARTITION_KEY, COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7)));
    assertThat(actual.get().contains(PARTITION_KEY)).isTrue();
    assertThat(actual.get().isNull(PARTITION_KEY)).isFalse();
    assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
    assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
    assertThat(actual.get().contains(COL_NAME1)).isTrue();
    assertThat(actual.get().isNull(COL_NAME1)).isFalse();
    assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get());
    assertThat(actual.get().getAsObject(COL_NAME1)).isEqualTo(col1Value.get());
    assertThat(actual.get().contains(COL_NAME2)).isTrue();
    assertThat(actual.get().isNull(COL_NAME2)).isFalse();
    assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get());
    assertThat(actual.get().getAsObject(COL_NAME2)).isEqualTo(col2Value.get());
    assertThat(actual.get().contains(COL_NAME3)).isTrue();
    assertThat(actual.get().isNull(COL_NAME3)).isFalse();
    assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get());
    assertThat(actual.get().getAsObject(COL_NAME3)).isEqualTo(col3Value.get());
    assertThat(actual.get().contains(COL_NAME4)).isTrue();
    assertThat(actual.get().isNull(COL_NAME4)).isFalse();
    assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get());
    assertThat(actual.get().getAsObject(COL_NAME4)).isEqualTo(col4Value.get());
    assertThat(actual.get().contains(COL_NAME5)).isTrue();
    assertThat(actual.get().isNull(COL_NAME5)).isFalse();
    assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get());
    assertThat(actual.get().getAsObject(COL_NAME5)).isEqualTo(col5Value.get());
    assertThat(actual.get().contains(COL_NAME6)).isTrue();
    assertThat(actual.get().isNull(COL_NAME6)).isFalse();
    assertThat(actual.get().getText(COL_NAME6)).isEqualTo(col6Value.get().get());
    assertThat(actual.get().getAsObject(COL_NAME6)).isEqualTo(col6Value.get().get());
    assertThat(actual.get().contains(COL_NAME7)).isTrue();
    assertThat(actual.get().isNull(COL_NAME7)).isFalse();
    assertThat(actual.get().getBlob(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
    assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
    assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.get().get());
    assertThat(actual.get().getAsObject(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
}
Also used : Put(com.scalar.db.api.Put) BlobValue(com.scalar.db.io.BlobValue) Result(com.scalar.db.api.Result) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) Get(com.scalar.db.api.Get) FloatValue(com.scalar.db.io.FloatValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) Key(com.scalar.db.io.Key) BigIntValue(com.scalar.db.io.BigIntValue) Test(org.junit.Test)

Example 22 with Put

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

the class StorageColumnValueIntegrationTestBase method put_WithNullValues_AfterPuttingRandomValues_ShouldPutCorrectly.

@Test
public void put_WithNullValues_AfterPuttingRandomValues_ShouldPutCorrectly() throws ExecutionException {
    // Arrange
    IntValue partitionKeyValue = new IntValue(PARTITION_KEY, 1);
    BooleanValue col1Value = new BooleanValue(COL_NAME1, false);
    IntValue col2Value = new IntValue(COL_NAME2, 0);
    BigIntValue col3Value = new BigIntValue(COL_NAME3, 0L);
    FloatValue col4Value = new FloatValue(COL_NAME4, 0.0f);
    DoubleValue col5Value = new DoubleValue(COL_NAME5, 0.0d);
    TextValue col6Value = new TextValue(COL_NAME6, (String) null);
    BlobValue col7Value = new BlobValue(COL_NAME7, (byte[]) null);
    Put putForRandomValues = new Put(new Key(partitionKeyValue)).withValue(getRandomValue(RANDOM, COL_NAME1, DataType.BOOLEAN)).withValue(getRandomValue(RANDOM, COL_NAME2, DataType.INT)).withValue(getRandomValue(RANDOM, COL_NAME3, DataType.BIGINT)).withValue(getRandomValue(RANDOM, COL_NAME4, DataType.FLOAT)).withValue(getRandomValue(RANDOM, COL_NAME5, DataType.DOUBLE)).withValue(getRandomValue(RANDOM, COL_NAME6, DataType.TEXT)).withValue(getRandomValue(RANDOM, COL_NAME7, DataType.BLOB)).forNamespace(namespace).forTable(TABLE);
    Put putForNullValues = new Put(new Key(partitionKeyValue)).withNullValue(COL_NAME1).withNullValue(COL_NAME2).withNullValue(COL_NAME3).withNullValue(COL_NAME4).withNullValue(COL_NAME5).withNullValue(COL_NAME6).withNullValue(COL_NAME7).forNamespace(namespace).forTable(TABLE);
    // Act
    storage.put(putForRandomValues);
    storage.put(putForNullValues);
    // Assert
    Optional<Result> actual = storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE));
    assertThat(actual).isPresent();
    assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue();
    assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue);
    assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value);
    assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value);
    assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value);
    assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value);
    assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value);
    assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value);
    assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value);
    assertThat(actual.get().getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(PARTITION_KEY, COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7)));
    assertThat(actual.get().contains(PARTITION_KEY)).isTrue();
    assertThat(actual.get().isNull(PARTITION_KEY)).isFalse();
    assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
    assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
    assertThat(actual.get().contains(COL_NAME1)).isTrue();
    assertThat(actual.get().isNull(COL_NAME1)).isTrue();
    assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get());
    assertThat(actual.get().getAsObject(COL_NAME1)).isNull();
    assertThat(actual.get().contains(COL_NAME2)).isTrue();
    assertThat(actual.get().isNull(COL_NAME2)).isTrue();
    assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get());
    assertThat(actual.get().getAsObject(COL_NAME2)).isNull();
    assertThat(actual.get().contains(COL_NAME3)).isTrue();
    assertThat(actual.get().isNull(COL_NAME3)).isTrue();
    assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get());
    assertThat(actual.get().getAsObject(COL_NAME3)).isNull();
    assertThat(actual.get().contains(COL_NAME4)).isTrue();
    assertThat(actual.get().isNull(COL_NAME4)).isTrue();
    assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get());
    assertThat(actual.get().getAsObject(COL_NAME4)).isNull();
    assertThat(actual.get().contains(COL_NAME5)).isTrue();
    assertThat(actual.get().isNull(COL_NAME5)).isTrue();
    assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get());
    assertThat(actual.get().getAsObject(COL_NAME5)).isNull();
    assertThat(actual.get().contains(COL_NAME6)).isTrue();
    assertThat(actual.get().isNull(COL_NAME6)).isTrue();
    assertThat(actual.get().getText(COL_NAME6)).isNull();
    assertThat(actual.get().getAsObject(COL_NAME6)).isNull();
    assertThat(actual.get().contains(COL_NAME7)).isTrue();
    assertThat(actual.get().isNull(COL_NAME7)).isTrue();
    assertThat(actual.get().getBlob(COL_NAME7)).isNull();
    assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isNull();
    assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isNull();
    assertThat(actual.get().getAsObject(COL_NAME7)).isNull();
}
Also used : Put(com.scalar.db.api.Put) BlobValue(com.scalar.db.io.BlobValue) Result(com.scalar.db.api.Result) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) Get(com.scalar.db.api.Get) FloatValue(com.scalar.db.io.FloatValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) Key(com.scalar.db.io.Key) BigIntValue(com.scalar.db.io.BigIntValue) Test(org.junit.Test)

Example 23 with Put

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

the class StorageColumnValueIntegrationTestBase method put_WithMinValues_ShouldPutCorrectly.

@Test
public void put_WithMinValues_ShouldPutCorrectly() throws ExecutionException {
    // Arrange
    IntValue partitionKeyValue = (IntValue) getMinValue(PARTITION_KEY, DataType.INT);
    BooleanValue col1Value = (BooleanValue) getMinValue(COL_NAME1, DataType.BOOLEAN);
    IntValue col2Value = (IntValue) getMinValue(COL_NAME2, DataType.INT);
    BigIntValue col3Value = (BigIntValue) getMinValue(COL_NAME3, DataType.BIGINT);
    FloatValue col4Value = (FloatValue) getMinValue(COL_NAME4, DataType.FLOAT);
    DoubleValue col5Value = (DoubleValue) getMinValue(COL_NAME5, DataType.DOUBLE);
    TextValue col6Value = (TextValue) getMinValue(COL_NAME6, DataType.TEXT);
    BlobValue col7Value = (BlobValue) getMinValue(COL_NAME7, DataType.BLOB);
    Put put = new Put(new Key(partitionKeyValue)).withValue(col1Value).withValue(col2Value).withValue(col3Value).withValue(col4Value).withValue(col5Value).withValue(col6Value).withValue(col7Value).forNamespace(namespace).forTable(TABLE);
    // Act
    storage.put(put);
    // Assert
    Optional<Result> actual = storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE));
    assertThat(actual).isPresent();
    assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue();
    assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue);
    assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value);
    assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value);
    assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value);
    assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value);
    assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value);
    assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value);
    assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value);
    assertThat(actual.get().getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(PARTITION_KEY, COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7)));
    assertThat(actual.get().contains(PARTITION_KEY)).isTrue();
    assertThat(actual.get().isNull(PARTITION_KEY)).isFalse();
    assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
    assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
    assertThat(actual.get().contains(COL_NAME1)).isTrue();
    assertThat(actual.get().isNull(COL_NAME1)).isFalse();
    assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get());
    assertThat(actual.get().getAsObject(COL_NAME1)).isEqualTo(col1Value.get());
    assertThat(actual.get().contains(COL_NAME2)).isTrue();
    assertThat(actual.get().isNull(COL_NAME2)).isFalse();
    assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get());
    assertThat(actual.get().getAsObject(COL_NAME2)).isEqualTo(col2Value.get());
    assertThat(actual.get().contains(COL_NAME3)).isTrue();
    assertThat(actual.get().isNull(COL_NAME3)).isFalse();
    assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get());
    assertThat(actual.get().getAsObject(COL_NAME3)).isEqualTo(col3Value.get());
    assertThat(actual.get().contains(COL_NAME4)).isTrue();
    assertThat(actual.get().isNull(COL_NAME4)).isFalse();
    assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get());
    assertThat(actual.get().getAsObject(COL_NAME4)).isEqualTo(col4Value.get());
    assertThat(actual.get().contains(COL_NAME5)).isTrue();
    assertThat(actual.get().isNull(COL_NAME5)).isFalse();
    assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get());
    assertThat(actual.get().getAsObject(COL_NAME5)).isEqualTo(col5Value.get());
    assertThat(actual.get().contains(COL_NAME6)).isTrue();
    assertThat(actual.get().isNull(COL_NAME6)).isFalse();
    assertThat(actual.get().getText(COL_NAME6)).isEqualTo(col6Value.get().get());
    assertThat(actual.get().getAsObject(COL_NAME6)).isEqualTo(col6Value.get().get());
    assertThat(actual.get().contains(COL_NAME7)).isTrue();
    assertThat(actual.get().isNull(COL_NAME7)).isFalse();
    assertThat(actual.get().getBlob(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
    assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
    assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.get().get());
    assertThat(actual.get().getAsObject(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
}
Also used : Put(com.scalar.db.api.Put) BlobValue(com.scalar.db.io.BlobValue) Result(com.scalar.db.api.Result) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) Get(com.scalar.db.api.Get) FloatValue(com.scalar.db.io.FloatValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) Key(com.scalar.db.io.Key) BigIntValue(com.scalar.db.io.BigIntValue) Test(org.junit.Test)

Example 24 with Put

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

the class StorageColumnValueIntegrationTestBase method put_WithRandomValues_ShouldPutCorrectly.

@Test
public void put_WithRandomValues_ShouldPutCorrectly() throws ExecutionException {
    RANDOM.setSeed(seed);
    for (int i = 0; i < ATTEMPT_COUNT; i++) {
        // Arrange
        IntValue partitionKeyValue = (IntValue) getRandomValue(RANDOM, PARTITION_KEY, DataType.INT);
        BooleanValue col1Value = (BooleanValue) getRandomValue(RANDOM, COL_NAME1, DataType.BOOLEAN);
        IntValue col2Value = (IntValue) getRandomValue(RANDOM, COL_NAME2, DataType.INT);
        BigIntValue col3Value = (BigIntValue) getRandomValue(RANDOM, COL_NAME3, DataType.BIGINT);
        FloatValue col4Value = (FloatValue) getRandomValue(RANDOM, COL_NAME4, DataType.FLOAT);
        DoubleValue col5Value = (DoubleValue) getRandomValue(RANDOM, COL_NAME5, DataType.DOUBLE);
        TextValue col6Value = (TextValue) getRandomValue(RANDOM, COL_NAME6, DataType.TEXT);
        BlobValue col7Value = (BlobValue) getRandomValue(RANDOM, COL_NAME7, DataType.BLOB);
        Put put = new Put(new Key(partitionKeyValue)).withValue(col1Value).withValue(col2Value).withValue(col3Value).withValue(col4Value).withValue(col5Value).withValue(col6Value).withValue(col7Value).forNamespace(namespace).forTable(TABLE);
        // Act
        storage.put(put);
        // Assert
        Optional<Result> actual = storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE));
        assertThat(actual).isPresent();
        assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue();
        assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue);
        assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue();
        assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value);
        assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue();
        assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value);
        assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue();
        assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value);
        assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
        assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value);
        assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue();
        assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value);
        assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue();
        assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value);
        assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue();
        assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value);
        assertThat(actual.get().getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(PARTITION_KEY, COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7)));
        assertThat(actual.get().contains(PARTITION_KEY)).isTrue();
        assertThat(actual.get().isNull(PARTITION_KEY)).isFalse();
        assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
        assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
        assertThat(actual.get().contains(COL_NAME1)).isTrue();
        assertThat(actual.get().isNull(COL_NAME1)).isFalse();
        assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get());
        assertThat(actual.get().getAsObject(COL_NAME1)).isEqualTo(col1Value.get());
        assertThat(actual.get().contains(COL_NAME2)).isTrue();
        assertThat(actual.get().isNull(COL_NAME2)).isFalse();
        assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get());
        assertThat(actual.get().getAsObject(COL_NAME2)).isEqualTo(col2Value.get());
        assertThat(actual.get().contains(COL_NAME3)).isTrue();
        assertThat(actual.get().isNull(COL_NAME3)).isFalse();
        assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get());
        assertThat(actual.get().getAsObject(COL_NAME3)).isEqualTo(col3Value.get());
        assertThat(actual.get().contains(COL_NAME4)).isTrue();
        assertThat(actual.get().isNull(COL_NAME4)).isFalse();
        assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get());
        assertThat(actual.get().getAsObject(COL_NAME4)).isEqualTo(col4Value.get());
        assertThat(actual.get().contains(COL_NAME5)).isTrue();
        assertThat(actual.get().isNull(COL_NAME5)).isFalse();
        assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get());
        assertThat(actual.get().getAsObject(COL_NAME5)).isEqualTo(col5Value.get());
        assertThat(actual.get().contains(COL_NAME6)).isTrue();
        assertThat(actual.get().isNull(COL_NAME6)).isFalse();
        assertThat(actual.get().getText(COL_NAME6)).isEqualTo(col6Value.get().get());
        assertThat(actual.get().getAsObject(COL_NAME6)).isEqualTo(col6Value.get().get());
        assertThat(actual.get().contains(COL_NAME7)).isTrue();
        assertThat(actual.get().isNull(COL_NAME7)).isFalse();
        assertThat(actual.get().getBlob(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
        assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
        assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.get().get());
        assertThat(actual.get().getAsObject(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
    }
}
Also used : Put(com.scalar.db.api.Put) BlobValue(com.scalar.db.io.BlobValue) Result(com.scalar.db.api.Result) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) Get(com.scalar.db.api.Get) FloatValue(com.scalar.db.io.FloatValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) Key(com.scalar.db.io.Key) BigIntValue(com.scalar.db.io.BigIntValue) Test(org.junit.Test)

Example 25 with Put

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

the class PutStatementHandler method handle.

@Nonnull
@Override
public List<Map<String, AttributeValue>> handle(Operation operation) throws ExecutionException {
    checkArgument(operation, Put.class);
    Put put = (Put) operation;
    TableMetadata tableMetadata = metadataManager.getTableMetadata(operation);
    try {
        execute(put, tableMetadata);
    } catch (ConditionalCheckFailedException e) {
        throw new NoMutationException("no mutation was applied.", e);
    } catch (TransactionConflictException e) {
        throw new RetriableExecutionException(e.getMessage(), e);
    } catch (DynamoDbException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
    return Collections.emptyList();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) TransactionConflictException(software.amazon.awssdk.services.dynamodb.model.TransactionConflictException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) ExecutionException(com.scalar.db.exception.storage.ExecutionException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) ConditionalCheckFailedException(software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException) NoMutationException(com.scalar.db.exception.storage.NoMutationException) Put(com.scalar.db.api.Put) Nonnull(javax.annotation.Nonnull)

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