Search in sources :

Example 86 with Get

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

the class GrpcStorageTest method get_StubThrowInternalError_ShouldThrowExecutionException.

@Test
public void get_StubThrowInternalError_ShouldThrowExecutionException() {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    Get get = new Get(partitionKey);
    when(blockingStub.get(any())).thenThrow(Status.INTERNAL.asRuntimeException());
    // Act
    assertThatThrownBy(() -> storage.get(get)).isInstanceOf(ExecutionException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 87 with Get

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

the class GrpcStorageTest method get_isCalledWithProperArguments_StubShouldBeCalledProperly.

@Test
public void get_isCalledWithProperArguments_StubShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    Get get = new Get(partitionKey);
    when(blockingStub.get(any())).thenReturn(GetResponse.newBuilder().build());
    // Act
    storage.get(get);
    // Assert
    verify(blockingStub).get(any());
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 88 with Get

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

the class ConsensusCommitTest method prepareGet.

private Get prepareGet() {
    Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
    Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
    return new Get(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE).forTable(ANY_TABLE_NAME);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key)

Example 89 with Get

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

the class CrudHandlerTest method get_KeyNotExistsInCrudSetAndExceptionThrownInStorage_ShouldThrowCrudException.

@Test
public void get_KeyNotExistsInCrudSetAndExceptionThrownInStorage_ShouldThrowCrudException() throws CrudException, ExecutionException {
    // Arrange
    Get get = prepareGet();
    when(snapshot.get(new Snapshot.Key(get))).thenReturn(Optional.empty());
    ExecutionException toThrow = mock(ExecutionException.class);
    when(storage.get(get)).thenThrow(toThrow);
    // Act Assert
    assertThatThrownBy(() -> handler.get(get)).isInstanceOf(CrudException.class).hasCause(toThrow);
}
Also used : Get(com.scalar.db.api.Get) ExecutionException(com.scalar.db.exception.storage.ExecutionException) CrudException(com.scalar.db.exception.transaction.CrudException) Test(org.junit.jupiter.api.Test)

Example 90 with Get

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

the class CrudHandlerTest method get_KeyNotExistsInSnapshotAndRecordInStorageNotCommitted_ShouldThrowUncommittedRecordException.

@Test
public void get_KeyNotExistsInSnapshotAndRecordInStorageNotCommitted_ShouldThrowUncommittedRecordException() throws CrudException, ExecutionException {
    // Arrange
    Get get = prepareGet();
    Optional<Result> expected = Optional.of(prepareResult(TransactionState.PREPARED));
    when(snapshot.get(new Snapshot.Key(get))).thenReturn(Optional.empty());
    when(storage.get(get)).thenReturn(expected);
    // Act Assert
    assertThatThrownBy(() -> handler.get(get)).isInstanceOf(UncommittedRecordException.class);
}
Also used : Get(com.scalar.db.api.Get) Result(com.scalar.db.api.Result) Test(org.junit.jupiter.api.Test)

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