use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryTransferProcessStore method update.
@Override
public void update(TransferProcess process) {
lockManager.writeLock(() -> {
process.updateStateTimestamp();
delete(process.getId());
TransferProcess internalCopy = process.copy();
processesByExternalId.put(process.getDataRequest().getId(), internalCopy);
processesById.put(process.getId(), internalCopy);
stateCache.computeIfAbsent(process.getState(), k -> new ArrayList<>()).add(internalCopy);
return null;
});
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryTransferProcessStoreTest method verifyOrderingByTimestamp.
@Test
void verifyOrderingByTimestamp() {
for (int i = 0; i < 100; i++) {
TransferProcess process = createProcess("test-process-" + i);
process.transitionInitial();
store.create(process);
}
List<TransferProcess> processes = store.nextForState(TransferProcessStates.INITIAL.code(), 50);
assertThat(processes).hasSize(50);
assertThat(processes).allMatch(p -> p.getStateTimestamp() > 0);
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryTransferProcessStoreTest method verifyNextForState_avoidsStarvation.
@Test
void verifyNextForState_avoidsStarvation() throws InterruptedException {
for (int i = 0; i < 10; i++) {
TransferProcess process = createProcess("test-process-" + i);
process.transitionInitial();
store.create(process);
}
var list1 = store.nextForState(TransferProcessStates.INITIAL.code(), 5);
// simulate a short delay to generate different timestamps
Thread.sleep(50);
list1.forEach(tp -> store.update(tp));
var list2 = store.nextForState(TransferProcessStates.INITIAL.code(), 5);
assertThat(list1).isNotEqualTo(list2).doesNotContainAnyElementsOf(list2);
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ProvisionManagerImplTest method deprovision_should_fail_when_provisioner_fails.
@Test
void deprovision_should_fail_when_provisioner_fails() {
when(provisioner.canDeprovision(isA(ProvisionedResource.class))).thenReturn(true);
when(provisioner.deprovision(isA(TestProvisionedResource.class))).thenReturn(failedFuture(new EdcException("error")));
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).failsWithin(1, SECONDS).withThrowableOfType(ExecutionException.class).withRootCauseInstanceOf(EdcException.class).withMessageContaining("error");
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess 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");
}
Aggregations