use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.
the class SelectStatementHandlerTest method prepare_ScanAllOperationWithLimit_ShouldPrepareProperQuery.
@Test
public void prepare_ScanAllOperationWithLimit_ShouldPrepareProperQuery() {
// Arrange
when(client.scan(any(ScanRequest.class))).thenReturn(scanResponse);
when(scanResponse.items()).thenReturn(Collections.singletonList(new HashMap<>()));
ScanAll scanAll = prepareScanAll().withLimit(ANY_LIMIT);
// Act Assert
assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException();
// Assert
ArgumentCaptor<ScanRequest> captor = ArgumentCaptor.forClass(ScanRequest.class);
verify(client).scan(captor.capture());
ScanRequest actualRequest = captor.getValue();
assertThat(actualRequest.limit()).isEqualTo(ANY_LIMIT);
}
use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.
the class JdbcServiceTest method whenGetScannerExecuted_withScanAll_shouldCallQueryBuilder.
@Test
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION")
public void whenGetScannerExecuted_withScanAll_shouldCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.select(any())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.from(any(), any(), any())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.limit(anyInt())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.build()).thenReturn(selectQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(preparedStatement.executeQuery()).thenReturn(resultSet);
when(resultSet.next()).thenReturn(false);
// Act
Scan scan = new ScanAll().forNamespace(NAMESPACE).forTable(TABLE);
jdbcService.getScanner(scan, connection);
// Assert
verify(operationChecker).check(any(ScanAll.class));
verify(queryBuilder).select(any());
}
use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.
the class JdbcServiceTest method whenScanExecuted_withScanAll_shouldCallQueryBuilder.
@Test
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION")
public void whenScanExecuted_withScanAll_shouldCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.select(any())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.from(any(), any(), any())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.limit(anyInt())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.build()).thenReturn(selectQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(preparedStatement.executeQuery()).thenReturn(resultSet);
when(resultSet.next()).thenReturn(false);
// Act
ScanAll scanAll = new ScanAll().forNamespace(NAMESPACE).forTable(TABLE);
jdbcService.scan(scanAll, connection);
// Assert
verify(operationChecker).check(any(ScanAll.class));
verify(queryBuilder).select(any());
}
use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.
the class SnapshotTest method get_ScanAllGivenAndAlreadyPresentInScanSet_ShouldReturnKeys.
@Test
public void get_ScanAllGivenAndAlreadyPresentInScanSet_ShouldReturnKeys() {
// Arrange
snapshot = prepareSnapshot(Isolation.SNAPSHOT);
// "text2"
Put put = preparePut();
Snapshot.Key putKey = new Snapshot.Key(put);
snapshot.put(putKey, put);
ScanAll scanAll = new ScanAll().withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME_2).forTable(ANY_TABLE_NAME_2);
Snapshot.Key aKey = mock(Snapshot.Key.class);
snapshot.put(scanAll, Collections.singletonList(aKey));
// Act Assert
Optional<List<Snapshot.Key>> keys = snapshot.get(scanAll);
// Assert
assertThat(keys).isNotEmpty();
assertThat(keys.get()).containsExactly(aKey);
}
use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.
the class SnapshotTest method get_ScanAllGivenAndPutInWriteSetNotOverlappingWithScanAll_ShouldReturnEmptyList.
@Test
public void get_ScanAllGivenAndPutInWriteSetNotOverlappingWithScanAll_ShouldReturnEmptyList() {
// Arrange
snapshot = prepareSnapshot(Isolation.SNAPSHOT);
// "text2"
Put put = preparePut();
Snapshot.Key putKey = new Snapshot.Key(put);
snapshot.put(putKey, put);
ScanAll scanAll = new ScanAll().withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME_2).forTable(ANY_TABLE_NAME_2);
// Act Assert
Optional<List<Snapshot.Key>> keys = snapshot.get(scanAll);
// Assert
assertThat(keys).isEmpty();
}
Aggregations