Search in sources :

Example 11 with TransactionException

use of com.scalar.db.exception.transaction.TransactionException in project scalardb by scalar-labs.

the class JdbcTransactionIntegrationTest method populateRecords.

private void populateRecords() throws TransactionException {
    JdbcTransaction 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();
}
Also used : IntStream(java.util.stream.IntStream) DatabaseConfig(com.scalar.db.config.DatabaseConfig) IntValue(com.scalar.db.io.IntValue) BeforeClass(org.junit.BeforeClass) Consistency(com.scalar.db.api.Consistency) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Value(com.scalar.db.io.Value) StorageFactory(com.scalar.db.service.StorageFactory) JdbcConfig(com.scalar.db.storage.jdbc.JdbcConfig) DistributedStorageAdmin(com.scalar.db.api.DistributedStorageAdmin) TableMetadata(com.scalar.db.api.TableMetadata) CrudException(com.scalar.db.exception.transaction.CrudException) ArrayList(java.util.ArrayList) Result(com.scalar.db.api.Result) TestUtils(com.scalar.db.storage.TestUtils) DataType(com.scalar.db.io.DataType) Before(org.junit.Before) Key(com.scalar.db.io.Key) AfterClass(org.junit.AfterClass) Test(org.junit.Test) Put(com.scalar.db.api.Put) Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) List(java.util.List) JdbcEnv(com.scalar.db.storage.jdbc.JdbcEnv) Scan(com.scalar.db.api.Scan) Optional(java.util.Optional) TransactionException(com.scalar.db.exception.transaction.TransactionException) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) CrudException(com.scalar.db.exception.transaction.CrudException)

Example 12 with TransactionException

use of com.scalar.db.exception.transaction.TransactionException in project scalardb by scalar-labs.

the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method populateRecords.

private void populateRecords(String table) 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 (TransactionException e) {
            throw new RuntimeException(e);
        }
    }));
    transaction.commit();
}
Also used : IntStream(java.util.stream.IntStream) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) Consistency(com.scalar.db.api.Consistency) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Value(com.scalar.db.io.Value) StorageFactory(com.scalar.db.service.StorageFactory) DistributedStorageAdmin(com.scalar.db.api.DistributedStorageAdmin) ConsensusCommitConfig(com.scalar.db.transaction.consensuscommit.ConsensusCommitConfig) TableMetadata(com.scalar.db.api.TableMetadata) ArrayList(java.util.ArrayList) Result(com.scalar.db.api.Result) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) GrpcTransactionManager(com.scalar.db.transaction.rpc.GrpcTransactionManager) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) CommitException(com.scalar.db.exception.transaction.CommitException) DataType(com.scalar.db.io.DataType) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) Before(org.junit.Before) GrpcConfig(com.scalar.db.storage.rpc.GrpcConfig) Key(com.scalar.db.io.Key) AfterClass(org.junit.AfterClass) TransactionState(com.scalar.db.api.TransactionState) IOException(java.io.IOException) Test(org.junit.Test) Put(com.scalar.db.api.Put) Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) List(java.util.List) Scan(com.scalar.db.api.Scan) Optional(java.util.Optional) TransactionException(com.scalar.db.exception.transaction.TransactionException) ConsensusCommitAdmin(com.scalar.db.transaction.consensuscommit.ConsensusCommitAdmin) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) TransactionException(com.scalar.db.exception.transaction.TransactionException) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put)

Aggregations

TransactionException (com.scalar.db.exception.transaction.TransactionException)12 Key (com.scalar.db.io.Key)9 ExecutionException (com.scalar.db.exception.storage.ExecutionException)7 DataType (com.scalar.db.io.DataType)7 IntValue (com.scalar.db.io.IntValue)7 Value (com.scalar.db.io.Value)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Optional (java.util.Optional)7 IntStream (java.util.stream.IntStream)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 CrudException (com.scalar.db.exception.transaction.CrudException)6 Get (com.scalar.db.api.Get)5 Put (com.scalar.db.api.Put)5 Result (com.scalar.db.api.Result)5 CommitException (com.scalar.db.exception.transaction.CommitException)5 Arrays (java.util.Arrays)5 Assertions.assertThatCode (org.assertj.core.api.Assertions.assertThatCode)5 ImmutableList (com.google.common.collect.ImmutableList)4 Ordering (com.scalar.db.api.Scan.Ordering)4