use of org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ProvisionManagerImplTest method deprovision_should_deprovision_all_the_transfer_process_provisioned_resources.
@Test
void deprovision_should_deprovision_all_the_transfer_process_provisioned_resources() {
var deprovisionResponse = DeprovisionResponse.Builder.newInstance().resource(new TestProvisionedDataDestinationResource("test-resource")).build();
when(provisioner.canDeprovision(isA(ProvisionedResource.class))).thenReturn(true);
when(provisioner.deprovision(isA(TestProvisionedResource.class))).thenReturn(completedFuture(deprovisionResponse));
TransferProcess transferProcess = TransferProcess.Builder.newInstance().id("id").state(TransferProcessStates.REQUESTED.code()).provisionedResourceSet(ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TestProvisionedResource())).build()).build();
var result = provisionManager.deprovision(transferProcess);
assertThat(result).succeedsWithin(1, SECONDS).extracting(responses -> responses.get(0)).extracting(DeprovisionResponse::getResource).extracting(ProvisionedDataDestinationResource.class::cast).extracting(ProvisionedDataDestinationResource::getResourceName).isEqualTo("test-resource");
}
use of org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource 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.TestProvisionedDataDestinationResource 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.TestProvisionedDataDestinationResource in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method deprovisioning_shouldTransitionToErrorOnFatalDeprovisionError.
@Test
void deprovisioning_shouldTransitionToErrorOnFatalDeprovisionError() throws InterruptedException {
var manifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
var resourceSet = ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TestProvisionedDataDestinationResource("test", PROVISIONED_RESOURCE_ID))).build();
var process = createTransferProcess(DEPROVISIONING).toBuilder().resourceManifest(manifest).provisionedResourceSet(resourceSet).build();
var deprovisionResult = StatusResult.<DeprovisionedResource>failure(ResponseStatus.FATAL_ERROR, "test error");
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
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() == ERROR.code()));
}
use of org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method deprovisioning_shouldNotTransitionOnRetriableDeprovisionError.
@Test
void deprovisioning_shouldNotTransitionOnRetriableDeprovisionError() throws InterruptedException {
var manifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
var resourceSet = ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TestProvisionedDataDestinationResource("test", PROVISIONED_RESOURCE_ID))).build();
var process = createTransferProcess(DEPROVISIONING).toBuilder().resourceManifest(manifest).provisionedResourceSet(resourceSet).build();
var deprovisionResult = StatusResult.<DeprovisionedResource>failure(ResponseStatus.ERROR_RETRY, "test error");
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
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(transferProcessStore).update(argThat(p -> p.getState() == DEPROVISIONING.code()));
verify(policyArchive, atLeastOnce()).findPolicyForContract(anyString());
}
Aggregations