Search in sources :

Example 1 with DistributedStorage

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

the class MultiStorageTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    MockitoAnnotations.openMocks(this).close();
    // Arrange
    Map<String, DistributedStorage> tableStorageMap = new HashMap<>();
    tableStorageMap.put(NAMESPACE1 + "." + TABLE1, storage1);
    tableStorageMap.put(NAMESPACE1 + "." + TABLE2, storage2);
    Map<String, DistributedStorage> namespaceStorageMap = new HashMap<>();
    namespaceStorageMap.put(NAMESPACE2, storage2);
    DistributedStorage defaultStorage = storage3;
    multiStorage = new MultiStorage(tableStorageMap, namespaceStorageMap, defaultStorage);
}
Also used : DistributedStorage(com.scalar.db.api.DistributedStorage) HashMap(java.util.HashMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with DistributedStorage

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

the class SnapshotTest method toSerializableWithExtraRead_ReadSetNotChanged_ShouldProcessWithoutExceptions.

@Test
public void toSerializableWithExtraRead_ReadSetNotChanged_ShouldProcessWithoutExceptions() throws ExecutionException {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
    Get get = prepareAnotherGet();
    Put put = preparePut();
    TransactionResult result = prepareResult(ANY_ID);
    TransactionResult txResult = new TransactionResult(result);
    snapshot.put(new Snapshot.Key(get), Optional.of(txResult));
    snapshot.put(new Snapshot.Key(put), put);
    DistributedStorage storage = mock(DistributedStorage.class);
    Get getWithProjections = prepareAnotherGet().withProjection(Attribute.ID).withProjection(Attribute.VERSION);
    when(storage.get(getWithProjections)).thenReturn(Optional.of(txResult));
    // Act Assert
    assertThatCode(() -> snapshot.toSerializableWithExtraRead(storage)).doesNotThrowAnyException();
    // Assert
    verify(storage).get(getWithProjections);
}
Also used : DistributedStorage(com.scalar.db.api.DistributedStorage) Get(com.scalar.db.api.Get) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 3 with DistributedStorage

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

the class SnapshotTest method toSerializableWithExtraRead_ReadSetExtended_ShouldThrowCommitConflictException.

@Test
public void toSerializableWithExtraRead_ReadSetExtended_ShouldThrowCommitConflictException() throws ExecutionException {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
    Get get = prepareAnotherGet();
    Put put = preparePut();
    snapshot.put(new Snapshot.Key(get), Optional.empty());
    snapshot.put(new Snapshot.Key(put), put);
    DistributedStorage storage = mock(DistributedStorage.class);
    TransactionResult txResult = prepareResult(ANY_ID);
    Get getWithProjections = prepareAnotherGet().withProjection(Attribute.ID).withProjection(Attribute.VERSION);
    when(storage.get(getWithProjections)).thenReturn(Optional.of(txResult));
    // Act Assert
    assertThatThrownBy(() -> snapshot.toSerializableWithExtraRead(storage)).isInstanceOf(CommitConflictException.class);
    // Assert
    verify(storage).get(getWithProjections);
}
Also used : DistributedStorage(com.scalar.db.api.DistributedStorage) Get(com.scalar.db.api.Get) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 4 with DistributedStorage

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

the class SnapshotTest method toSerializableWithExtraRead_ReadSetUpdated_ShouldThrowCommitConflictException.

@Test
public void toSerializableWithExtraRead_ReadSetUpdated_ShouldThrowCommitConflictException() throws ExecutionException {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
    Get get = prepareAnotherGet();
    Put put = preparePut();
    TransactionResult txResult = prepareResult(ANY_ID);
    snapshot.put(new Snapshot.Key(get), Optional.of(txResult));
    snapshot.put(new Snapshot.Key(put), put);
    DistributedStorage storage = mock(DistributedStorage.class);
    TransactionResult changedTxResult = prepareResult(ANY_ID + "x");
    Get getWithProjections = prepareAnotherGet().withProjection(Attribute.ID).withProjection(Attribute.VERSION);
    when(storage.get(getWithProjections)).thenReturn(Optional.of(changedTxResult));
    // Act Assert
    assertThatThrownBy(() -> snapshot.toSerializableWithExtraRead(storage)).isInstanceOf(CommitConflictException.class);
    // Assert
    verify(storage).get(getWithProjections);
}
Also used : DistributedStorage(com.scalar.db.api.DistributedStorage) Get(com.scalar.db.api.Get) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 5 with DistributedStorage

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

the class MultiStorage method getStorage.

private DistributedStorage getStorage(Operation operation) {
    String fullTaleName = operation.forFullTableName().get();
    DistributedStorage storage = tableStorageMap.get(fullTaleName);
    if (storage != null) {
        return storage;
    }
    String namespace = operation.forNamespace().get();
    storage = namespaceStorageMap.get(namespace);
    return storage != null ? storage : defaultStorage;
}
Also used : DistributedStorage(com.scalar.db.api.DistributedStorage) AbstractDistributedStorage(com.scalar.db.storage.common.AbstractDistributedStorage)

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