use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class SnapshotTest method get_KeyGivenContainedInDeleteSet_ShouldReturnEmpty.
@Test
public void get_KeyGivenContainedInDeleteSet_ShouldReturnEmpty() throws CrudException {
// Arrange
snapshot = prepareSnapshot(Isolation.SNAPSHOT);
Delete delete = prepareDelete();
Snapshot.Key key = new Snapshot.Key(delete);
snapshot.put(key, delete);
// Act
Optional<TransactionResult> actual = snapshot.get(key);
// Assert
assertThat(actual).isNotPresent();
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class SnapshotTest method put_DeleteGiven_ShouldHoldWhatsGivenInDeleteSet.
@Test
public void put_DeleteGiven_ShouldHoldWhatsGivenInDeleteSet() {
// Arrange
snapshot = prepareSnapshot(Isolation.SNAPSHOT);
Delete delete = prepareDelete();
Snapshot.Key key = new Snapshot.Key(delete);
// Act
snapshot.put(key, delete);
// Assert
assertThat(deleteSet.get(key)).isEqualTo(delete);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class SnapshotTest method to_CommitMutationComposerGiven_ShouldCallComposerProperly.
@Test
public void to_CommitMutationComposerGiven_ShouldCallComposerProperly() throws CommitConflictException, ExecutionException {
// Arrange
snapshot = prepareSnapshot(Isolation.SNAPSHOT);
Put put = preparePut();
Delete delete = prepareAnotherDelete();
TransactionResult result = prepareResult(ANY_ID);
snapshot.put(new Snapshot.Key(prepareGet()), Optional.of(result));
snapshot.put(new Snapshot.Key(prepareAnotherGet()), Optional.of(result));
snapshot.put(new Snapshot.Key(put), put);
snapshot.put(new Snapshot.Key(delete), delete);
// Act
snapshot.to(commitComposer);
// Assert
verify(commitComposer).add(put, result);
verify(commitComposer).add(delete, result);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class SnapshotTest method to_RollbackMutationComposerGivenAndSerializableWithExtraWriteIsolationSet_ShouldCallComposerProperly.
@Test
public void to_RollbackMutationComposerGivenAndSerializableWithExtraWriteIsolationSet_ShouldCallComposerProperly() throws CommitConflictException, ExecutionException {
// Arrange
snapshot = prepareSnapshot(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_WRITE);
Put put = preparePut();
Delete delete = prepareAnotherDelete();
TransactionResult result = prepareResult(ANY_ID);
snapshot.put(new Snapshot.Key(prepareGet()), Optional.of(result));
snapshot.put(new Snapshot.Key(prepareAnotherGet()), Optional.of(result));
snapshot.put(new Snapshot.Key(put), put);
snapshot.put(new Snapshot.Key(delete), delete);
configureBehavior();
// Act
snapshot.to(rollbackComposer);
// Assert
// no effect on RollbackMutationComposer
verify(rollbackComposer).add(put, result);
verify(rollbackComposer).add(delete, result);
verify(snapshot).toSerializableWithExtraWrite(rollbackComposer);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationException.
@Test
public void handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationException() {
// Arrange
when(container.getScripts()).thenReturn(cosmosScripts);
when(cosmosScripts.getStoredProcedure(anyString())).thenReturn(storedProcedure);
CosmosException toThrow = mock(CosmosException.class);
doThrow(toThrow).when(storedProcedure).execute(anyList(), any(CosmosStoredProcedureRequestOptions.class));
when(toThrow.getSubStatusCode()).thenReturn(CosmosErrorCode.PRECONDITION_FAILED.get());
Delete delete = prepareDelete().withCondition(new DeleteIfExists());
// Act Assert
assertThatThrownBy(() -> handler.handle(delete)).isInstanceOf(NoMutationException.class);
}
Aggregations