Search in sources :

Example 86 with IntValue

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

the class OperationCheckerTest method whenCheckingPutOperationWithInvalidPutIfConditionWithIsNull_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithInvalidPutIfConditionWithIsNull_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
    MutationCondition condition = ConditionBuilder.putIf(ConditionBuilder.buildConditionalExpression(IntColumn.of(COL1, 1), Operator.IS_NULL)).build();
    Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) MutationCondition(com.scalar.db.api.MutationCondition) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 87 with IntValue

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

the class OperationCheckerTest method whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
    MutationCondition condition = new DeleteIf();
    Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) MutationCondition(com.scalar.db.api.MutationCondition) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) DeleteIf(com.scalar.db.api.DeleteIf) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 88 with IntValue

use of com.scalar.db.io.IntValue 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)));
}
Also used : BlobValue(com.scalar.db.io.BlobValue) DoubleValue(com.scalar.db.io.DoubleValue) IntColumn(com.scalar.db.io.IntColumn) BooleanColumn(com.scalar.db.io.BooleanColumn) TextColumn(com.scalar.db.io.TextColumn) DoubleColumn(com.scalar.db.io.DoubleColumn) BigIntColumn(com.scalar.db.io.BigIntColumn) FloatColumn(com.scalar.db.io.FloatColumn) Column(com.scalar.db.io.Column) BlobColumn(com.scalar.db.io.BlobColumn) TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) FloatValue(com.scalar.db.io.FloatValue) BigIntValue(com.scalar.db.io.BigIntValue) BlobValue(com.scalar.db.io.BlobValue) BooleanValue(com.scalar.db.io.BooleanValue) FloatValue(com.scalar.db.io.FloatValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) BigIntValue(com.scalar.db.io.BigIntValue) Test(org.junit.jupiter.api.Test)

Example 89 with IntValue

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

the class ConsensusCommitSpecificIntegrationTestBase method putAndCommit_TwoPartitionsMutationsGiven_ShouldAccessStorageTwiceForPrepareAndCommit.

@Test
public void putAndCommit_TwoPartitionsMutationsGiven_ShouldAccessStorageTwiceForPrepareAndCommit() throws CommitException, UnknownTransactionStatusException, ExecutionException, CoordinatorException {
    // Arrange
    IntValue balance = new IntValue(BALANCE, INITIAL_BALANCE);
    List<Put> puts = preparePuts(namespace1, TABLE_1);
    puts.get(0).withValue(balance);
    // next account
    puts.get(NUM_TYPES).withValue(balance);
    ConsensusCommit transaction = manager.start();
    // Act
    transaction.put(puts.get(0));
    transaction.put(puts.get(NUM_TYPES));
    transaction.commit();
    // Assert
    // twice for prepare, twice for commit
    verify(storage, times(4)).mutate(anyList());
    verify(coordinator).putState(any(Coordinator.State.class));
}
Also used : TransactionState(com.scalar.db.api.TransactionState) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 90 with IntValue

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

the class ConsensusCommitSpecificIntegrationTestBase method putAndCommit_SinglePartitionMutationsGiven_ShouldAccessStorageOnceForPrepareAndCommit.

@Test
public void putAndCommit_SinglePartitionMutationsGiven_ShouldAccessStorageOnceForPrepareAndCommit() throws CommitException, UnknownTransactionStatusException, ExecutionException, CoordinatorException {
    // Arrange
    IntValue balance = new IntValue(BALANCE, INITIAL_BALANCE);
    List<Put> puts = preparePuts(namespace1, TABLE_1);
    puts.get(0).withValue(balance);
    puts.get(1).withValue(balance);
    ConsensusCommit transaction = manager.start();
    // Act
    transaction.put(puts.get(0));
    transaction.put(puts.get(1));
    transaction.commit();
    // Assert
    // one for prepare, one for commit
    verify(storage, times(2)).mutate(anyList());
    verify(coordinator).putState(any(Coordinator.State.class));
}
Also used : TransactionState(com.scalar.db.api.TransactionState) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Aggregations

IntValue (com.scalar.db.io.IntValue)108 Test (org.junit.jupiter.api.Test)65 TextValue (com.scalar.db.io.TextValue)63 Key (com.scalar.db.io.Key)62 Put (com.scalar.db.api.Put)55 BooleanValue (com.scalar.db.io.BooleanValue)48 DoubleValue (com.scalar.db.io.DoubleValue)38 Result (com.scalar.db.api.Result)35 Test (org.junit.Test)33 Get (com.scalar.db.api.Get)29 Value (com.scalar.db.io.Value)26 BigIntValue (com.scalar.db.io.BigIntValue)23 BlobValue (com.scalar.db.io.BlobValue)20 FloatValue (com.scalar.db.io.FloatValue)19 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)15 ConditionalExpression (com.scalar.db.api.ConditionalExpression)13 MutationCondition (com.scalar.db.api.MutationCondition)12 PutIf (com.scalar.db.api.PutIf)8 TransactionState (com.scalar.db.api.TransactionState)8 DeleteIf (com.scalar.db.api.DeleteIf)6