Search in sources :

Example 6 with ScanAll

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);
}
Also used : ScanRequest(software.amazon.awssdk.services.dynamodb.model.ScanRequest) HashMap(java.util.HashMap) ScanAll(com.scalar.db.api.ScanAll) Test(org.junit.jupiter.api.Test)

Example 7 with ScanAll

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());
}
Also used : Scan(com.scalar.db.api.Scan) ScanAll(com.scalar.db.api.ScanAll) Test(org.junit.jupiter.api.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with ScanAll

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());
}
Also used : ScanAll(com.scalar.db.api.ScanAll) Test(org.junit.jupiter.api.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 9 with ScanAll

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);
}
Also used : ScanAll(com.scalar.db.api.ScanAll) List(java.util.List) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 10 with ScanAll

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();
}
Also used : ScanAll(com.scalar.db.api.ScanAll) List(java.util.List) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Aggregations

ScanAll (com.scalar.db.api.ScanAll)52 Test (org.junit.jupiter.api.Test)43 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Result (com.scalar.db.api.Result)9 CosmosQueryRequestOptions (com.azure.cosmos.models.CosmosQueryRequestOptions)8 Put (com.scalar.db.api.Put)4 HashMap (java.util.HashMap)4 Scan (com.scalar.db.api.Scan)3 TableMetadata (com.scalar.db.api.TableMetadata)3 Key (com.scalar.db.io.Key)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 ScanRequest (software.amazon.awssdk.services.dynamodb.model.ScanRequest)3 SelectQuery (com.scalar.db.storage.jdbc.query.SelectQuery)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2 Nonnull (javax.annotation.Nonnull)2 ResultSet (com.datastax.driver.core.ResultSet)1 Select (com.datastax.driver.core.querybuilder.Select)1