Search in sources :

Example 1 with TransferType

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

the class TransferProcessManagerImplIntegrationTest method createUnsavedTransferProcess.

private TransferProcess.Builder createUnsavedTransferProcess() {
    String processId = UUID.randomUUID().toString();
    var dataRequest = DataRequest.Builder.newInstance().id(processId).transferType(new TransferType()).managedResources(true).destinationType("test-type").contractId(UUID.randomUUID().toString()).build();
    return TransferProcess.Builder.newInstance().provisionedResourceSet(ProvisionedResourceSet.Builder.newInstance().build()).type(TransferProcess.Type.CONSUMER).id("test-process-" + processId).state(UNSAVED.code()).dataRequest(dataRequest);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TransferType(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferType)

Example 2 with TransferType

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

the class TransferProcessManagerImplTest method verifyCompleted_noCheckerForSomeResources.

@Test
@DisplayName("checkComplete: should automatically transition process with no managed resources if no checker")
void verifyCompleted_noCheckerForSomeResources() throws InterruptedException {
    var process = createTransferProcess(IN_PROGRESS, new TransferType(), false);
    process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
    process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
    var latch = countDownOnUpdateLatch();
    when(transferProcessStore.nextForState(eq(IN_PROGRESS.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
    when(statusCheckerRegistry.resolve(anyString())).thenReturn(null);
    manager.start();
    assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
    verify(statusCheckerRegistry, atLeastOnce()).resolve(any());
    verify(transferProcessStore).update(argThat(p -> p.getState() == COMPLETED.code()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PROVISIONING(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.PROVISIONING) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) DataAddressResolver(org.eclipse.dataspaceconnector.spi.asset.DataAddressResolver) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExponentialWaitStrategy(org.eclipse.dataspaceconnector.spi.retry.ExponentialWaitStrategy) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) PROVISIONED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.PROVISIONED) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ProvisionManager(org.eclipse.dataspaceconnector.spi.transfer.provision.ProvisionManager) Mockito.doThrow(org.mockito.Mockito.doThrow) DataFlowManager(org.eclipse.dataspaceconnector.spi.transfer.flow.DataFlowManager) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) SecretToken(org.eclipse.dataspaceconnector.spi.types.domain.transfer.SecretToken) StatusCheckerRegistry(org.eclipse.dataspaceconnector.spi.types.domain.transfer.StatusCheckerRegistry) PolicyArchive(org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) ERROR(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.ERROR) Collections.emptyList(java.util.Collections.emptyList) ENDED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.ENDED) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) EdcException(org.eclipse.dataspaceconnector.spi.EdcException) PROVIDER(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess.Type.PROVIDER) DEPROVISIONED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.DEPROVISIONED) UUID(java.util.UUID) JsonPOJOBuilder(com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder) StatusResult(org.eclipse.dataspaceconnector.spi.response.StatusResult) Instant(java.time.Instant) TransferProcessStore(org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test) DeprovisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DeprovisionedResource) CountDownLatch(java.util.concurrent.CountDownLatch) CompletableFuture.failedFuture(java.util.concurrent.CompletableFuture.failedFuture) List(java.util.List) TransferType(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferType) ProvisionResponse(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse) UTC(java.time.ZoneOffset.UTC) CommandQueue(org.eclipse.dataspaceconnector.spi.command.CommandQueue) ProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) REQUESTING(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.REQUESTING) ProvisionedContentResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedContentResource) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Result(org.eclipse.dataspaceconnector.spi.result.Result) CommandRunner(org.eclipse.dataspaceconnector.spi.command.CommandRunner) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) DEPROVISIONING(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.DEPROVISIONING) TransferProcessObservable(org.eclipse.dataspaceconnector.spi.transfer.observe.TransferProcessObservable) REQUESTED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.REQUESTED) STREAMING(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.STREAMING) IN_PROGRESS(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.IN_PROGRESS) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) CONSUMER(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess.Type.CONSUMER) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) ResponseStatus(org.eclipse.dataspaceconnector.spi.response.ResponseStatus) ResourceManifest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceManifest) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) ResourceManifestGenerator(org.eclipse.dataspaceconnector.spi.transfer.provision.ResourceManifestGenerator) ProvisionedResourceSet(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedResourceSet) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) Mockito.times(org.mockito.Mockito.times) Vault(org.eclipse.dataspaceconnector.spi.security.Vault) Mockito.when(org.mockito.Mockito.when) DisplayName(org.junit.jupiter.api.DisplayName) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) COMPLETED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.COMPLETED) Mockito.never(org.mockito.Mockito.never) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) RemoteMessageDispatcherRegistry(org.eclipse.dataspaceconnector.spi.message.RemoteMessageDispatcherRegistry) Clock(java.time.Clock) INITIAL(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.INITIAL) TransferProcessStates(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TransferType(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with TransferType

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

the class TransferProcessManagerImplTest method verifyCompletedNonManagedResources.

@Test
@DisplayName("checkComplete: should transition process with no managed resources if checker returns completed")
void verifyCompletedNonManagedResources() throws InterruptedException {
    TransferProcess process = createTransferProcess(REQUESTED, new TransferType(), false);
    process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
    process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
    when(transferProcessStore.nextForState(eq(IN_PROGRESS.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
    when(statusCheckerRegistry.resolve(anyString())).thenReturn((tp, resources) -> true);
    var latch = countDownOnUpdateLatch();
    manager.start();
    assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
    verify(statusCheckerRegistry, atLeastOnce()).resolve(any());
    verify(transferProcessStore).update(argThat(p -> p.getState() == COMPLETED.code()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PROVISIONING(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.PROVISIONING) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) DataAddressResolver(org.eclipse.dataspaceconnector.spi.asset.DataAddressResolver) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExponentialWaitStrategy(org.eclipse.dataspaceconnector.spi.retry.ExponentialWaitStrategy) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) PROVISIONED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.PROVISIONED) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ProvisionManager(org.eclipse.dataspaceconnector.spi.transfer.provision.ProvisionManager) Mockito.doThrow(org.mockito.Mockito.doThrow) DataFlowManager(org.eclipse.dataspaceconnector.spi.transfer.flow.DataFlowManager) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) SecretToken(org.eclipse.dataspaceconnector.spi.types.domain.transfer.SecretToken) StatusCheckerRegistry(org.eclipse.dataspaceconnector.spi.types.domain.transfer.StatusCheckerRegistry) PolicyArchive(org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) ERROR(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.ERROR) Collections.emptyList(java.util.Collections.emptyList) ENDED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.ENDED) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) EdcException(org.eclipse.dataspaceconnector.spi.EdcException) PROVIDER(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess.Type.PROVIDER) DEPROVISIONED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.DEPROVISIONED) UUID(java.util.UUID) JsonPOJOBuilder(com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder) StatusResult(org.eclipse.dataspaceconnector.spi.response.StatusResult) Instant(java.time.Instant) TransferProcessStore(org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test) DeprovisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DeprovisionedResource) CountDownLatch(java.util.concurrent.CountDownLatch) CompletableFuture.failedFuture(java.util.concurrent.CompletableFuture.failedFuture) List(java.util.List) TransferType(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferType) ProvisionResponse(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse) UTC(java.time.ZoneOffset.UTC) CommandQueue(org.eclipse.dataspaceconnector.spi.command.CommandQueue) ProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) REQUESTING(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.REQUESTING) ProvisionedContentResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedContentResource) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Result(org.eclipse.dataspaceconnector.spi.result.Result) CommandRunner(org.eclipse.dataspaceconnector.spi.command.CommandRunner) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) DEPROVISIONING(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.DEPROVISIONING) TransferProcessObservable(org.eclipse.dataspaceconnector.spi.transfer.observe.TransferProcessObservable) REQUESTED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.REQUESTED) STREAMING(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.STREAMING) IN_PROGRESS(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.IN_PROGRESS) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) CONSUMER(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess.Type.CONSUMER) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) ResponseStatus(org.eclipse.dataspaceconnector.spi.response.ResponseStatus) ResourceManifest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceManifest) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) ResourceManifestGenerator(org.eclipse.dataspaceconnector.spi.transfer.provision.ResourceManifestGenerator) ProvisionedResourceSet(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedResourceSet) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) Mockito.times(org.mockito.Mockito.times) Vault(org.eclipse.dataspaceconnector.spi.security.Vault) Mockito.when(org.mockito.Mockito.when) DisplayName(org.junit.jupiter.api.DisplayName) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) COMPLETED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.COMPLETED) Mockito.never(org.mockito.Mockito.never) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) RemoteMessageDispatcherRegistry(org.eclipse.dataspaceconnector.spi.message.RemoteMessageDispatcherRegistry) Clock(java.time.Clock) INITIAL(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.INITIAL) TransferProcessStates(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) TransferType(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TransferType

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

the class TransferProcessManagerImplTest method verifyCheckProvisioned_allAreNonFinite.

@Test
@DisplayName("checkProvisioned: all resources belong to non-finite processes")
void verifyCheckProvisioned_allAreNonFinite() throws InterruptedException {
    TransferType type = TransferType.Builder.transferType().isFinite(false).build();
    TransferProcess process = createTransferProcess(REQUESTED_ACK, type, true);
    process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
    var cdl = new CountDownLatch(1);
    when(store.nextForState(eq(REQUESTED_ACK.code()), anyInt())).thenReturn(List.of(process));
    doAnswer(i -> {
        cdl.countDown();
        return null;
    }).when(store).update(process);
    manager.start();
    assertThat(cdl.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
    assertThat(process.getState()).describedAs("State should be STREAMING").isEqualTo(TransferProcessStates.STREAMING.code());
    verify(store, atLeastOnce()).nextForState(anyInt(), anyInt());
    verify(store, atLeastOnce()).update(process);
}
Also used : TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) CountDownLatch(java.util.concurrent.CountDownLatch) TransferType(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TransferType (org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferType)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)2 JsonTypeName (com.fasterxml.jackson.annotation.JsonTypeName)2 JsonDeserialize (com.fasterxml.jackson.databind.annotation.JsonDeserialize)2 JsonPOJOBuilder (com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder)2 Clock (java.time.Clock)2 Instant (java.time.Instant)2 UTC (java.time.ZoneOffset.UTC)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 CompletableFuture.failedFuture (java.util.concurrent.CompletableFuture.failedFuture)2 TimeUnit (java.util.concurrent.TimeUnit)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Policy (org.eclipse.dataspaceconnector.policy.model.Policy)2 EdcException (org.eclipse.dataspaceconnector.spi.EdcException)2 DataAddressResolver (org.eclipse.dataspaceconnector.spi.asset.DataAddressResolver)2