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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations