use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcServiceTest method whenPutOperationWithPutIfNotExistsConditionExecuted_shouldReturnTrueAndCallQueryBuilder.
@Test
public void whenPutOperationWithPutIfNotExistsConditionExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.insertInto(any(), any(), any())).thenReturn(insertQueryBuilder);
when(insertQueryBuilder.values(any(), any(), any())).thenReturn(insertQueryBuilder);
when(insertQueryBuilder.build()).thenReturn(insertQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
// Act
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfNotExists()).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.put(put, connection);
// Assert
assertThat(ret).isTrue();
verify(operationChecker).check(any(Put.class));
verify(queryBuilder).insertInto(any(), any(), any());
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcServiceTest method whenPutOperationExecuted_shouldReturnTrueAndCallQueryBuilder.
@Test
public void whenPutOperationExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.upsertInto(any(), any(), any())).thenReturn(upsertQueryBuilder);
when(upsertQueryBuilder.values(any(), any(), any())).thenReturn(upsertQueryBuilder);
when(upsertQueryBuilder.build()).thenReturn(upsertQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
// Act
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.put(put, connection);
// Assert
assertThat(ret).isTrue();
verify(operationChecker).check(any(Put.class));
verify(queryBuilder).upsertInto(any(), any(), any());
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcServiceTest method whenMutateOperationExecuted_shouldReturnTrueAndCallQueryBuilder.
@Test
public void whenMutateOperationExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
// Arrange
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(queryBuilder.upsertInto(any(), any(), any())).thenReturn(upsertQueryBuilder);
when(upsertQueryBuilder.values(any(), any(), any())).thenReturn(upsertQueryBuilder);
when(upsertQueryBuilder.build()).thenReturn(upsertQuery);
when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.where(any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
// Act
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.mutate(Arrays.asList(put, delete), connection);
// Assert
assertThat(ret).isTrue();
verify(operationChecker).check(anyList());
verify(operationChecker).check(any(Put.class));
verify(operationChecker).check(any(Delete.class));
verify(queryBuilder).upsertInto(any(), any(), any());
verify(queryBuilder).deleteFrom(any(), any(), any());
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class MultiStorageTest method whenPutDataIntoTable2_DataShouldBeWrittenIntoStorage2.
@Test
public void whenPutDataIntoTable2_DataShouldBeWrittenIntoStorage2() throws ExecutionException {
// Arrange
String namespace = NAMESPACE1;
String table = TABLE2;
Key partitionKey = new Key(COL_NAME1, 1);
Key clusteringKey = new Key(COL_NAME2, 2);
Put put = new Put(partitionKey, clusteringKey).withValue(COL_NAME3, 3).forNamespace(namespace).forTable(table);
// Act
multiStorage.put(put);
// Assert
verify(storage2).put(any(Put.class));
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class MultiStorageTest method whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage.
@Test
public void whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage() throws ExecutionException {
// Arrange
String namespace = NAMESPACE1;
String table = TABLE3;
Key partitionKey = new Key(COL_NAME1, 1);
Key clusteringKey = new Key(COL_NAME2, 2);
Put put = new Put(partitionKey, clusteringKey).withValue(COL_NAME3, 3).forNamespace(namespace).forTable(table);
// Act
multiStorage.put(put);
// Assert
verify(storage3).put(any(Put.class));
}
Aggregations