Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Interrupt the transfer process earlier for terminated contracts #1074

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 for terminated contracts ([PR#1074](https://github.com/sovity/edc-ce/pull/1074))

### Deployment Migration Notes

Expand Down
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org),
version 1.4, available at http://contributor-covenant.org/version/1/4.
This Code of Conduct is adapted from the [Contributor Covenant](http://www.contributor-covenant.org),
version 1.4, available at http://www.contributor-covenant.org/version/1/4.
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
Loading