Search in sources :

Example 6 with ResultImpl

use of com.scalar.db.common.ResultImpl in project scalardb by scalar-labs.

the class TransactionResultTest method equals_ResultImplWithDifferentValuesGiven_ShouldReturnFalse.

@Test
public void equals_ResultImplWithDifferentValuesGiven_ShouldReturnFalse() {
    // Arrange
    Result r1 = new ResultImpl(ImmutableMap.<String, Column<?>>builder().put(ANY_NAME_1, TextColumn.of(ANY_NAME_1, ANY_TEXT_1)).put(ANY_NAME_2, TextColumn.of(ANY_NAME_2, ANY_TEXT_2)).put(ANY_NAME_3, IntColumn.of(ANY_NAME_3, ANY_INT_2)).put(Attribute.ID, ScalarDbUtils.toColumn(Attribute.toIdValue(ANY_ID_2))).put(Attribute.PREPARED_AT, ScalarDbUtils.toColumn(Attribute.toPreparedAtValue(ANY_TIME_3))).put(Attribute.COMMITTED_AT, ScalarDbUtils.toColumn(Attribute.toCommittedAtValue(ANY_TIME_4))).put(Attribute.STATE, ScalarDbUtils.toColumn(Attribute.toStateValue(TransactionState.COMMITTED))).put(Attribute.VERSION, ScalarDbUtils.toColumn(Attribute.toVersionValue(ANY_VERSION_2))).put(Attribute.BEFORE_PREFIX + ANY_NAME_3, IntColumn.of(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_1)).put(Attribute.BEFORE_ID, ScalarDbUtils.toColumn(Attribute.toBeforeIdValue(ANY_ID_1))).put(Attribute.BEFORE_PREPARED_AT, ScalarDbUtils.toColumn(Attribute.toBeforePreparedAtValue(ANY_TIME_1))).put(Attribute.BEFORE_COMMITTED_AT, ScalarDbUtils.toColumn(Attribute.toBeforeCommittedAtValue(ANY_TIME_2))).put(Attribute.BEFORE_STATE, ScalarDbUtils.toColumn(Attribute.toBeforeStateValue(TransactionState.COMMITTED))).put(Attribute.BEFORE_VERSION, ScalarDbUtils.toColumn(Attribute.toBeforeVersionValue(ANY_VERSION_1))).build(), TABLE_METADATA);
    Map<String, Column<?>> emptyValues = Collections.emptyMap();
    Result r2 = new TransactionResult(new ResultImpl(emptyValues, TABLE_METADATA));
    // Act Assert
    assertThat(r1.equals(r2)).isFalse();
}
Also used : IntColumn(com.scalar.db.io.IntColumn) Column(com.scalar.db.io.Column) TextColumn(com.scalar.db.io.TextColumn) ResultImpl(com.scalar.db.common.ResultImpl) Result(com.scalar.db.api.Result) Test(org.junit.jupiter.api.Test)

Example 7 with ResultImpl

use of com.scalar.db.common.ResultImpl in project scalardb by scalar-labs.

the class TransactionResultTest method equals_ResultImplWithSameValuesGiven_ShouldReturnTrue.

@Test
public void equals_ResultImplWithSameValuesGiven_ShouldReturnTrue() {
    // Arrange
    Result r1 = new ResultImpl(ImmutableMap.<String, Column<?>>builder().put(ANY_NAME_1, TextColumn.of(ANY_NAME_1, ANY_TEXT_1)).put(ANY_NAME_2, TextColumn.of(ANY_NAME_2, ANY_TEXT_2)).put(ANY_NAME_3, IntColumn.of(ANY_NAME_3, ANY_INT_2)).put(Attribute.ID, ScalarDbUtils.toColumn(Attribute.toIdValue(ANY_ID_2))).put(Attribute.PREPARED_AT, ScalarDbUtils.toColumn(Attribute.toPreparedAtValue(ANY_TIME_3))).put(Attribute.COMMITTED_AT, ScalarDbUtils.toColumn(Attribute.toCommittedAtValue(ANY_TIME_4))).put(Attribute.STATE, ScalarDbUtils.toColumn(Attribute.toStateValue(TransactionState.COMMITTED))).put(Attribute.VERSION, ScalarDbUtils.toColumn(Attribute.toVersionValue(ANY_VERSION_2))).put(Attribute.BEFORE_PREFIX + ANY_NAME_3, IntColumn.of(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_1)).put(Attribute.BEFORE_ID, ScalarDbUtils.toColumn(Attribute.toBeforeIdValue(ANY_ID_1))).put(Attribute.BEFORE_PREPARED_AT, ScalarDbUtils.toColumn(Attribute.toBeforePreparedAtValue(ANY_TIME_1))).put(Attribute.BEFORE_COMMITTED_AT, ScalarDbUtils.toColumn(Attribute.toBeforeCommittedAtValue(ANY_TIME_2))).put(Attribute.BEFORE_STATE, ScalarDbUtils.toColumn(Attribute.toBeforeStateValue(TransactionState.COMMITTED))).put(Attribute.BEFORE_VERSION, ScalarDbUtils.toColumn(Attribute.toBeforeVersionValue(ANY_VERSION_1))).build(), TABLE_METADATA);
    Result r2 = new TransactionResult(r1);
    // Act Assert
    assertThat(r1.equals(r2)).isTrue();
}
Also used : IntColumn(com.scalar.db.io.IntColumn) Column(com.scalar.db.io.Column) TextColumn(com.scalar.db.io.TextColumn) ResultImpl(com.scalar.db.common.ResultImpl) Result(com.scalar.db.api.Result) Test(org.junit.jupiter.api.Test)

Example 8 with ResultImpl

use of com.scalar.db.common.ResultImpl in project scalardb by scalar-labs.

the class FilteredResultTest method equals_ResultImplWithSameValuesGiven_WithoutProjections_ShouldReturnTrue.

@Test
public void equals_ResultImplWithSameValuesGiven_WithoutProjections_ShouldReturnTrue() {
    // Arrange
    Result filteredResult = new FilteredResult(result, Collections.emptyList(), TABLE_METADATA);
    Result anotherResult = new ResultImpl(ImmutableMap.of(ACCOUNT_ID, ScalarDbUtils.toColumn(ACCOUNT_ID_VALUE), ACCOUNT_TYPE, ScalarDbUtils.toColumn(ACCOUNT_TYPE_VALUE), BALANCE, ScalarDbUtils.toColumn(BALANCE_VALUE)), TABLE_METADATA);
    // Act
    boolean isEqual = filteredResult.equals(anotherResult);
    // Assert
    assertThat(isEqual).isTrue();
}
Also used : ResultImpl(com.scalar.db.common.ResultImpl) Result(com.scalar.db.api.Result) Test(org.junit.jupiter.api.Test)

Example 9 with ResultImpl

use of com.scalar.db.common.ResultImpl in project scalardb by scalar-labs.

the class MergedResultTest method equals_ResultImplWithSamePutAndResultGiven_ShouldReturnTrue.

@Test
public void equals_ResultImplWithSamePutAndResultGiven_ShouldReturnTrue() {
    // Arrange
    Put put = new Put(new Key(ANY_NAME_1, ANY_TEXT_1), new Key(ANY_NAME_2, ANY_TEXT_2)).withValue(ANY_NAME_3, ANY_INT_3);
    MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA);
    Result another = new ResultImpl(ImmutableMap.<String, Column<?>>builder().put(ANY_NAME_1, TextColumn.of(ANY_NAME_1, ANY_TEXT_1)).put(ANY_NAME_2, TextColumn.of(ANY_NAME_2, ANY_TEXT_2)).put(ANY_NAME_3, IntColumn.of(ANY_NAME_3, ANY_INT_3)).put(ANY_NAME_4, TextColumn.of(ANY_NAME_4, ANY_TEXT_3)).put(Attribute.ID, ScalarDbUtils.toColumn(Attribute.toIdValue(ANY_ID_2))).put(Attribute.PREPARED_AT, ScalarDbUtils.toColumn(Attribute.toPreparedAtValue(ANY_TIME_3))).put(Attribute.COMMITTED_AT, ScalarDbUtils.toColumn(Attribute.toCommittedAtValue(ANY_TIME_4))).put(Attribute.STATE, ScalarDbUtils.toColumn(Attribute.toStateValue(TransactionState.COMMITTED))).put(Attribute.VERSION, ScalarDbUtils.toColumn(Attribute.toVersionValue(ANY_VERSION_2))).put(Attribute.BEFORE_PREFIX + ANY_NAME_3, IntColumn.of(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_1)).put(Attribute.BEFORE_PREFIX + ANY_NAME_4, TextColumn.of(Attribute.BEFORE_PREFIX + ANY_NAME_4, ANY_TEXT_4)).put(Attribute.BEFORE_ID, ScalarDbUtils.toColumn(Attribute.toBeforeIdValue(ANY_ID_1))).put(Attribute.BEFORE_PREPARED_AT, ScalarDbUtils.toColumn(Attribute.toBeforePreparedAtValue(ANY_TIME_1))).put(Attribute.BEFORE_COMMITTED_AT, ScalarDbUtils.toColumn(Attribute.toBeforeCommittedAtValue(ANY_TIME_2))).put(Attribute.BEFORE_STATE, ScalarDbUtils.toColumn(Attribute.toBeforeStateValue(TransactionState.COMMITTED))).put(Attribute.BEFORE_VERSION, ScalarDbUtils.toColumn(Attribute.toBeforeVersionValue(ANY_VERSION_1))).build(), TABLE_METADATA);
    // Act Assert
    assertThat(mergedResult.equals(another)).isTrue();
}
Also used : IntColumn(com.scalar.db.io.IntColumn) Column(com.scalar.db.io.Column) TextColumn(com.scalar.db.io.TextColumn) ResultImpl(com.scalar.db.common.ResultImpl) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.jupiter.api.Test)

Example 10 with ResultImpl

use of com.scalar.db.common.ResultImpl in project scalardb by scalar-labs.

the class MergedResultTest method equals_ResultImplWithDifferentPutAndResultGiven_ShouldReturnFalse.

@Test
public void equals_ResultImplWithDifferentPutAndResultGiven_ShouldReturnFalse() {
    // Arrange
    Put put = new Put(new Key(ANY_NAME_1, ANY_TEXT_1), new Key(ANY_NAME_2, ANY_TEXT_2)).withValue(ANY_NAME_3, ANY_INT_3);
    MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA);
    Result another = new ResultImpl(Collections.emptyMap(), TABLE_METADATA);
    // Act Assert
    assertThat(mergedResult.equals(another)).isFalse();
}
Also used : ResultImpl(com.scalar.db.common.ResultImpl) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.jupiter.api.Test)

Aggregations

ResultImpl (com.scalar.db.common.ResultImpl)10 Test (org.junit.jupiter.api.Test)9 Result (com.scalar.db.api.Result)8 Column (com.scalar.db.io.Column)5 Key (com.scalar.db.io.Key)4 TextColumn (com.scalar.db.io.TextColumn)4 IntColumn (com.scalar.db.io.IntColumn)3 Put (com.scalar.db.api.Put)2 Scan (com.scalar.db.api.Scan)2 Delete (com.scalar.db.api.Delete)1 DistributedStorage (com.scalar.db.api.DistributedStorage)1 Scanner (com.scalar.db.api.Scanner)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1