use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutationException.
@Test
public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutationException() throws IOException, ExecutionException {
// Arrange
int pKey = 0;
int cKey = 0;
List<Put> puts = preparePuts();
assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException();
puts.get(0).withCondition(new PutIfNotExists());
puts.get(1).withCondition(new PutIfNotExists());
puts.get(2).withCondition(new PutIfNotExists());
Scan scan = new Scan(new Key(COL_NAME1, pKey));
// Act
assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))).isInstanceOf(NoMutationException.class);
// Assert
List<Result> results = scanAll(scan);
assertThat(results.size()).isEqualTo(1);
assertThat(results.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, pKey + cKey)));
}
use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class InsertStatementHandlerTest method handle_PutWithoutConditionButNoMutationApplied_ShouldThrowProperExecutionException.
@Test
public void handle_PutWithoutConditionButNoMutationApplied_ShouldThrowProperExecutionException() {
// Arrange
put = preparePutWithClusteringKey();
put.withCondition(new PutIfNotExists());
spy = prepareSpiedInsertStatementHandler();
ResultSet results = mock(ResultSet.class);
Row row = mock(Row.class);
when(results.one()).thenReturn(row);
when(row.getBool(0)).thenReturn(false);
doReturn(results).when(spy).execute(bound, put);
// Act Assert
assertThatThrownBy(() -> spy.handle(put)).isInstanceOf(NoMutationException.class);
}
use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class InsertStatementHandlerTest method handle_PutWithConditionButNoMutationApplied_ShouldThrowProperExecutionException.
@Test
public void handle_PutWithConditionButNoMutationApplied_ShouldThrowProperExecutionException() {
// Arrange
put = preparePutWithClusteringKey();
put.withCondition(new PutIfNotExists());
spy = prepareSpiedInsertStatementHandler();
ResultSet results = mock(ResultSet.class);
Row row = mock(Row.class);
when(results.one()).thenReturn(row);
when(row.getBool(0)).thenReturn(false);
doReturn(results).when(spy).execute(bound, put);
// Act Assert
assertThatThrownBy(() -> spy.handle(put)).isInstanceOf(NoMutationException.class);
}
use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class InsertStatementHandlerTest method prepare_PutOperationWithIfNotExistsGiven_ShouldPrepareProperQuery.
@Test
public void prepare_PutOperationWithIfNotExistsGiven_ShouldPrepareProperQuery() {
// Arrange
String expected = Joiner.on(" ").skipNulls().join(new String[] { "INSERT INTO", ANY_NAMESPACE_NAME + "." + ANY_TABLE_NAME, "(" + ANY_NAME_1 + "," + ANY_NAME_2 + "," + ANY_NAME_3 + ")", "VALUES", "(?,?,?)", "IF NOT EXISTS;" });
configureBehavior(expected);
put = preparePutWithClusteringKey();
put.withCondition(new PutIfNotExists());
// Act
handler.prepare(put);
// Assert
verify(session).prepare(expected);
}
use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class InsertStatementHandlerTest method prepare_PutOperationWithIfNotExistsGiven_ShouldCallAccept.
@Test
public void prepare_PutOperationWithIfNotExistsGiven_ShouldCallAccept() {
// Arrange
configureBehavior(null);
put = preparePutWithClusteringKey();
PutIfNotExists putIfNotExists = spy(new PutIfNotExists());
put.withCondition(putIfNotExists);
// Act
handler.prepare(put);
// Assert
verify(putIfNotExists).accept(any(ConditionSetter.class));
}
Aggregations