use of org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore 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.transfer.store.TransferProcessStore 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.transfer.store.TransferProcessStore 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.transfer.store.TransferProcessStore 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()));
}
use of org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore 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()));
}
Aggregations