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");
}
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();
}
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");
}
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());
}
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();
}
Aggregations