Search in sources :

Example 86 with TextValue

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

the class ResultImplTest method getClusteringKey_NotRequiredValuesGiven_ShouldReturnClusteringKey.

@Test
public void getClusteringKey_NotRequiredValuesGiven_ShouldReturnClusteringKey() {
    // Arrange
    ResultImpl result1 = new ResultImpl(ImmutableMap.<String, Optional<Value<?>>>builder().put(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))).build(), TABLE_METADATA);
    ResultImpl result2 = new ResultImpl(ImmutableMap.<String, Optional<Value<?>>>builder().put(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))).put(ANY_NAME_2, Optional.empty()).build(), TABLE_METADATA);
    // Act
    Optional<Key> key1 = result1.getClusteringKey();
    Optional<Key> key2 = result2.getClusteringKey();
    // Assert
    assertThat(key1).isNotPresent();
    assertThat(key2).isNotPresent();
}
Also used : Optional(java.util.Optional) TextValue(com.scalar.db.io.TextValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) BigIntValue(com.scalar.db.io.BigIntValue) FloatValue(com.scalar.db.io.FloatValue) BlobValue(com.scalar.db.io.BlobValue) BooleanValue(com.scalar.db.io.BooleanValue) Key(com.scalar.db.io.Key) Test(org.junit.Test)

Example 87 with TextValue

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

the class ResultImplTest method getValue_ProperValuesWithNullTextValueAndNullBlobValueGivenInConstructor_ShouldReturnWhatsSet.

@Test
public void getValue_ProperValuesWithNullTextValueAndNullBlobValueGivenInConstructor_ShouldReturnWhatsSet() {
    // Arrange
    ResultImpl result = new ResultImpl(ImmutableMap.<String, Optional<Value<?>>>builder().put(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))).put(ANY_NAME_2, Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_2))).put(ANY_COLUMN_NAME_1, Optional.of(new BooleanValue(ANY_COLUMN_NAME_1, true))).put(ANY_COLUMN_NAME_2, Optional.of(new IntValue(ANY_COLUMN_NAME_2, Integer.MAX_VALUE))).put(ANY_COLUMN_NAME_3, Optional.of(new BigIntValue(ANY_COLUMN_NAME_3, BigIntValue.MAX_VALUE))).put(ANY_COLUMN_NAME_4, Optional.of(new FloatValue(ANY_COLUMN_NAME_4, Float.MAX_VALUE))).put(ANY_COLUMN_NAME_5, Optional.of(new DoubleValue(ANY_COLUMN_NAME_5, Double.MAX_VALUE))).put(ANY_COLUMN_NAME_6, Optional.of(new TextValue(ANY_COLUMN_NAME_6, (String) null))).put(ANY_COLUMN_NAME_7, Optional.of(new BlobValue(ANY_COLUMN_NAME_7, (byte[]) null))).build(), TABLE_METADATA);
    // Act Assert
    assertThat(result.getValue(ANY_NAME_1)).isEqualTo(Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1)));
    assertThat(result.getValue(ANY_NAME_2)).isEqualTo(Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_2)));
    assertThat(result.getValue(ANY_COLUMN_NAME_1)).isEqualTo(Optional.of(new BooleanValue(ANY_COLUMN_NAME_1, true)));
    assertThat(result.getValue(ANY_COLUMN_NAME_2)).isEqualTo(Optional.of(new IntValue(ANY_COLUMN_NAME_2, Integer.MAX_VALUE)));
    assertThat(result.getValue(ANY_COLUMN_NAME_3)).isEqualTo(Optional.of(new BigIntValue(ANY_COLUMN_NAME_3, BigIntValue.MAX_VALUE)));
    assertThat(result.getValue(ANY_COLUMN_NAME_4)).isEqualTo(Optional.of(new FloatValue(ANY_COLUMN_NAME_4, Float.MAX_VALUE)));
    assertThat(result.getValue(ANY_COLUMN_NAME_5)).isEqualTo(Optional.of(new DoubleValue(ANY_COLUMN_NAME_5, Double.MAX_VALUE)));
    assertThat(result.getValue(ANY_COLUMN_NAME_6)).isEqualTo(Optional.of(new TextValue(ANY_COLUMN_NAME_6, (String) null)));
    assertThat(result.getValue(ANY_COLUMN_NAME_7)).isEqualTo(Optional.of(new BlobValue(ANY_COLUMN_NAME_7, (byte[]) null)));
    assertThat(result.getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_COLUMN_NAME_1, ANY_COLUMN_NAME_2, ANY_COLUMN_NAME_3, ANY_COLUMN_NAME_4, ANY_COLUMN_NAME_5, ANY_COLUMN_NAME_6, ANY_COLUMN_NAME_7)));
    assertThat(result.contains(ANY_NAME_1)).isTrue();
    assertThat(result.isNull(ANY_NAME_1)).isFalse();
    assertThat(result.getText(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
    assertThat(result.getAsObject(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
    assertThat(result.contains(ANY_NAME_2)).isTrue();
    assertThat(result.isNull(ANY_NAME_2)).isFalse();
    assertThat(result.getText(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
    assertThat(result.getAsObject(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
    assertThat(result.contains(ANY_COLUMN_NAME_1)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_1)).isFalse();
    assertThat(result.getBoolean(ANY_COLUMN_NAME_1)).isEqualTo(true);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_1)).isEqualTo(true);
    assertThat(result.contains(ANY_COLUMN_NAME_2)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_2)).isFalse();
    assertThat(result.getInt(ANY_COLUMN_NAME_2)).isEqualTo(Integer.MAX_VALUE);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_2)).isEqualTo(Integer.MAX_VALUE);
    assertThat(result.contains(ANY_COLUMN_NAME_3)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_3)).isFalse();
    assertThat(result.getBigInt(ANY_COLUMN_NAME_3)).isEqualTo(BigIntValue.MAX_VALUE);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_3)).isEqualTo(BigIntValue.MAX_VALUE);
    assertThat(result.contains(ANY_COLUMN_NAME_4)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_4)).isFalse();
    assertThat(result.getFloat(ANY_COLUMN_NAME_4)).isEqualTo(Float.MAX_VALUE);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_4)).isEqualTo(Float.MAX_VALUE);
    assertThat(result.contains(ANY_COLUMN_NAME_5)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_5)).isFalse();
    assertThat(result.getDouble(ANY_COLUMN_NAME_5)).isEqualTo(Double.MAX_VALUE);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_5)).isEqualTo(Double.MAX_VALUE);
    assertThat(result.contains(ANY_COLUMN_NAME_6)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_6)).isTrue();
    assertThat(result.getText(ANY_COLUMN_NAME_6)).isNull();
    assertThat(result.getAsObject(ANY_COLUMN_NAME_6)).isNull();
    assertThat(result.contains(ANY_COLUMN_NAME_7)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_7)).isTrue();
    assertThat(result.getBlob(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getBlobAsByteBuffer(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getBlobAsBytes(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getAsObject(ANY_COLUMN_NAME_7)).isNull();
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) 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) BigIntValue(com.scalar.db.io.BigIntValue) FloatValue(com.scalar.db.io.FloatValue) 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) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Example 88 with TextValue

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(values, 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));
}
Also used : TextValue(com.scalar.db.io.TextValue) Key(com.scalar.db.io.Key) Test(org.junit.Test)

Example 89 with TextValue

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

the class SnapshotTest method toSerializableWithExtraRead_MultipleScansInScanSetExist_ShouldThrowCommitConflictException.

@Test
public void toSerializableWithExtraRead_MultipleScansInScanSetExist_ShouldThrowCommitConflictException() throws ExecutionException {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
    Scan scan1 = new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)).withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
    Scan scan2 = new Scan(new Key(ANY_NAME_1, ANY_TEXT_2)).withStart(new Key(ANY_NAME_2, ANY_TEXT_1)).withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
    Result result1 = new TransactionResult(new ResultImpl(ImmutableMap.of(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1)), ANY_NAME_2, Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_2)), Attribute.ID, Optional.of(Attribute.toIdValue("id1")), Attribute.VERSION, Optional.of(Attribute.toVersionValue(ANY_VERSION))), TABLE_METADATA));
    Result result2 = new TransactionResult(new ResultImpl(ImmutableMap.of(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_2)), ANY_NAME_2, Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_1)), Attribute.ID, Optional.of(Attribute.toIdValue("id2")), Attribute.VERSION, Optional.of(Attribute.toVersionValue(ANY_VERSION))), TABLE_METADATA));
    Snapshot.Key key1 = new Snapshot.Key(scan1, result1);
    Snapshot.Key key2 = new Snapshot.Key(scan2, result2);
    snapshot.put(scan1, Collections.singletonList(key1));
    snapshot.put(scan2, Collections.singletonList(key2));
    snapshot.put(key1, Optional.of(new TransactionResult(result1)));
    snapshot.put(key2, Optional.of(new TransactionResult(result2)));
    DistributedStorage storage = mock(DistributedStorage.class);
    Scanner scanner1 = mock(Scanner.class);
    when(scanner1.iterator()).thenReturn(Collections.singletonList(result1).iterator());
    Scan scan1WithProjections = new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)).withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME).withProjection(Attribute.ID).withProjection(Attribute.VERSION);
    when(storage.scan(scan1WithProjections)).thenReturn(scanner1);
    Scanner scanner2 = mock(Scanner.class);
    when(scanner2.iterator()).thenReturn(Collections.singletonList(result2).iterator());
    Scan scan2WithProjections = new Scan(new Key(ANY_NAME_1, ANY_TEXT_2)).withStart(new Key(ANY_NAME_2, ANY_TEXT_1)).withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME).withProjection(Attribute.ID).withProjection(Attribute.VERSION);
    when(storage.scan(scan2WithProjections)).thenReturn(scanner2);
    // Act Assert
    assertThatCode(() -> snapshot.toSerializableWithExtraRead(storage)).doesNotThrowAnyException();
}
Also used : Scanner(com.scalar.db.api.Scanner) DistributedStorage(com.scalar.db.api.DistributedStorage) TextValue(com.scalar.db.io.TextValue) Scan(com.scalar.db.api.Scan) ResultImpl(com.scalar.db.util.ResultImpl) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.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