use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class ScalarDbUtilsTest method copyAndSetTargetToIfNot_ScanGiven_ShouldReturnDifferentInstance.
@Test
public void copyAndSetTargetToIfNot_ScanGiven_ShouldReturnDifferentInstance() {
// Arrange
Scan scan = new Scan(new Key("c1", "v1"));
// Act
Scan actual = ScalarDbUtils.copyAndSetTargetToIfNot(scan, NAMESPACE, TABLE);
// Assert
assertThat(actual == scan).isFalse();
assertThat(scan.forNamespace()).isNotPresent();
assertThat(scan.forTable()).isNotPresent();
assertThat(actual.forNamespace()).isEqualTo(NAMESPACE);
assertThat(actual.forTable()).isEqualTo(TABLE);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class SelectStatementHandlerTest method prepare_ScanOperationWithMultipleOrdering_ShouldPrepareProperQuery.
@Test
public void prepare_ScanOperationWithMultipleOrdering_ShouldPrepareProperQuery() {
// Arrange
String expected = Joiner.on(" ").skipNulls().join(new String[] { "SELECT * FROM", ANY_NAMESPACE_NAME + "." + ANY_TABLE_NAME, "WHERE", ANY_NAME_1 + "=?", "AND", ANY_NAME_2 + ">=?", "ORDER BY", ANY_NAME_2, ASC_ORDER + "," + ANY_NAME_3, DESC_ORDER.toString(), "LIMIT", ANY_LIMIT + ";" });
configureBehavior(expected);
scan = prepareScan();
scan.withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withOrdering(new Scan.Ordering(ANY_NAME_2, ASC_ORDER)).withOrdering(new Scan.Ordering(ANY_NAME_3, DESC_ORDER)).withLimit(ANY_LIMIT);
// Act
handler.prepare(scan);
// Assert
verify(session).prepare(expected);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingScanOperationWithAllValidArguments_shouldNotThrowAnyException.
@Test
public void whenCheckingScanOperationWithAllValidArguments_shouldNotThrowAnyException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key startClusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
Key endClusteringKey = new Key(CKEY1, 2, CKEY2, "val9");
List<String> projections = Arrays.asList(COL1, COL2, COL3);
int limit = 10;
Scan scan = new Scan(partitionKey).withStart(startClusteringKey).withEnd(endClusteringKey).withProjections(projections).withLimit(limit).withOrdering(new Scan.Ordering(CKEY1, Scan.Ordering.Order.ASC)).withOrdering(new Scan.Ordering(CKEY2, Scan.Ordering.Order.DESC)).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException();
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingScanOperationWithInvalidClusteringKeyRange_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingScanOperationWithInvalidClusteringKeyRange_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key startClusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
Key endClusteringKey = new Key(CKEY1, 2);
List<String> projections = Arrays.asList(COL1, COL2, COL3);
int limit = 10;
Scan scan = new Scan(partitionKey).withStart(startClusteringKey).withEnd(endClusteringKey).withProjections(projections).withLimit(limit).withOrdering(new Scan.Ordering(CKEY1, Scan.Ordering.Order.ASC)).withOrdering(new Scan.Ordering(CKEY2, Scan.Ordering.Order.DESC)).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(scan)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyException.
@Test
public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key startClusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
Key endClusteringKey = new Key(CKEY1, 2, CKEY2, "val9");
List<String> projections = Arrays.asList(COL1, COL2, COL3);
int limit = 10;
Scan scan = new Scan(partitionKey).withStart(startClusteringKey).withEnd(endClusteringKey).withProjections(projections).withLimit(limit).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException();
}
Aggregations