use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithPutIfExistsCondition_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingDeleteOperationWithPutIfExistsCondition_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
MutationCondition condition = new PutIfExists();
Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(delete)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class BatchHandlerTest method handle_MultipleMutationsGiven_ShouldCallStoredProcedure.
@Test
public void handle_MultipleMutationsGiven_ShouldCallStoredProcedure() {
// Arrange
when(container.getScripts()).thenReturn(cosmosScripts);
when(cosmosScripts.getStoredProcedure(anyString())).thenReturn(storedProcedure);
when(storedProcedure.execute(anyList(), any(CosmosStoredProcedureRequestOptions.class))).thenReturn(spResponse);
Put put1 = preparePut();
Put put2 = preparePut().withCondition(new PutIfNotExists());
Delete delete1 = prepareDelete();
Delete delete2 = prepareDelete().withCondition(new DeleteIfExists());
CosmosMutation cosmosMutation1 = new CosmosMutation(put1, metadata);
CosmosMutation cosmosMutation2 = new CosmosMutation(put2, metadata);
CosmosMutation cosmosMutation3 = new CosmosMutation(delete1, metadata);
CosmosMutation cosmosMutation4 = new CosmosMutation(delete2, metadata);
Record record1 = cosmosMutation1.makeRecord();
Record record2 = cosmosMutation2.makeRecord();
Record emptyRecord = new Record();
String query1 = cosmosMutation1.makeConditionalQuery();
String query2 = cosmosMutation2.makeConditionalQuery();
String query3 = cosmosMutation3.makeConditionalQuery();
String query4 = cosmosMutation4.makeConditionalQuery();
// Act Assert
assertThatCode(() -> handler.handle(Arrays.asList(put1, put2, delete1, delete2))).doesNotThrowAnyException();
// Assert
verify(cosmosScripts).getStoredProcedure("mutate.js");
verify(storedProcedure).execute(captor.capture(), any(CosmosStoredProcedureRequestOptions.class));
assertThat(captor.getValue().get(0)).isEqualTo(4);
assertThat(captor.getValue().get(1)).isEqualTo(CosmosMutation.MutationType.PUT.ordinal());
assertThat(captor.getValue().get(2)).isEqualTo(CosmosMutation.MutationType.PUT_IF_NOT_EXISTS.ordinal());
assertThat(captor.getValue().get(3)).isEqualTo(CosmosMutation.MutationType.DELETE_IF.ordinal());
assertThat(captor.getValue().get(4)).isEqualTo(CosmosMutation.MutationType.DELETE_IF.ordinal());
assertThat(captor.getValue().get(5)).isEqualTo(record1);
assertThat(captor.getValue().get(6)).isEqualTo(record2);
assertThat(captor.getValue().get(7)).isEqualTo(emptyRecord);
assertThat(captor.getValue().get(8)).isEqualTo(emptyRecord);
assertThat(captor.getValue().get(9)).isEqualTo(query1);
assertThat(captor.getValue().get(10)).isEqualTo(query2);
assertThat(captor.getValue().get(11)).isEqualTo(query3);
assertThat(captor.getValue().get(12)).isEqualTo(query4);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class BatchHandlerTest method prepareDelete.
private Delete prepareDelete() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
return new Delete(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class BatchHandlerTest method handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationException.
@Test
public void handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationException() {
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());
Put put = preparePut().withCondition(new PutIfNotExists());
Delete delete = prepareDelete().withCondition(new DeleteIfExists());
// Act Assert
assertThatThrownBy(() -> handler.handle(Arrays.asList(put, delete))).isInstanceOf(NoMutationException.class);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class CosmosMutationTest method prepareDelete.
private Delete prepareDelete() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
return new Delete(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}
Aggregations