Search in sources :

Example 96 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageServiceTest method mutate_IsCalledWithSinglePut_StorageShouldBeCalledProperly.

@Test
public void mutate_IsCalledWithSinglePut_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Put(partitionKey))).build();
    @SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(storage).mutate(anyList());
    verify(responseObserver).onNext(any());
    verify(responseObserver).onCompleted();
}
Also used : Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 97 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class TwoPhaseConsensusCommitTest method preparePut.

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

Example 98 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class TwoPhaseConsensusCommitTest 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 99 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class JdbcTransactionManagerTest method mutate_withConflictError_shouldThrowCrudConflictException.

@Test
public void mutate_withConflictError_shouldThrowCrudConflictException() throws SQLException, ExecutionException {
    // Arrange
    when(jdbcService.put(any(), any())).thenThrow(sqlException);
    when(sqlException.getErrorCode()).thenReturn(1213);
    // Act Assert
    assertThatThrownBy(() -> {
        JdbcTransaction transaction = manager.start();
        Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
        Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
        transaction.mutate(Arrays.asList(put, delete));
    }).isInstanceOf(CrudConflictException.class);
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 100 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class JdbcTransactionManagerTest method scan_withConflictError_shouldThrowCrudConflictException.

@Test
public void scan_withConflictError_shouldThrowCrudConflictException() throws SQLException, ExecutionException {
    // Arrange
    when(jdbcService.scan(any(), any())).thenThrow(sqlException);
    when(sqlException.getErrorCode()).thenReturn(1213);
    // Act Assert
    assertThatThrownBy(() -> {
        JdbcTransaction transaction = manager.start();
        Scan scan = new Scan(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
        transaction.scan(scan);
    }).isInstanceOf(CrudConflictException.class);
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Aggregations

Key (com.scalar.db.io.Key)603 Test (org.junit.jupiter.api.Test)391 Put (com.scalar.db.api.Put)211 Scan (com.scalar.db.api.Scan)145 Get (com.scalar.db.api.Get)134 Delete (com.scalar.db.api.Delete)118 Result (com.scalar.db.api.Result)94 Test (org.junit.Test)90 TextValue (com.scalar.db.io.TextValue)88 IntValue (com.scalar.db.io.IntValue)81 BooleanValue (com.scalar.db.io.BooleanValue)51 HashMap (java.util.HashMap)42 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)40 ArrayList (java.util.ArrayList)39 Value (com.scalar.db.io.Value)38 DoubleValue (com.scalar.db.io.DoubleValue)35 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)31 QueryRequest (software.amazon.awssdk.services.dynamodb.model.QueryRequest)29 KeyBytesEncoder (com.scalar.db.storage.dynamo.bytes.KeyBytesEncoder)27 ByteBuffer (java.nio.ByteBuffer)27