Search in sources :

Example 11 with DistributedStorage

use of com.scalar.db.api.DistributedStorage 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

DistributedStorage (com.scalar.db.api.DistributedStorage)11 Put (com.scalar.db.api.Put)7 Test (org.junit.jupiter.api.Test)7 Scan (com.scalar.db.api.Scan)6 Scanner (com.scalar.db.api.Scanner)6 Key (com.scalar.db.io.Key)4 Get (com.scalar.db.api.Get)3 Result (com.scalar.db.api.Result)2 Test (org.junit.Test)2 ResultImpl (com.scalar.db.common.ResultImpl)1 TextValue (com.scalar.db.io.TextValue)1 AbstractDistributedStorage (com.scalar.db.storage.common.AbstractDistributedStorage)1 ResultImpl (com.scalar.db.util.ResultImpl)1 HashMap (java.util.HashMap)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1