Search in sources :

Example 76 with Get

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

the class OperationCheckerTest method whenCheckingGetOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingGetOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = null;
    List<String> projections = Arrays.asList(COL1, COL2, COL3);
    Get get = new Get(partitionKey, clusteringKey).withProjections(projections).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(get)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 77 with Get

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

the class OperationCheckerTest method whenCheckingGetOperationWithIndexedColumnAsPartitionKeyButWrongType_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingGetOperationWithIndexedColumnAsPartitionKeyButWrongType_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(COL1, "1");
    Key clusteringKey = null;
    List<String> projections = Arrays.asList(COL1, COL2, COL3);
    Get get = new Get(partitionKey, clusteringKey).withProjections(projections).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(get)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 78 with Get

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

the class CosmosOperationTest method getCosmosPartitionKey_MultipleKeysGiven_ShouldReturnPartitionKey.

@Test
public void getCosmosPartitionKey_MultipleKeysGiven_ShouldReturnPartitionKey() {
    // Arrange
    when(metadata.getPartitionKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3)));
    Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_INT_1);
    Get get = new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
    CosmosOperation cosmosOperation = new CosmosOperation(get, metadata);
    // Act
    PartitionKey actual = cosmosOperation.getCosmosPartitionKey();
    // Assert
    assertThat(actual).isEqualTo(new PartitionKey(ANY_TEXT_1 + ":" + ANY_TEXT_2 + ":" + ANY_INT_1));
}
Also used : Get(com.scalar.db.api.Get) PartitionKey(com.azure.cosmos.models.PartitionKey) Key(com.scalar.db.io.Key) PartitionKey(com.azure.cosmos.models.PartitionKey) Test(org.junit.jupiter.api.Test)

Example 79 with Get

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

the class CosmosOperationTest method getConcatenatedPartitionKey_MultipleKeysGiven_ShouldReturnConcatenatedPartitionKey.

@Test
public void getConcatenatedPartitionKey_MultipleKeysGiven_ShouldReturnConcatenatedPartitionKey() {
    // Arrange
    when(metadata.getPartitionKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3)));
    Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_INT_1);
    Get get = new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
    CosmosOperation cosmosOperation = new CosmosOperation(get, metadata);
    // Act
    String actual = cosmosOperation.getConcatenatedPartitionKey();
    // Assert
    assertThat(actual).isEqualTo(ANY_TEXT_1 + ":" + ANY_TEXT_2 + ":" + ANY_INT_1);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) PartitionKey(com.azure.cosmos.models.PartitionKey) Test(org.junit.jupiter.api.Test)

Example 80 with Get

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

the class JdbcServiceTest method whenGetOperationExecuted_shouldCallQueryBuilder.

@Test
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION")
public void whenGetOperationExecuted_shouldCallQueryBuilder() throws Exception {
    // Arrange
    when(queryBuilder.select(any())).thenReturn(selectQueryBuilder);
    when(selectQueryBuilder.from(any(), any(), any())).thenReturn(selectQueryBuilder);
    when(selectQueryBuilder.where(any(), any())).thenReturn(selectQueryBuilder);
    when(selectQueryBuilder.build()).thenReturn(selectQuery);
    when(connection.prepareStatement(any())).thenReturn(preparedStatement);
    when(preparedStatement.executeQuery()).thenReturn(resultSet);
    when(resultSet.next()).thenReturn(false);
    // Act
    Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
    jdbcService.get(get, connection);
    // Assert
    verify(operationChecker).check(any(Get.class));
    verify(queryBuilder).select(any());
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Get (com.scalar.db.api.Get)286 Test (org.junit.jupiter.api.Test)130 Result (com.scalar.db.api.Result)129 Key (com.scalar.db.io.Key)126 Test (org.junit.Test)88 Put (com.scalar.db.api.Put)86 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)32 Delete (com.scalar.db.api.Delete)28 IntValue (com.scalar.db.io.IntValue)28 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)21 TextValue (com.scalar.db.io.TextValue)16 ConditionalExpression (com.scalar.db.api.ConditionalExpression)13 PartitionKey (com.azure.cosmos.models.PartitionKey)12 TableMetadata (com.scalar.db.api.TableMetadata)10 BooleanValue (com.scalar.db.io.BooleanValue)10 PutIf (com.scalar.db.api.PutIf)8 BigIntValue (com.scalar.db.io.BigIntValue)7 HashMap (java.util.HashMap)7 BlobValue (com.scalar.db.io.BlobValue)6 DistributedTransactionServiceWithConsensusCommitIntegrationTest.prepareGet (com.scalar.db.server.DistributedTransactionServiceWithConsensusCommitIntegrationTest.prepareGet)6