use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithJdbcTransactionIntegrationTest method populateRecords.
private void populateRecords() throws TransactionException {
GrpcTransaction transaction = manager.start();
IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
Key partitionKey = new Key(ACCOUNT_ID, i);
Key clusteringKey = new Key(ACCOUNT_TYPE, j);
Put put = new Put(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(TABLE).withValue(BALANCE, INITIAL_BALANCE);
try {
transaction.put(put);
} catch (CrudException e) {
throw new RuntimeException(e);
}
}));
transaction.commit();
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method prepareDelete.
static Delete prepareDelete(int id, int type, String table) {
Key partitionKey = new Key(ACCOUNT_ID, id);
Key clusteringKey = new Key(ACCOUNT_TYPE, type);
return new Delete(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(table).withConsistency(Consistency.LINEARIZABLE);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase method put_MultiplePutWithDifferentPartitionsWithIfNotExistsGiven_ShouldThrowIllegalArgumentException.
@Test
public void put_MultiplePutWithDifferentPartitionsWithIfNotExistsGiven_ShouldThrowIllegalArgumentException() throws IOException, ExecutionException {
// Arrange
List<Put> puts = preparePuts();
puts.get(0).withCondition(new PutIfNotExists());
puts.get(3).withCondition(new PutIfNotExists());
puts.get(6).withCondition(new PutIfNotExists());
// Act
assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(3), puts.get(6)))).isInstanceOf(IllegalArgumentException.class);
// Assert
List<Result> results;
results = scanAll(new Scan(new Key(COL_NAME1, 0)));
assertThat(results.size()).isEqualTo(0);
results = scanAll(new Scan(new Key(COL_NAME1, 3)));
assertThat(results.size()).isEqualTo(0);
results = scanAll(new Scan(new Key(COL_NAME1, 6)));
assertThat(results.size()).isEqualTo(0);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase method scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues.
@Test
public void scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues() throws ExecutionException, IOException {
// Arrange
for (int i = 0; i < 345; i++) {
Key partitionKey = new Key(COL_NAME1, i % 4);
Key clusteringKey = new Key(COL_NAME4, i);
storage.put(new Put(partitionKey, clusteringKey).withBlobValue(COL_NAME6, new byte[5000]));
}
Scan scan = new ScanAll();
// Act
List<Result> results = scanAll(scan);
// Assert
List<ExpectedResult> expectedResults = new ArrayList<>();
for (int i = 0; i < 345; i++) {
Key partitionKey = new Key(COL_NAME1, i % 4);
Key clusteringKey = new Key(COL_NAME4, i);
expectedResults.add(new ExpectedResultBuilder().partitionKey(partitionKey).clusteringKey(clusteringKey).nonKeyColumns(Arrays.asList(TextColumn.ofNull(COL_NAME2), IntColumn.ofNull(COL_NAME3), BooleanColumn.ofNull(COL_NAME5), BlobColumn.of(COL_NAME6, new byte[5000]))).build());
}
assertResultsContainsExactlyInAnyOrder(results, expectedResults);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase method prepareDeletes.
private List<Delete> prepareDeletes() {
List<Delete> deletes = new ArrayList<>();
IntStream.range(0, 5).forEach(i -> IntStream.range(0, 3).forEach(j -> {
Key partitionKey = new Key(COL_NAME1, i);
Key clusteringKey = new Key(COL_NAME4, j);
Delete delete = new Delete(partitionKey, clusteringKey);
deletes.add(delete);
}));
return deletes;
}
Aggregations