Skip to content

Commit

Permalink
fix: Interrupt the transfer process earlier for terminated contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed Oct 29, 2024
1 parent 0d9974e commit 98fd9e3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).

- Refactoring: Config as Java Code ([#1051](https://github.com/sovity/edc-ce/pull/1051))
- Fix issues with the Create Data Offer Endpoint ([PR#1055](https://github.com/sovity/edc-ce/pull/1055))
- Interrupt the transfer process earlier (TODO PR#)

### Deployment Migration Notes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class TransferProcessBlocker implements TransferProcessListener {
private final DslContextFactory dslContextFactory;
private final ContractAgreementIsTerminatedQuery contractAgreementIsTerminated;

@Override
public void preRequesting(TransferProcess process) {
private void stopIt(TransferProcess process) {
val terminated = dslContextFactory.transactionResult(dsl ->
contractAgreementIsTerminated.isTerminated(dsl, process.getContractId()));

Expand All @@ -37,4 +36,9 @@ public void preRequesting(TransferProcess process) {
throw new IllegalStateException(message);
}
}

@Override
public void preCreated(TransferProcess process) {
stopIt(process);
}
}
2 changes: 2 additions & 0 deletions tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ dependencies {
testAnnotationProcessor(libs.lombok)
testCompileOnly(libs.lombok)

testImplementation(project(":extensions:database-direct-access"))
testImplementation(project(":extensions:test-backend-controller"))
testImplementation(project(":extensions:wrapper:clients:java-client"))
testImplementation(project(":utils:test-utils"))
testImplementation(project(":utils:jooq-database-access"))
testImplementation(libs.jsonUnit.assertj)
testImplementation(libs.mockito.core)
testImplementation(libs.assertj.core)
Expand Down
18 changes: 18 additions & 0 deletions tests/src/test/java/de/sovity/edc/e2e/ContractTerminationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import de.sovity.edc.client.gen.model.ContractTerminationRequest;
import de.sovity.edc.client.gen.model.InitiateTransferRequest;
import de.sovity.edc.client.gen.model.TransferHistoryEntry;
import de.sovity.edc.ext.db.jooq.Tables;
import de.sovity.edc.extension.contacttermination.ContractAgreementTerminationService;
import de.sovity.edc.extension.contacttermination.ContractTerminationEvent;
import de.sovity.edc.extension.contacttermination.ContractTerminationObserver;
import de.sovity.edc.extension.db.directaccess.DslContextFactory;
import de.sovity.edc.extension.e2e.extension.Consumer;
import de.sovity.edc.extension.e2e.extension.E2eScenario;
import de.sovity.edc.extension.e2e.extension.E2eTestExtension;
Expand Down Expand Up @@ -359,7 +361,9 @@ void doesntCrashWhenAgreementDoesntExist(
void cantTransferDataAfterTerminated(
E2eScenario scenario,
ClientAndServer mockServer,
@Consumer DslContextFactory consumerDsl,
@Consumer EdcClient consumerClient,
@Provider DslContextFactory providerDsl,
@Provider EdcClient providerClient
) {
val assetId = "asset-1";
Expand Down Expand Up @@ -410,6 +414,20 @@ void cantTransferDataAfterTerminated(
awaitTerminationCount(consumerClient, 1);
awaitTerminationCount(providerClient, 1);

val t = Tables.SOVITY_CONTRACT_TERMINATION;

val terminatedOnProviderSide = providerDsl.transactionResult((ptrx) ->
ptrx.selectCount()
.from(t)
.where(t.CONTRACT_AGREEMENT_ID.eq(contractAgreementId))
.execute());

assertThat(terminatedOnProviderSide).isEqualTo(1);
// pretend that the consumer didn't receive the termination message and let them try to get the data
consumerDsl.transactionResult((ctrx) -> ctrx.truncate(t).execute());
val terminatedOnConsumerSide = consumerDsl.transactionResult((ctrx) -> ctrx.fetchCount(t));
assertThat(terminatedOnConsumerSide).isEqualTo(0);

// act
consumerClient.uiApi().initiateTransfer(transferRequest);
// first transfer attempt
Expand Down

0 comments on commit 98fd9e3

Please sign in to comment.