Search in sources :

Example 1 with TestResourceDefinition

use of org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ProvisionManagerImplTest method provision_should_fail_when_provisioner_fails.

@Test
void provision_should_fail_when_provisioner_fails() {
    when(provisioner.canProvision(isA(TestResourceDefinition.class))).thenReturn(true);
    when(provisioner.provision(isA(TestResourceDefinition.class))).thenReturn(failedFuture(new EdcException("error")));
    TransferProcess transferProcess = TransferProcess.Builder.newInstance().id("id").state(TransferProcessStates.REQUESTED.code()).resourceManifest(ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build()).build();
    var result = provisionManager.provision(transferProcess);
    assertThat(result).failsWithin(1, SECONDS).withThrowableOfType(ExecutionException.class).withRootCauseInstanceOf(EdcException.class).withMessageContaining("error");
}
Also used : TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) EdcException(org.eclipse.dataspaceconnector.spi.EdcException) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) Test(org.junit.jupiter.api.Test)

Example 2 with TestResourceDefinition

use of org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition in project DataSpaceConnector by eclipse-dataspaceconnector.

the class TransferProcessManagerImplTest method setup.

@BeforeEach
void setup() {
    var resourceManifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
    when(manifestGenerator.generateResourceManifest(any(TransferProcess.class))).thenReturn(resourceManifest);
    manager = TransferProcessManagerImpl.Builder.newInstance().provisionManager(provisionManager).dataFlowManager(mock(DataFlowManager.class)).waitStrategy(mock(ExponentialWaitStrategy.class)).batchSize(TRANSFER_MANAGER_BATCHSIZE).dispatcherRegistry(dispatcherRegistry).manifestGenerator(manifestGenerator).monitor(mock(Monitor.class)).commandQueue(mock(CommandQueue.class)).commandRunner(mock(CommandRunner.class)).typeManager(new TypeManager()).statusCheckerRegistry(statusCheckerRegistry).observable(mock(TransferProcessObservable.class)).store(store).build();
}
Also used : Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) ExponentialWaitStrategy(org.eclipse.dataspaceconnector.spi.retry.ExponentialWaitStrategy) CommandRunner(org.eclipse.dataspaceconnector.spi.command.CommandRunner) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with TestResourceDefinition

use of org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ProvisionManagerImplTest method provision_should_provision_all_the_transfer_process_definitions.

@Test
void provision_should_provision_all_the_transfer_process_definitions() {
    when(provisioner.canProvision(isA(TestResourceDefinition.class))).thenReturn(true);
    var provisionResult = StatusResult.success(ProvisionResponse.Builder.newInstance().resource(new TestProvisionedDataDestinationResource("test-resource", "1")).build());
    when(provisioner.provision(isA(TestResourceDefinition.class), isA(Policy.class))).thenReturn(completedFuture(provisionResult));
    var result = provisionManager.provision(List.of(new TestResourceDefinition()), policy);
    assertThat(result).succeedsWithin(1, SECONDS).extracting(responses -> responses.get(0)).extracting(StatusResult::getContent).extracting(ProvisionResponse::getResource).extracting(ProvisionedDataDestinationResource.class::cast).extracting(ProvisionedDataDestinationResource::getResourceName).isEqualTo("test-resource");
}
Also used : Policy(org.eclipse.dataspaceconnector.policy.model.Policy) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) BeforeEach(org.junit.jupiter.api.BeforeEach) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ProvisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedResource) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EdcException(org.eclipse.dataspaceconnector.spi.EdcException) Mockito.when(org.mockito.Mockito.when) StatusResult(org.eclipse.dataspaceconnector.spi.response.StatusResult) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) DeprovisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DeprovisionedResource) CompletableFuture.failedFuture(java.util.concurrent.CompletableFuture.failedFuture) Provisioner(org.eclipse.dataspaceconnector.spi.transfer.provision.Provisioner) List(java.util.List) ProvisionResponse(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse) ProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) Mockito.mock(org.mockito.Mockito.mock) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource) StatusResult(org.eclipse.dataspaceconnector.spi.response.StatusResult) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) Test(org.junit.jupiter.api.Test)

Example 4 with TestResourceDefinition

use of org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition in project DataSpaceConnector by eclipse-dataspaceconnector.

the class TransferProcessManagerImplIntegrationTest method verifyProvision_shouldNotStarve.

@Test
@DisplayName("Verify that no process 'starves' during two consecutive runs, when the batch size > number of processes")
void verifyProvision_shouldNotStarve() throws InterruptedException {
    var numProcesses = TRANSFER_MANAGER_BATCHSIZE * 2;
    var processesToProvision = new CountDownLatch(numProcesses);
    when(provisionManager.provision(any(), any(Policy.class))).thenAnswer(i -> {
        processesToProvision.countDown();
        return completedFuture(List.of(ProvisionResponse.Builder.newInstance().resource(new TestProvisionedDataDestinationResource("any", "1")).build()));
    });
    var manifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
    var processes = IntStream.range(0, numProcesses).mapToObj(i -> provisionedResourceSet()).map(resourceSet -> createUnsavedTransferProcess().resourceManifest(manifest).provisionedResourceSet(resourceSet).build()).peek(TransferProcess::transitionInitial).peek(store::create).collect(Collectors.toList());
    transferProcessManager.start();
    assertThat(processesToProvision.await(10, SECONDS)).isTrue();
    assertThat(processes).describedAs("All transfer processes state should be greater than INITIAL").allSatisfy(process -> {
        var id = process.getId();
        var storedProcess = store.find(id);
        assertThat(storedProcess).describedAs("Should exist in the TransferProcessStore").isNotNull();
        assertThat(storedProcess.getState()).isGreaterThan(INITIAL.code());
    });
    verify(provisionManager, times(numProcesses)).provision(any(), any());
}
Also used : Policy(org.eclipse.dataspaceconnector.policy.model.Policy) IntStream(java.util.stream.IntStream) UNSAVED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.UNSAVED) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) DataAddressResolver(org.eclipse.dataspaceconnector.spi.asset.DataAddressResolver) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ComponentTest(org.eclipse.dataspaceconnector.common.annotations.ComponentTest) ExponentialWaitStrategy(org.eclipse.dataspaceconnector.spi.retry.ExponentialWaitStrategy) CommandRunner(org.eclipse.dataspaceconnector.spi.command.CommandRunner) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) ProvisionManager(org.eclipse.dataspaceconnector.spi.transfer.provision.ProvisionManager) InMemoryTransferProcessStore(org.eclipse.dataspaceconnector.core.defaults.transferprocessstore.InMemoryTransferProcessStore) DataFlowManager(org.eclipse.dataspaceconnector.spi.transfer.flow.DataFlowManager) TransferProcessObservable(org.eclipse.dataspaceconnector.spi.transfer.observe.TransferProcessObservable) StatusCheckerRegistry(org.eclipse.dataspaceconnector.spi.types.domain.transfer.StatusCheckerRegistry) PolicyArchive(org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) 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) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) TransferProcessStore(org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore) DisplayName(org.junit.jupiter.api.DisplayName) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) TransferType(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferType) ProvisionResponse(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse) RemoteMessageDispatcherRegistry(org.eclipse.dataspaceconnector.spi.message.RemoteMessageDispatcherRegistry) CommandQueue(org.eclipse.dataspaceconnector.spi.command.CommandQueue) INITIAL(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.INITIAL) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) CountDownLatch(java.util.concurrent.CountDownLatch) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ComponentTest(org.eclipse.dataspaceconnector.common.annotations.ComponentTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with TestResourceDefinition

use of org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition in project DataSpaceConnector by eclipse-dataspaceconnector.

the class TransferProcessManagerImplIntegrationTest method setup.

@SuppressWarnings("unchecked")
@BeforeEach
void setup() {
    var resourceManifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
    when(manifestGenerator.generateConsumerResourceManifest(any(DataRequest.class), any(Policy.class))).thenReturn(resourceManifest);
    var policyArchive = mock(PolicyArchive.class);
    when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
    transferProcessManager = TransferProcessManagerImpl.Builder.newInstance().provisionManager(provisionManager).dataFlowManager(mock(DataFlowManager.class)).waitStrategy(mock(ExponentialWaitStrategy.class)).batchSize(TRANSFER_MANAGER_BATCHSIZE).dispatcherRegistry(mock(RemoteMessageDispatcherRegistry.class)).manifestGenerator(manifestGenerator).monitor(mock(Monitor.class)).commandQueue(mock(CommandQueue.class)).commandRunner(mock(CommandRunner.class)).typeManager(new TypeManager()).statusCheckerRegistry(mock(StatusCheckerRegistry.class)).observable(mock(TransferProcessObservable.class)).transferProcessStore(store).policyArchive(policyArchive).addressResolver(mock(DataAddressResolver.class)).build();
}
Also used : Policy(org.eclipse.dataspaceconnector.policy.model.Policy) DataAddressResolver(org.eclipse.dataspaceconnector.spi.asset.DataAddressResolver) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) StatusCheckerRegistry(org.eclipse.dataspaceconnector.spi.types.domain.transfer.StatusCheckerRegistry) ExponentialWaitStrategy(org.eclipse.dataspaceconnector.spi.retry.ExponentialWaitStrategy) RemoteMessageDispatcherRegistry(org.eclipse.dataspaceconnector.spi.message.RemoteMessageDispatcherRegistry) CommandRunner(org.eclipse.dataspaceconnector.spi.command.CommandRunner) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TestResourceDefinition (org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition)15 Policy (org.eclipse.dataspaceconnector.policy.model.Policy)13 Monitor (org.eclipse.dataspaceconnector.spi.monitor.Monitor)13 Test (org.junit.jupiter.api.Test)13 EdcException (org.eclipse.dataspaceconnector.spi.EdcException)12 CommandRunner (org.eclipse.dataspaceconnector.spi.command.CommandRunner)12 ExponentialWaitStrategy (org.eclipse.dataspaceconnector.spi.retry.ExponentialWaitStrategy)12 TypeManager (org.eclipse.dataspaceconnector.spi.types.TypeManager)12 List (java.util.List)11 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 DataAddressResolver (org.eclipse.dataspaceconnector.spi.asset.DataAddressResolver)11 RemoteMessageDispatcherRegistry (org.eclipse.dataspaceconnector.spi.message.RemoteMessageDispatcherRegistry)11 DataRequest (org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest)11 UUID (java.util.UUID)10 CompletableFuture.failedFuture (java.util.concurrent.CompletableFuture.failedFuture)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 CommandQueue (org.eclipse.dataspaceconnector.spi.command.CommandQueue)10 PolicyArchive (org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive)10 StatusResult (org.eclipse.dataspaceconnector.spi.response.StatusResult)10