use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceManifest 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.spi.types.domain.transfer.ResourceManifest in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method deprovisioning_shouldTransitionToDeprovisioned.
@Test
void deprovisioning_shouldTransitionToDeprovisioned() throws InterruptedException {
var manifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
var resourceSet = ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TokenTestProvisionResource("test", PROVISIONED_RESOURCE_ID))).build();
var process = createTransferProcess(DEPROVISIONING).toBuilder().resourceManifest(manifest).provisionedResourceSet(resourceSet).build();
var deprovisionResult = StatusResult.success(DeprovisionedResource.Builder.newInstance().provisionedResourceId(PROVISIONED_RESOURCE_ID).build());
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(vault.deleteSecret(any())).thenReturn(Result.success());
when(provisionManager.deprovision(any(), isA(Policy.class))).thenReturn(completedFuture(List.of(deprovisionResult)));
when(transferProcessStore.nextForState(eq(DEPROVISIONING.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
when(transferProcessStore.find(process.getId())).thenReturn(process);
var latch = countDownOnUpdateLatch();
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(policyArchive, atLeastOnce()).findPolicyForContract(anyString());
verify(transferProcessStore).update(argThat(p -> p.getState() == DEPROVISIONED.code()));
verify(vault).deleteSecret(any());
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceManifest in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method provisioning_shouldContinueOnRetryProvisionError.
@Test
void provisioning_shouldContinueOnRetryProvisionError() throws InterruptedException {
var process = createTransferProcess(PROVISIONING).toBuilder().resourceManifest(ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build()).build();
var provisionResult = StatusResult.<ProvisionResponse>failure(ResponseStatus.ERROR_RETRY, "test error");
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(provisionManager.provision(any(), isA(Policy.class))).thenReturn(completedFuture(List.of(provisionResult)));
when(transferProcessStore.nextForState(eq(PROVISIONING.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
when(transferProcessStore.find(process.getId())).thenReturn(process);
var latch = countDownOnUpdateLatch();
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(policyArchive, atLeastOnce()).findPolicyForContract(anyString());
verify(transferProcessStore).update(argThat(p -> p.getState() == PROVISIONING.code()));
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceManifest in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method initial_shouldTransitionToProvisioning.
@Test
void initial_shouldTransitionToProvisioning() throws InterruptedException {
var process = createTransferProcess(INITIAL);
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(transferProcessStore.nextForState(eq(INITIAL.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
var resourceManifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
when(manifestGenerator.generateConsumerResourceManifest(any(DataRequest.class), any(Policy.class))).thenReturn(resourceManifest);
var latch = countDownOnUpdateLatch();
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(policyArchive, atLeastOnce()).findPolicyForContract(anyString());
verifyNoInteractions(provisionManager);
verify(transferProcessStore).update(argThat(p -> p.getState() == PROVISIONING.code()));
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceManifest in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImpl method processInitial.
/**
* Process INITIAL transfer<p>
* set it to PROVISIONING
*
* @param process the INITIAL transfer fetched
* @return if the transfer has been processed or not
*/
@WithSpan
private boolean processInitial(TransferProcess process) {
var dataRequest = process.getDataRequest();
var policy = policyArchive.findPolicyForContract(dataRequest.getContractId());
ResourceManifest manifest;
if (process.getType() == CONSUMER) {
manifest = manifestGenerator.generateConsumerResourceManifest(dataRequest, policy);
} else {
var assetId = process.getDataRequest().getAssetId();
var dataAddress = addressResolver.resolveForAsset(assetId);
if (dataAddress == null) {
process.transitionError("Asset not found: " + assetId);
updateTransferProcess(process, l -> l.preError(process));
}
// default the content address to the asset address; this may be overridden during provisioning
process.addContentDataAddress(dataAddress);
manifest = manifestGenerator.generateProviderResourceManifest(dataRequest, dataAddress, policy);
}
process.transitionProvisioning(manifest);
updateTransferProcess(process, l -> l.preProvisioning(process));
return true;
}
Aggregations