Skip to content

Commit

Permalink
chore: Changed the state of the transfer process when EDR expires fro…
Browse files Browse the repository at this point in the history
…m Completed to Terminated (#948)
  • Loading branch information
wolf4ood authored Dec 20, 2023
1 parent 59d2654 commit c431a9c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void update(EndpointDataReferenceEntry edrEntry) {


private ProcessorImpl<EndpointDataReferenceEntry> processEdrInState(EndpointDataReferenceEntryStates state, Function<EndpointDataReferenceEntry, Boolean> function) {
var filter = new Criterion[] {hasState(state.code())};
var filter = new Criterion[]{ hasState(state.code()) };
return processor(() -> edrCache.nextNotLeased(batchSize, filter), telemetry.contextPropagationMiddleware(function));
}

Expand Down Expand Up @@ -222,7 +222,7 @@ private StatusResult<Void> checkExpiration(EndpointDataReferenceEntry entry) {
return StatusResult.success();
} else {
breakLease(entry);
return StatusResult.failure(ResponseStatus.ERROR_RETRY, "Not yet expired.");
return StatusResult.success();
}
}

Expand Down Expand Up @@ -302,6 +302,10 @@ private Builder() {
edrManager = new EdrManagerImpl();
}

public static Builder newInstance() {
return new Builder();
}

public Builder contractNegotiationService(ContractNegotiationService negotiationService) {
edrManager.contractNegotiationService = negotiationService;
return this;
Expand Down Expand Up @@ -373,9 +377,5 @@ public EdrManagerImpl build() {

return edrManager;
}

public static Builder newInstance() {
return new Builder();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private void cleanOldEdr(String assetId, String agreementId) {

var transferProcess = transferProcessStore.findById(entry.getTransferProcessId());

if (transferProcess != null && transferProcess.canBeCompleted()) {
transferProcess.transitionCompleting();
if (transferProcess != null && transferProcess.canBeTerminated()) {
transferProcess.transitionTerminating();
transferProcessStore.save(transferProcess);
} else {
monitor.info(format("Cannot terminate transfer process with id: %s", entry.getTransferProcessId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ public String requestTransfer(String dataRequestId, String contractId, String as

}

public JsonArray getAllTransferProcess() {
return baseRequest()
.when()
.post("/v2/transferprocesses/request")
.then()
.statusCode(200)
.extract()
.body()
.as(JsonArray.class);
}

public String getTransferProcessState(String id) {
return baseRequest()
.when()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,28 @@ void negotiateEdr_shouldRenewTheEdr() throws IOException {
.findFirst()
.orElseThrow();

// Check Termination on Sokrates
await().pollInterval(fibonacci())
.atMost(ASYNC_TIMEOUT)
.untilAsserted(() -> {
var tpState = SOKRATES.getTransferProcessState(transferProcessId);
assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.COMPLETED.toString());
assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.TERMINATED.toString());
});


// Check Termination on Plato
await().pollInterval(fibonacci())
.atMost(ASYNC_TIMEOUT)
.untilAsserted(() -> {
var tpState = PLATO.getAllTransferProcess()
.stream()
.filter(json -> json.asJsonObject().getJsonString("correlationId").getString().equals(transferProcessId))
.map(json -> json.asJsonObject().getJsonString("state").getString())
.findFirst();

assertThat(tpState)
.isPresent()
.hasValue(TransferProcessStates.TERMINATED.toString());
});
}

Expand Down

0 comments on commit c431a9c

Please sign in to comment.