Search in sources :

Example 1 with TransferProcessDocument

use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosTransferProcessStoreIntegrationTest method invokeStoreProcedure.

@Test
void invokeStoreProcedure() {
    // create one item
    var tp = createTransferProcess("proc1");
    store.create(tp);
    List<Object> procedureParams = Arrays.asList(100, 5, connectorId);
    CosmosStoredProcedureRequestOptions options = new CosmosStoredProcedureRequestOptions();
    options.setPartitionKey(PartitionKey.NONE);
    CosmosStoredProcedureResponse sprocResponse = container.getScripts().getStoredProcedure("nextForState").execute(procedureParams, options);
    var result = sprocResponse.getResponseAsString();
    var l = typeManager.readValue(result, List.class);
    List<TransferProcessDocument> documents = (List<TransferProcessDocument>) l.stream().map(o -> typeManager.writeValueAsString(o)).map(json -> typeManager.readValue(json.toString(), TransferProcessDocument.class)).collect(Collectors.toList());
    assertThat(documents).allSatisfy(document -> {
        assertThat(document.getLease()).isNotNull().hasFieldOrPropertyWithValue("leasedBy", connectorId).hasFieldOrProperty("leasedAt");
    });
}
Also used : BadRequestException(com.azure.cosmos.implementation.BadRequestException) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CosmosTestClient(org.eclipse.dataspaceconnector.azure.testfixtures.CosmosTestClient) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CosmosDatabase(com.azure.cosmos.CosmosDatabase) PartitionKey(com.azure.cosmos.models.PartitionKey) Scanner(java.util.Scanner) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) TestHelper.createTransferProcess(org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcess) AfterAll(org.junit.jupiter.api.AfterAll) CosmosStoredProcedureRequestOptions(com.azure.cosmos.models.CosmosStoredProcedureRequestOptions) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) CosmosDbApiImpl(org.eclipse.dataspaceconnector.azure.cosmos.CosmosDbApiImpl) ResourceManifest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceManifest) CosmosStoredProcedureProperties(com.azure.cosmos.models.CosmosStoredProcedureProperties) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) EdcException(org.eclipse.dataspaceconnector.spi.EdcException) CosmosStoredProcedureResponse(com.azure.cosmos.models.CosmosStoredProcedureResponse) UUID(java.util.UUID) CosmosItemResponse(com.azure.cosmos.models.CosmosItemResponse) TransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument) Collectors(java.util.stream.Collectors) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) CosmosScripts(com.azure.cosmos.CosmosScripts) CosmosPagedIterable(com.azure.cosmos.util.CosmosPagedIterable) IntegrationTest(org.eclipse.dataspaceconnector.common.annotations.IntegrationTest) CosmosContainer(com.azure.cosmos.CosmosContainer) TransferProcessStates(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates) CosmosStoredProcedureRequestOptions(com.azure.cosmos.models.CosmosStoredProcedureRequestOptions) TransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument) List(java.util.List) CosmosStoredProcedureResponse(com.azure.cosmos.models.CosmosStoredProcedureResponse) Test(org.junit.jupiter.api.Test) IntegrationTest(org.eclipse.dataspaceconnector.common.annotations.IntegrationTest)

Example 2 with TransferProcessDocument

use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosTransferProcessStore method update.

@Override
public void update(TransferProcess process) {
    var document = new TransferProcessDocument(process, partitionKey);
    try {
        leaseContext.acquireLease(process.getId());
        failsafeExecutor.run(() -> cosmosDbApi.saveItem(document));
        leaseContext.breakLease(process.getId());
    } catch (BadRequestException ex) {
        throw new EdcException(ex);
    }
}
Also used : TransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument) BadRequestException(com.azure.cosmos.implementation.BadRequestException) EdcException(org.eclipse.dataspaceconnector.spi.EdcException)

Example 3 with TransferProcessDocument

use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosTransferProcessStoreIntegrationTest method nextForState_verifyDelete.

@Test
@DisplayName("Verify that a leased entity can still be deleted")
void nextForState_verifyDelete() {
    var tp = createTransferProcess("test-id", TransferProcessStates.IN_PROGRESS);
    var doc = new TransferProcessDocument(tp, partitionKey);
    container.upsertItem(doc);
    var result = store.nextForState(TransferProcessStates.IN_PROGRESS.code(), 5);
    assertThat(result).hasSize(1);
    // make sure the lease is acquired
    var leasedDoc = readDocument(tp.getId());
    assertThat(leasedDoc.getLease()).isNotNull();
    store.delete(tp.getId());
    assertThat(container.readAllItems(new PartitionKey(partitionKey), Object.class)).isEmpty();
}
Also used : TransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument) TestHelper.createTransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcessDocument) PartitionKey(com.azure.cosmos.models.PartitionKey) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TransferProcessDocument

use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosTransferProcessStoreIntegrationTest method nextForState_shouldOnlyReturnFreeItems.

@Test
void nextForState_shouldOnlyReturnFreeItems() {
    String id1 = "process1";
    var tp = createTransferProcess(id1, TransferProcessStates.INITIAL);
    String id2 = "process2";
    var tp2 = createTransferProcess(id2, TransferProcessStates.INITIAL);
    store.create(tp);
    store.create(tp2);
    TransferProcessDocument item = readDocument(id2);
    item.acquireLease("test-leaser");
    container.upsertItem(item);
    // act - one should be ignored
    List<TransferProcess> processes = store.nextForState(TransferProcessStates.INITIAL.code(), 5);
    assertThat(processes).hasSize(1).allMatch(p -> p.getId().equals(id1));
}
Also used : TransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument) TestHelper.createTransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcessDocument) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) TestHelper.createTransferProcess(org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcess) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with TransferProcessDocument

use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosTransferProcessStoreIntegrationTest method invokeStoredProcedure.

@Test
void invokeStoredProcedure() {
    // create one item
    var tp = createTransferProcess("proc1");
    store.create(tp);
    List<Object> procedureParams = Arrays.asList(100, 5, connectorId);
    CosmosStoredProcedureRequestOptions options = new CosmosStoredProcedureRequestOptions();
    options.setPartitionKey(PartitionKey.NONE);
    CosmosStoredProcedureResponse sprocResponse = container.getScripts().getStoredProcedure("nextForState").execute(procedureParams, options);
    var result = sprocResponse.getResponseAsString();
    var l = typeManager.readValue(result, List.class);
    List<TransferProcessDocument> documents = (List<TransferProcessDocument>) l.stream().map(o -> typeManager.writeValueAsString(o)).map(json -> typeManager.readValue(json.toString(), TransferProcessDocument.class)).collect(Collectors.toList());
    assertThat(documents).allSatisfy(document -> {
        assertThat(document.getLease()).isNotNull().hasFieldOrPropertyWithValue("leasedBy", connectorId).hasFieldOrProperty("leasedAt");
    });
}
Also used : SortOrder(org.eclipse.dataspaceconnector.spi.query.SortOrder) IntStream(java.util.stream.IntStream) BadRequestException(com.azure.cosmos.implementation.BadRequestException) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CosmosTestClient(org.eclipse.dataspaceconnector.azure.testfixtures.CosmosTestClient) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CosmosDatabase(com.azure.cosmos.CosmosDatabase) PartitionKey(com.azure.cosmos.models.PartitionKey) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) TestHelper.createTransferProcess(org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcess) AfterAll(org.junit.jupiter.api.AfterAll) CosmosStoredProcedureRequestOptions(com.azure.cosmos.models.CosmosStoredProcedureRequestOptions) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) CosmosDbApiImpl(org.eclipse.dataspaceconnector.azure.cosmos.CosmosDbApiImpl) ResourceManifest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceManifest) Awaitility.await(org.awaitility.Awaitility.await) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) RetryPolicy(net.jodah.failsafe.RetryPolicy) EdcException(org.eclipse.dataspaceconnector.spi.EdcException) CosmosStoredProcedureResponse(com.azure.cosmos.models.CosmosStoredProcedureResponse) UUID(java.util.UUID) CosmosItemResponse(com.azure.cosmos.models.CosmosItemResponse) TransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument) Collectors(java.util.stream.Collectors) QuerySpec(org.eclipse.dataspaceconnector.spi.query.QuerySpec) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) TestHelper.createTransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcessDocument) ChronoUnit(java.time.temporal.ChronoUnit) CosmosPagedIterable(com.azure.cosmos.util.CosmosPagedIterable) CosmosContainer(com.azure.cosmos.CosmosContainer) TransferProcessStates(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates) Comparator(java.util.Comparator) CosmosStoredProcedureRequestOptions(com.azure.cosmos.models.CosmosStoredProcedureRequestOptions) TransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument) TestHelper.createTransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcessDocument) List(java.util.List) CosmosStoredProcedureResponse(com.azure.cosmos.models.CosmosStoredProcedureResponse) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

TransferProcessDocument (org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument)7 Test (org.junit.jupiter.api.Test)6 AzureCosmosDbIntegrationTest (org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest)5 TestHelper.createTransferProcessDocument (org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcessDocument)5 PartitionKey (com.azure.cosmos.models.PartitionKey)4 TransferProcess (org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess)4 TestHelper.createTransferProcess (org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcess)4 BadRequestException (com.azure.cosmos.implementation.BadRequestException)3 EdcException (org.eclipse.dataspaceconnector.spi.EdcException)3 DisplayName (org.junit.jupiter.api.DisplayName)3 CosmosContainer (com.azure.cosmos.CosmosContainer)2 CosmosDatabase (com.azure.cosmos.CosmosDatabase)2 CosmosItemResponse (com.azure.cosmos.models.CosmosItemResponse)2 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)2 CosmosStoredProcedureResponse (com.azure.cosmos.models.CosmosStoredProcedureResponse)2 CosmosPagedIterable (com.azure.cosmos.util.CosmosPagedIterable)2 Duration (java.time.Duration)2 ChronoUnit (java.time.temporal.ChronoUnit)2 Arrays (java.util.Arrays)2 List (java.util.List)2