Search in sources :

Example 1 with TransferProcess

use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.

the class InMemoryTransferProcessStore method update.

@Override
public void update(TransferProcess process) {
    lockManager.writeLock(() -> {
        process.updateStateTimestamp();
        delete(process.getId());
        TransferProcess internalCopy = process.copy();
        processesByExternalId.put(process.getDataRequest().getId(), internalCopy);
        processesById.put(process.getId(), internalCopy);
        stateCache.computeIfAbsent(process.getState(), k -> new ArrayList<>()).add(internalCopy);
        return null;
    });
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Collectors(java.util.stream.Collectors) TransferProcessStore(org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) LockManager(org.eclipse.dataspaceconnector.common.concurrency.LockManager) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) ArrayList(java.util.ArrayList) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess)

Example 2 with TransferProcess

use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.

the class InMemoryTransferProcessStoreTest method verifyOrderingByTimestamp.

@Test
void verifyOrderingByTimestamp() {
    for (int i = 0; i < 100; i++) {
        TransferProcess process = createProcess("test-process-" + i);
        process.transitionInitial();
        store.create(process);
    }
    List<TransferProcess> processes = store.nextForState(TransferProcessStates.INITIAL.code(), 50);
    assertThat(processes).hasSize(50);
    assertThat(processes).allMatch(p -> p.getStateTimestamp() > 0);
}
Also used : TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) Test(org.junit.jupiter.api.Test)

Example 3 with TransferProcess

use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.

the class InMemoryTransferProcessStoreTest method verifyNextForState_avoidsStarvation.

@Test
void verifyNextForState_avoidsStarvation() throws InterruptedException {
    for (int i = 0; i < 10; i++) {
        TransferProcess process = createProcess("test-process-" + i);
        process.transitionInitial();
        store.create(process);
    }
    var list1 = store.nextForState(TransferProcessStates.INITIAL.code(), 5);
    // simulate a short delay to generate different timestamps
    Thread.sleep(50);
    list1.forEach(tp -> store.update(tp));
    var list2 = store.nextForState(TransferProcessStates.INITIAL.code(), 5);
    assertThat(list1).isNotEqualTo(list2).doesNotContainAnyElementsOf(list2);
}
Also used : TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) Test(org.junit.jupiter.api.Test)

Example 4 with TransferProcess

use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ProvisionManagerImplTest method deprovision_should_fail_when_provisioner_fails.

@Test
void deprovision_should_fail_when_provisioner_fails() {
    when(provisioner.canDeprovision(isA(ProvisionedResource.class))).thenReturn(true);
    when(provisioner.deprovision(isA(TestProvisionedResource.class))).thenReturn(failedFuture(new EdcException("error")));
    TransferProcess transferProcess = TransferProcess.Builder.newInstance().id("id").state(TransferProcessStates.REQUESTED.code()).provisionedResourceSet(ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TestProvisionedResource())).build()).build();
    var result = provisionManager.deprovision(transferProcess);
    assertThat(result).failsWithin(1, SECONDS).withThrowableOfType(ExecutionException.class).withRootCauseInstanceOf(EdcException.class).withMessageContaining("error");
}
Also used : EdcException(org.eclipse.dataspaceconnector.spi.EdcException) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) ProvisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedResource) Test(org.junit.jupiter.api.Test)

Example 5 with TransferProcess

use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ProvisionManagerImplTest method deprovision_should_deprovision_all_the_transfer_process_provisioned_resources.

@Test
void deprovision_should_deprovision_all_the_transfer_process_provisioned_resources() {
    var deprovisionResponse = DeprovisionResponse.Builder.newInstance().resource(new TestProvisionedDataDestinationResource("test-resource")).build();
    when(provisioner.canDeprovision(isA(ProvisionedResource.class))).thenReturn(true);
    when(provisioner.deprovision(isA(TestProvisionedResource.class))).thenReturn(completedFuture(deprovisionResponse));
    TransferProcess transferProcess = TransferProcess.Builder.newInstance().id("id").state(TransferProcessStates.REQUESTED.code()).provisionedResourceSet(ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TestProvisionedResource())).build()).build();
    var result = provisionManager.deprovision(transferProcess);
    assertThat(result).succeedsWithin(1, SECONDS).extracting(responses -> responses.get(0)).extracting(DeprovisionResponse::getResource).extracting(ProvisionedDataDestinationResource.class::cast).extracting(ProvisionedDataDestinationResource::getResourceName).isEqualTo("test-resource");
}
Also used : TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ProvisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedResource) Test(org.junit.jupiter.api.Test)

Aggregations

TransferProcess (org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess)41 Test (org.junit.jupiter.api.Test)32 CountDownLatch (java.util.concurrent.CountDownLatch)13 List (java.util.List)12 TransferProcessStore (org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore)9 DisplayName (org.junit.jupiter.api.DisplayName)9 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 ArrayList (java.util.ArrayList)6 Collections (java.util.Collections)6 Comparator (java.util.Comparator)6 HashMap (java.util.HashMap)6 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)6 Collectors.toList (java.util.stream.Collectors.toList)6 LockManager (org.eclipse.dataspaceconnector.common.concurrency.LockManager)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 AzureCosmosDbIntegrationTest (org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest)5 TestHelper.createTransferProcess (org.eclipse.dataspaceconnector.transfer.store.cosmos.TestHelper.createTransferProcess)4 Stream (java.util.stream.Stream)3