Search in sources :

Example 91 with Key

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

the class DistributedStorageIntegrationTestBase method prepareDelete.

private Delete prepareDelete(int pKey, int cKey) {
    Key partitionKey = new Key(COL_NAME1, pKey);
    Key clusteringKey = new Key(COL_NAME4, cKey);
    return new Delete(partitionKey, clusteringKey);
}
Also used : Key(com.scalar.db.io.Key)

Example 92 with Key

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

the class DistributedStorageIntegrationTestBase method scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults.

@Test
public void scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults() throws ExecutionException, IOException {
    // Arrange
    populateRecords();
    int pKey = 0;
    // Act
    Scan scan = new Scan(new Key(COL_NAME1, pKey));
    List<Result> actual = new ArrayList<>();
    Scanner scanner = storage.scan(scan);
    Optional<Result> result = scanner.one();
    scanner.forEach(actual::add);
    scanner.close();
    // Assert
    assertThat(result.isPresent()).isTrue();
    assertThat(result.get().getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(result.get().getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(0);
    assertThat(actual.size()).isEqualTo(2);
    assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1);
    assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2);
}
Also used : ArrayList(java.util.ArrayList) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 93 with Key

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

the class DistributedStorageServiceTest method mutate_StorageThrowsIllegalArgumentException_ShouldThrowInvalidArgumentError.

@Test
public void mutate_StorageThrowsIllegalArgumentException_ShouldThrowInvalidArgumentError() 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);
    doThrow(IllegalArgumentException.class).when(storage).mutate(anyList());
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(responseObserver).onError(exceptionCaptor.capture());
    assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Status.Code.INVALID_ARGUMENT);
}
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 94 with Key

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

the class DistributedStorageServiceTest method mutate_IsCalledWithSingleDelete_StorageShouldBeCalledProperly.

@Test
public void mutate_IsCalledWithSingleDelete_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Delete(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 : Delete(com.scalar.db.api.Delete) Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 95 with Key

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

the class DistributedStorageServiceTest method mutate_IsCalledWithMixedPutAndDelete_StorageShouldBeCalledProperly.

@Test
public void mutate_IsCalledWithMixedPutAndDelete_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addAllMutation(Arrays.asList(ProtoUtils.toMutation(new Put(partitionKey)), ProtoUtils.toMutation(new Delete(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 : Delete(com.scalar.db.api.Delete) 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)

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