diff --git a/core/edr-cache-core/src/main/java/org/eclipse/tractusx/edc/edr/core/defaults/InMemoryEndpointDataReferenceCache.java b/core/edr-cache-core/src/main/java/org/eclipse/tractusx/edc/edr/core/defaults/InMemoryEndpointDataReferenceCache.java index f9ea70d6a..59072ff71 100644 --- a/core/edr-cache-core/src/main/java/org/eclipse/tractusx/edc/edr/core/defaults/InMemoryEndpointDataReferenceCache.java +++ b/core/edr-cache-core/src/main/java/org/eclipse/tractusx/edc/edr/core/defaults/InMemoryEndpointDataReferenceCache.java @@ -54,6 +54,7 @@ public class InMemoryEndpointDataReferenceCache implements EndpointDataReference private final LockManager lockManager; private final EdrCacheEntryPredicateConverter predicateConverter = new EdrCacheEntryPredicateConverter(); + private final Map> entriesByAssetId; private final Map entriesByEdrId; @@ -174,7 +175,7 @@ public StoreResult deleteByTransferProcessId(String } - public @NotNull List leaseAndGet(int max, Criterion... criteria) { + private @NotNull List leaseAndGet(int max, Criterion... criteria) { return lockManager.writeLock(() -> { var filterPredicate = Arrays.stream(criteria).map(predicateConverter::convert).reduce(x -> true, Predicate::and); var entities = entriesByEdrId.values().stream() diff --git a/core/edr-core/src/main/java/org/eclipse/tractusx/edc/edr/core/manager/EdrManagerImpl.java b/core/edr-core/src/main/java/org/eclipse/tractusx/edc/edr/core/manager/EdrManagerImpl.java index 911006a69..363021271 100644 --- a/core/edr-core/src/main/java/org/eclipse/tractusx/edc/edr/core/manager/EdrManagerImpl.java +++ b/core/edr-core/src/main/java/org/eclipse/tractusx/edc/edr/core/manager/EdrManagerImpl.java @@ -23,6 +23,7 @@ import org.eclipse.edc.connector.transfer.spi.types.TransferRequest; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.query.Criterion; +import org.eclipse.edc.spi.query.QuerySpec; import org.eclipse.edc.spi.response.ResponseStatus; import org.eclipse.edc.spi.response.StatusResult; import org.eclipse.edc.spi.retry.ExponentialWaitStrategy; @@ -60,6 +61,7 @@ import static org.eclipse.tractusx.edc.edr.core.EdrCoreExtension.DEFAULT_ITERATION_WAIT; import static org.eclipse.tractusx.edc.edr.core.EdrCoreExtension.DEFAULT_SEND_RETRY_BASE_DELAY; import static org.eclipse.tractusx.edc.edr.core.EdrCoreExtension.DEFAULT_SEND_RETRY_LIMIT; +import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.DELETING; import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.EXPIRED; import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.NEGOTIATED; import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.from; @@ -110,6 +112,7 @@ public void start() { stateMachineManager = StateMachineManager.Builder.newInstance("edr-manager", monitor, executorInstrumentation, waitStrategy) .processor(processEdrInState(NEGOTIATED, this::processNegotiated)) .processor(processEdrInState(EXPIRED, this::processExpired)) + .processor(processDeletingEdr(this::processDeleting)) .build(); stateMachineManager.start(); @@ -136,17 +139,17 @@ protected void transitionToExpired(EndpointDataReferenceEntry edrEntry) { update(edrEntry); } - protected void transitionToDeleted(EndpointDataReferenceEntry edrEntry) { - edrEntry.transitionToDeleted(); - update(edrEntry); - } - protected void transitionToError(EndpointDataReferenceEntry edrEntry, String message) { edrEntry.setErrorDetail(message); edrEntry.transitionError(); update(edrEntry); } + protected void transitionToDeleting(EndpointDataReferenceEntry edrEntry) { + edrEntry.transitionToDeleting(); + update(edrEntry); + } + private void update(EndpointDataReferenceEntry edrEntry) { edrCache.update(edrEntry); monitor.debug(format("Edr entry %s is now in state %s.", edrEntry.getId(), from(edrEntry.getState()))); @@ -158,6 +161,16 @@ private StateProcessorImpl processEdrInState(Endpoin return new StateProcessorImpl<>(() -> edrCache.nextNotLeased(batchSize, filter), telemetry.contextPropagationMiddleware(function)); } + + private StateProcessorImpl processDeletingEdr(Function function) { + var query = QuerySpec.Builder.newInstance() + .filter(hasState(DELETING.code())) + .limit(batchSize) + .build(); + + return new StateProcessorImpl<>(() -> edrCache.queryForEntries(query).collect(Collectors.toList()), telemetry.contextPropagationMiddleware(function)); + } + private ContractRequest createContractRequest(NegotiateEdrRequest request) { var callbacks = Stream.concat(request.getCallbackAddresses().stream(), Stream.of(LOCAL_CALLBACK)).collect(Collectors.toList()); @@ -189,23 +202,35 @@ private boolean processNegotiated(EndpointDataReferenceEntry edrEntry) { } private boolean processExpired(EndpointDataReferenceEntry edrEntry) { - if (shouldBeRemoved(edrEntry)) { - return entityRetryProcessFactory.doSyncProcess(edrEntry, () -> deleteEntry(edrEntry)) - .onDelay(this::breakLease) - .onSuccess((n, result) -> { - }) - .onFailure((n, throwable) -> transitionToExpired(n)) - .onFatalError((n, failure) -> transitionToError(n, failure.getFailureDetail())) - .onRetryExhausted((n, failure) -> transitionToError(n, format("Failed delete EDR token: %s", failure.getFailureDetail()))) - .execute("Start an EDR token deletion"); + return entityRetryProcessFactory.doSimpleProcess(edrEntry, () -> checkExpiration(edrEntry)) + .onDelay(this::breakLease) + .execute("Start EDR token deletion check"); + + } + + + private boolean processDeleting(EndpointDataReferenceEntry edrEntry) { + return entityRetryProcessFactory.doSyncProcess(edrEntry, () -> deleteEntry(edrEntry)) + .onDelay(this::breakLease) + .onSuccess((n, result) -> { + }) + .onFailure((n, throwable) -> transitionToDeleting(n)) + .onFatalError((n, failure) -> transitionToError(n, failure.getFailureDetail())) + .onRetryExhausted((n, failure) -> transitionToError(n, format("Failed deleted EDR token: %s", failure.getFailureDetail()))) + .execute("Start EDR token deletion"); + } + + private boolean checkExpiration(EndpointDataReferenceEntry entry) { + if (shouldBeRemoved(entry)) { + transitionToDeleting(entry); + return true; } else { - breakLease(edrEntry); + breakLease(entry); return false; } } private StatusResult deleteEntry(EndpointDataReferenceEntry entry) { - this.transitionToDeleted(entry); var result = edrCache.deleteByTransferProcessId(entry.getTransferProcessId()); if (result.succeeded()) { monitor.debug(format("Deleted EDR cached entry for transfer process id %s", entry.getTransferProcessId())); diff --git a/edc-extensions/edr/edr-cache-sql/src/main/java/org/eclipse/tractusx/edc/edr/store/sql/SqlEndpointDataReferenceCache.java b/edc-extensions/edr/edr-cache-sql/src/main/java/org/eclipse/tractusx/edc/edr/store/sql/SqlEndpointDataReferenceCache.java index b100da429..9a90ee294 100644 --- a/edc-extensions/edr/edr-cache-sql/src/main/java/org/eclipse/tractusx/edc/edr/store/sql/SqlEndpointDataReferenceCache.java +++ b/edc-extensions/edr/edr-cache-sql/src/main/java/org/eclipse/tractusx/edc/edr/store/sql/SqlEndpointDataReferenceCache.java @@ -58,6 +58,8 @@ public class SqlEndpointDataReferenceCache extends AbstractSqlStore implements E private final SqlLeaseContextBuilder leaseContext; + private final String leaseHolder; + public SqlEndpointDataReferenceCache(DataSourceRegistry dataSourceRegistry, String dataSourceName, TransactionContext transactionContext, EdrStatements statements, @@ -67,6 +69,7 @@ public SqlEndpointDataReferenceCache(DataSourceRegistry dataSourceRegistry, Stri this.statements = statements; this.clock = clock; this.vault = vault; + this.leaseHolder = connectorId; leaseContext = SqlLeaseContextBuilder.with(transactionContext, connectorId, statements, clock, queryExecutor); } diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/DataWiper.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/DataWiper.java index 060e75975..afc32db4a 100644 --- a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/DataWiper.java +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/DataWiper.java @@ -61,8 +61,6 @@ public void clearEdrCache() { var edrCache = context.getService(EndpointDataReferenceCache.class); edrCache.queryForEntries(QuerySpec.max()).forEach(entry -> { try { - entry.transitionToDeleted(); - edrCache.update(entry); edrCache.deleteByTransferProcessId(entry.getTransferProcessId()); } catch (Exception e) { context.getMonitor().warning("Failed to clean up the cache", e); diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/AbstractDeleteEdrTest.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/AbstractDeleteEdrTest.java new file mode 100644 index 000000000..21ab2dac6 --- /dev/null +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/AbstractDeleteEdrTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.tractusx.edc.tests.edr; + +import jakarta.json.Json; +import okhttp3.mockwebserver.MockWebServer; +import org.assertj.core.api.Condition; +import org.eclipse.tractusx.edc.lifecycle.Participant; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.time.Duration; +import java.util.ArrayList; +import java.util.UUID; + +import static java.time.Duration.ofSeconds; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; +import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.EXPIRED; +import static org.eclipse.tractusx.edc.helpers.PolicyHelperFunctions.businessPartnerNumberPolicy; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.PLATO_NAME; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.SOKRATES_NAME; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.platoConfiguration; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.sokratesConfiguration; + +public abstract class AbstractDeleteEdrTest { + + protected static final Participant SOKRATES = new Participant(SOKRATES_NAME, SOKRATES_BPN, sokratesConfiguration()); + protected static final Participant PLATO = new Participant(PLATO_NAME, PLATO_BPN, platoConfiguration()); + private static final Duration ASYNC_TIMEOUT = ofSeconds(45); + MockWebServer server; + + @BeforeEach + void setup() { + server = new MockWebServer(); + } + + @Test + @DisplayName("Verify that expired EDR are deleted") + void negotiateEdr_shouldRemoveExpiredEdrs() throws IOException { + + var assetId = UUID.randomUUID().toString(); + + var authCodeHeaderName = "test-authkey"; + var authCode = "test-authcode"; + PLATO.createAsset(assetId, Json.createObjectBuilder().build(), Json.createObjectBuilder() + .add(EDC_NAMESPACE + "type", "HttpData") + .add(EDC_NAMESPACE + "contentType", "application/json") + .add(EDC_NAMESPACE + "baseUrl", "http://test:8080") + .add(EDC_NAMESPACE + "authKey", authCodeHeaderName) + .add(EDC_NAMESPACE + "authCode", authCode) + .build()); + + PLATO.createPolicy(businessPartnerNumberPolicy("policy-1", SOKRATES.getBpn())); + PLATO.createPolicy(businessPartnerNumberPolicy("policy-2", SOKRATES.getBpn())); + PLATO.createContractDefinition(assetId, "def-1", "policy-1", "policy-2"); + + var callbacks = Json.createArrayBuilder() + .build(); + + SOKRATES.negotiateEdr(PLATO, assetId, callbacks); + + var expired = new ArrayList(); + + await().atMost(ASYNC_TIMEOUT) + .untilAsserted(() -> { + var edrCaches = SOKRATES.getEdrEntriesByAssetId(assetId); + var localExpired = edrCaches.stream() + .filter(json -> json.asJsonObject().getJsonString("tx:edrState").getString().equals(EXPIRED.name())) + .map(json -> json.asJsonObject().getJsonString("edc:transferProcessId").getString()) + .toList(); + assertThat(localExpired).hasSizeGreaterThan(0); + expired.add(localExpired.get(0)); + }); + + await().atMost(ASYNC_TIMEOUT) + .untilAsserted(() -> expired.forEach((id) -> SOKRATES.getEdrRequest(id).statusCode(404))); + + } + + @AfterEach + void teardown() throws IOException { + server.shutdown(); + } + + + private Condition stateCondition(String value, String description) { + return new Condition<>(m -> m.equals(value), description); + } + +} diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/AbstractRenewalEdrTest.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/AbstractRenewalEdrTest.java index be972740c..21f89b894 100644 --- a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/AbstractRenewalEdrTest.java +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/AbstractRenewalEdrTest.java @@ -27,12 +27,13 @@ import org.junit.jupiter.api.Test; import java.io.IOException; -import java.util.ArrayList; +import java.time.Duration; import java.util.List; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; +import static java.time.Duration.ofSeconds; import static org.assertj.core.api.Assertions.anyOf; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -55,7 +56,7 @@ public abstract class AbstractRenewalEdrTest { protected static final Participant SOKRATES = new Participant(SOKRATES_NAME, SOKRATES_BPN, sokratesConfiguration()); protected static final Participant PLATO = new Participant(PLATO_NAME, PLATO_BPN, platoConfiguration()); - + private static final Duration ASYNC_TIMEOUT = ofSeconds(45); MockWebServer server; @BeforeEach @@ -105,11 +106,12 @@ void negotiateEdr_shouldRenewTheEdr() throws IOException { JsonArrayBuilder edrCaches = Json.createArrayBuilder(); - await().untilAsserted(() -> { - var localEdrCaches = SOKRATES.getEdrEntriesByAssetId(assetId); - assertThat(localEdrCaches).hasSizeGreaterThan(1); - localEdrCaches.forEach(edrCaches::add); - }); + await().atMost(ASYNC_TIMEOUT) + .untilAsserted(() -> { + var localEdrCaches = SOKRATES.getEdrEntriesByAssetId(assetId); + assertThat(localEdrCaches).hasSizeGreaterThan(1); + localEdrCaches.forEach(edrCaches::add); + }); assertThat(edrCaches.build()) @@ -118,62 +120,6 @@ void negotiateEdr_shouldRenewTheEdr() throws IOException { .areAtLeast(1, stateCondition(EXPIRED.name(), "Expired")); } - @Test - @DisplayName("Verify that expired EDR are deleted") - void negotiateEdr_shouldRemoveExpiredEdrs() throws IOException { - - var expectedEvents = List.of( - createEvent(TransferProcessCompleted.class), - createEvent(TransferProcessCompleted.class)); - - var assetId = UUID.randomUUID().toString(); - var url = server.url("/mock/api"); - server.start(); - - var authCodeHeaderName = "test-authkey"; - var authCode = "test-authcode"; - PLATO.createAsset(assetId, Json.createObjectBuilder().build(), Json.createObjectBuilder() - .add(EDC_NAMESPACE + "type", "HttpData") - .add(EDC_NAMESPACE + "contentType", "application/json") - .add(EDC_NAMESPACE + "baseUrl", url.toString()) - .add(EDC_NAMESPACE + "authKey", authCodeHeaderName) - .add(EDC_NAMESPACE + "authCode", authCode) - .build()); - - PLATO.createPolicy(businessPartnerNumberPolicy("policy-1", SOKRATES.getBpn())); - PLATO.createPolicy(businessPartnerNumberPolicy("policy-2", SOKRATES.getBpn())); - PLATO.createContractDefinition(assetId, "def-1", "policy-1", "policy-2"); - - var callbacks = Json.createArrayBuilder() - .add(createCallback(url.toString(), true, Set.of("transfer.process.completed"))) - .build(); - - expectedEvents.forEach(event -> server.enqueue(new MockResponse())); - - SOKRATES.negotiateEdr(PLATO, assetId, callbacks); - - var events = expectedEvents.stream() - .map(receivedEvent -> waitForEvent(server, receivedEvent)) - .collect(Collectors.toList()); - - assertThat(expectedEvents).usingRecursiveFieldByFieldElementComparator().containsAll(events); - - - var expired = new ArrayList(); - - await().untilAsserted(() -> { - var edrCaches = SOKRATES.getEdrEntriesByAssetId(assetId); - var localExpired = edrCaches.stream() - .filter(json -> json.asJsonObject().getJsonString("tx:edrState").getString().equals(EXPIRED.name())) - .map(json -> json.asJsonObject().getJsonString("edc:transferProcessId").getString()) - .toList(); - assertThat(localExpired).hasSizeGreaterThan(0); - expired.addAll(localExpired); - }); - - await().untilAsserted(() -> expired.forEach((id) -> SOKRATES.getEdrRequest(id).statusCode(404))); - - } @AfterEach void teardown() throws IOException { @@ -184,5 +130,5 @@ void teardown() throws IOException { private Condition stateCondition(String value, String description) { return new Condition<>(m -> m.equals(value), description); } - + } diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/DeleteEdrInMemoryTest.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/DeleteEdrInMemoryTest.java new file mode 100644 index 000000000..2ca557532 --- /dev/null +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/DeleteEdrInMemoryTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.tractusx.edc.tests.edr; + + +import org.eclipse.edc.junit.annotations.EndToEndTest; +import org.eclipse.tractusx.edc.lifecycle.ParticipantRuntime; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.PLATO_NAME; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.SOKRATES_NAME; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.platoConfiguration; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.sokratesConfiguration; +import static org.eclipse.tractusx.edc.tests.edr.TestFunctions.renewalConfiguration; + +@EndToEndTest +public class DeleteEdrInMemoryTest extends AbstractDeleteEdrTest { + + @RegisterExtension + protected static final ParticipantRuntime SOKRATES_RUNTIME = new ParticipantRuntime( + ":edc-tests:runtime:runtime-memory", + SOKRATES_NAME, + SOKRATES_BPN, + renewalConfiguration(sokratesConfiguration(), "5") + ); + + @RegisterExtension + protected static final ParticipantRuntime PLATO_RUNTIME = new ParticipantRuntime( + ":edc-tests:runtime:runtime-memory", + PLATO_NAME, + PLATO_BPN, + renewalConfiguration(platoConfiguration()) + ); +} diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/DeleteEdrPostgresqlTest.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/DeleteEdrPostgresqlTest.java new file mode 100644 index 000000000..c1b3f96b9 --- /dev/null +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/DeleteEdrPostgresqlTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.tractusx.edc.tests.edr; + +import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.tractusx.edc.lifecycle.PgParticipantRuntime; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.PLATO_NAME; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.SOKRATES_NAME; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.platoConfiguration; +import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.sokratesConfiguration; +import static org.eclipse.tractusx.edc.tests.edr.TestFunctions.renewalConfiguration; + +@PostgresqlDbIntegrationTest +public class DeleteEdrPostgresqlTest extends AbstractDeleteEdrTest { + + @RegisterExtension + protected static final PgParticipantRuntime SOKRATES_RUNTIME = new PgParticipantRuntime( + ":edc-tests:runtime:runtime-postgresql", + SOKRATES_NAME, + SOKRATES_BPN, + renewalConfiguration(sokratesConfiguration(), "5") + ); + @RegisterExtension + protected static final PgParticipantRuntime PLATO_RUNTIME = new PgParticipantRuntime( + ":edc-tests:runtime:runtime-postgresql", + PLATO_NAME, + PLATO_BPN, + renewalConfiguration(platoConfiguration()) + ); + +} diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/TestFunctions.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/TestFunctions.java index 9c6148144..e123c61f1 100644 --- a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/TestFunctions.java +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/edr/TestFunctions.java @@ -28,11 +28,15 @@ public class TestFunctions { private static final ObjectMapper MAPPER = new ObjectMapper(); public static Map renewalConfiguration(Map config) { + return renewalConfiguration(config, "10"); + } + + public static Map renewalConfiguration(Map config, String retention) { var ssiConfiguration = new HashMap() { { - put("edc.edr.state-machine.expiring-duration", "4"); - put("edc.edr.state-machine.expired-retention", "1"); - put("edc.transfer.proxy.token.validity.seconds", "4"); + put("edc.edr.state-machine.expiring-duration", "10"); + put("edc.edr.state-machine.expired-retention", retention); + put("edc.transfer.proxy.token.validity.seconds", "15"); } }; ssiConfiguration.putAll(config); diff --git a/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/store/EndpointDataReferenceCache.java b/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/store/EndpointDataReferenceCache.java index 0ae806743..67eec1096 100644 --- a/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/store/EndpointDataReferenceCache.java +++ b/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/store/EndpointDataReferenceCache.java @@ -83,4 +83,5 @@ default boolean filterActive(EndpointDataReferenceEntry entry) { */ StoreResult deleteByTransferProcessId(String id); + } diff --git a/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/types/EndpointDataReferenceEntry.java b/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/types/EndpointDataReferenceEntry.java index 3857e3a71..339971fc4 100644 --- a/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/types/EndpointDataReferenceEntry.java +++ b/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/types/EndpointDataReferenceEntry.java @@ -29,7 +29,7 @@ import static java.util.Objects.requireNonNull; import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.TX_NAMESPACE; -import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.DELETED; +import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.DELETING; import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.ERROR; import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.EXPIRED; import static org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntryStates.NEGOTIATED; @@ -138,11 +138,10 @@ public void transitionToExpired() { transition(EXPIRED, EXPIRED, NEGOTIATED, REFRESHING); } - public void transitionToDeleted() { - transition(DELETED, DELETED, EXPIRED, REFRESHING, NEGOTIATED); + public void transitionToDeleting() { + transition(DELETING, DELETING, EXPIRED); } - private void transition(EndpointDataReferenceEntryStates end, Predicate canTransitTo) { if (!canTransitTo.test(EndpointDataReferenceEntryStates.from(state))) { throw new IllegalStateException(format("Cannot transition from state %s to %s", EndpointDataReferenceEntryStates.from(state), EndpointDataReferenceEntryStates.from(end.code()))); diff --git a/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/types/EndpointDataReferenceEntryStates.java b/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/types/EndpointDataReferenceEntryStates.java index 3ccb822fe..5abf02697 100644 --- a/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/types/EndpointDataReferenceEntryStates.java +++ b/spi/edr-spi/src/main/java/org/eclipse/tractusx/edc/edr/spi/types/EndpointDataReferenceEntryStates.java @@ -28,11 +28,10 @@ public enum EndpointDataReferenceEntryStates { REFRESHING(100), EXPIRED(200), - ERROR(300), - - DELETED(400); + ERROR(300), + DELETING(400); private final int code; EndpointDataReferenceEntryStates(int code) { diff --git a/spi/edr-spi/src/testFixtures/java/org/eclipse/tractusx/edc/edr/spi/EndpointDataReferenceCacheTestBase.java b/spi/edr-spi/src/testFixtures/java/org/eclipse/tractusx/edc/edr/spi/EndpointDataReferenceCacheTestBase.java index 07e489efa..963ddbd45 100644 --- a/spi/edr-spi/src/testFixtures/java/org/eclipse/tractusx/edc/edr/spi/EndpointDataReferenceCacheTestBase.java +++ b/spi/edr-spi/src/testFixtures/java/org/eclipse/tractusx/edc/edr/spi/EndpointDataReferenceCacheTestBase.java @@ -369,7 +369,7 @@ void delete_isLeasedByOther_shouldThrowException() { assertThatThrownBy(() -> getStore().deleteByTransferProcessId(entry.getTransferProcessId())).isInstanceOf(IllegalStateException.class); } - + protected abstract EndpointDataReferenceCache getStore(); protected abstract void lockEntity(String negotiationId, String owner, Duration duration);