Search in sources :

Example 11 with ScanAll

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

the class SnapshotTest method get_ScanAllGivenAndPutInWriteSetInSameTable_ShouldThrowException.

@Test
public void get_ScanAllGivenAndPutInWriteSetInSameTable_ShouldThrowException() {
    // 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).forTable(ANY_TABLE_NAME);
    // Act Assert
    Throwable thrown = catchThrowable(() -> snapshot.get(scanAll));
    // Assert
    assertThat(thrown).isInstanceOf(IllegalArgumentException.class);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ScanAll(com.scalar.db.api.ScanAll) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 12 with ScanAll

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

the class SelectStatementHandlerTest method handle_ScanAllOperationWithProjectedColumns_ShouldCallQueryItemsWithProjectedColumns.

@Test
public void handle_ScanAllOperationWithProjectedColumns_ShouldCallQueryItemsWithProjectedColumns() {
    // Arrange
    when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
    Record expected = new Record();
    when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
    ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(ANY_NAME_3, ANY_NAME_4));
    // Act Assert
    assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException();
    // Assert
    String expectedQuery = "select r.id, " + "r.concatenatedPartitionKey, " + "{\"name3\":r.values[\"name3\"],\"name4\":r.values[\"name4\"]} as values " + "from Record r";
    verify(container).queryItems(eq(expectedQuery), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) ScanAll(com.scalar.db.api.ScanAll) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 13 with ScanAll

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

the class SelectStatementHandlerTest method handle_ScanAllOperationWithPrimaryKeyProjected_ShouldCallQueryItemsWithOnlyProjectedPrimaryKey.

@Test
public void handle_ScanAllOperationWithPrimaryKeyProjected_ShouldCallQueryItemsWithOnlyProjectedPrimaryKey() {
    // Arrange
    when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
    Record expected = new Record();
    when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
    ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(ANY_NAME_1, ANY_NAME_2));
    // Act Assert
    assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException();
    // Assert
    String expectedQuery = "select r.id, " + "r.concatenatedPartitionKey, " + "{\"name1\":r.partitionKey[\"name1\"]} as partitionKey, " + "{\"name2\":r.clusteringKey[\"name2\"]} as clusteringKey " + "from Record r";
    verify(container).queryItems(eq(expectedQuery), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) ScanAll(com.scalar.db.api.ScanAll) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 14 with ScanAll

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

the class SelectStatementHandlerTest method handle_ScanAllOperationWithoutLimit_ShouldCallQueryItemsWithProperQuery.

@Test
public void handle_ScanAllOperationWithoutLimit_ShouldCallQueryItemsWithProperQuery() {
    // Arrange
    when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
    Record expected = new Record();
    when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
    ScanAll scanAll = prepareScanAll();
    // Act Assert
    assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException();
    // Assert
    String expectedQuery = "select * from Record r";
    verify(container).queryItems(eq(expectedQuery), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) ScanAll(com.scalar.db.api.ScanAll) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 15 with ScanAll

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

the class SelectStatementHandlerTest method handle_ScanAllOperationWithLimit_ShouldCallQueryItemsWithProperQuery.

@Test
public void handle_ScanAllOperationWithLimit_ShouldCallQueryItemsWithProperQuery() {
    // Arrange
    when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
    Record expected = new Record();
    when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
    ScanAll scanAll = prepareScanAll().withLimit(ANY_LIMIT);
    // Act Assert
    assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException();
    // Assert
    String expectedQuery = "select * from Record r offset 0 limit " + ANY_LIMIT;
    verify(container).queryItems(eq(expectedQuery), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) ScanAll(com.scalar.db.api.ScanAll) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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