Search in sources :

Example 1 with ScanAll

use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.

the class SelectStatementHandlerTest method prepare_ScanAllOperationWithoutLimit_ShouldPrepareProperQuery.

@Test
public void prepare_ScanAllOperationWithoutLimit_ShouldPrepareProperQuery() {
    // Arrange
    String expected = Joiner.on(" ").skipNulls().join(new String[] { "SELECT * FROM", ANY_NAMESPACE_NAME + "." + ANY_TABLE_NAME + ";" });
    configureBehavior(expected);
    ScanAll scanAll = prepareScanAll();
    // Act
    handler.prepare(scanAll);
    // Assert
    verify(session).prepare(expected);
}
Also used : ScanAll(com.scalar.db.api.ScanAll) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with ScanAll

use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.

the class SelectStatementHandlerTest method prepare_ScanAllOperationWithProjectedColumns_ShouldPrepareProperQuery.

@Test
public void prepare_ScanAllOperationWithProjectedColumns_ShouldPrepareProperQuery() {
    // Arrange
    String expected = Joiner.on(" ").skipNulls().join(new String[] { "SELECT", ANY_NAME_1 + "," + ANY_NAME_2, "FROM", ANY_NAMESPACE_NAME + "." + ANY_TABLE_NAME + ";" });
    configureBehavior(expected);
    ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(ANY_NAME_1, ANY_NAME_2));
    // Act
    handler.prepare(scanAll);
    // Assert
    verify(session).prepare(expected);
}
Also used : ScanAll(com.scalar.db.api.ScanAll) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with ScanAll

use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.

the class OperationCheckerTest method whenCheckingScanAllOperationWithNegativeLimitNumber_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingScanAllOperationWithNegativeLimitNumber_shouldThrowIllegalArgumentException() {
    // Arrange
    List<String> projections = Arrays.asList(COL1, COL2, COL3);
    int limit = -10;
    ScanAll scanAll = new ScanAll().withProjections(projections).withLimit(limit).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(scanAll)).isInstanceOf(IllegalArgumentException.class);
}
Also used : ScanAll(com.scalar.db.api.ScanAll) Test(org.junit.jupiter.api.Test)

Example 4 with ScanAll

use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.

the class SelectStatementHandlerTest method prepare_ScanAllOperationWithProjectedColumns_ShouldPrepareProperQuery.

@Test
public void prepare_ScanAllOperationWithProjectedColumns_ShouldPrepareProperQuery() {
    // Arrange
    when(client.scan(any(ScanRequest.class))).thenReturn(scanResponse);
    when(scanResponse.items()).thenReturn(Collections.singletonList(new HashMap<>()));
    ScanAll scanAll = prepareScanAll().withProjection(ANY_NAME_1).withProjection(ANY_NAME_2).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
    Map<String, String> expectedExpressionAttributeNames = new HashMap<>();
    expectedExpressionAttributeNames.put(DynamoOperation.COLUMN_NAME_ALIAS + "0", ANY_NAME_1);
    expectedExpressionAttributeNames.put(DynamoOperation.COLUMN_NAME_ALIAS + "1", ANY_NAME_2);
    // 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.expressionAttributeNames()).isEqualTo(expectedExpressionAttributeNames);
    assertThat(actualRequest.projectionExpression()).isEqualTo(DynamoOperation.COLUMN_NAME_ALIAS + "0," + DynamoOperation.COLUMN_NAME_ALIAS + "1");
}
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 5 with ScanAll

use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.

the class SelectStatementHandlerTest method prepare_ScanAllOperationWithoutLimit_ShouldPrepareProperQuery.

@Test
public void prepare_ScanAllOperationWithoutLimit_ShouldPrepareProperQuery() {
    // Arrange
    when(client.scan(any(ScanRequest.class))).thenReturn(scanResponse);
    when(scanResponse.items()).thenReturn(Collections.singletonList(new HashMap<>()));
    ScanAll scanAll = prepareScanAll();
    // 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(null);
}
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)

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