Skip to content

Commit

Permalink
pr remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Dec 19, 2023
1 parent fb8e0eb commit f69827e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,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 @@ -22,7 +22,6 @@
import org.eclipse.edc.connector.contract.spi.event.contractnegotiation.ContractNegotiationInitiated;
import org.eclipse.edc.connector.contract.spi.event.contractnegotiation.ContractNegotiationRequested;
import org.eclipse.edc.connector.contract.spi.event.contractnegotiation.ContractNegotiationVerified;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessCompleted;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessInitiated;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessProvisioned;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessRequested;
Expand Down Expand Up @@ -78,8 +77,7 @@ void negotiateEdr_shouldInvokeCallbacks() throws IOException {
createEvent(TransferProcessInitiated.class),
createEvent(TransferProcessProvisioned.class),
createEvent(TransferProcessRequested.class),
createEvent(TransferProcessStarted.class),
createEvent(TransferProcessCompleted.class));
createEvent(TransferProcessStarted.class));

var assetId = "api-asset-1";
var url = server.url("/mock/api");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.assertj.core.api.Condition;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessCompleted;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessStarted;
import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.tractusx.edc.lifecycle.Participant;
Expand Down Expand Up @@ -72,8 +72,8 @@ void setup() {
void negotiateEdr_shouldRenewTheEdr() throws IOException {

var expectedEvents = List.of(
createEvent(TransferProcessCompleted.class),
createEvent(TransferProcessCompleted.class));
createEvent(TransferProcessStarted.class),
createEvent(TransferProcessStarted.class));

var assetId = UUID.randomUUID().toString();
var url = server.url("/mock/api");
Expand All @@ -95,7 +95,7 @@ void negotiateEdr_shouldRenewTheEdr() throws IOException {
PLATO.createContractDefinition(assetId, "def-1", "policy-1", "policy-2");

var callbacks = Json.createArrayBuilder()
.add(createCallback(url.toString(), true, Set.of("transfer.process.completed")))
.add(createCallback(url.toString(), true, Set.of("transfer.process.started")))
.build();

expectedEvents.forEach(event -> server.enqueue(new MockResponse()));
Expand Down Expand Up @@ -134,7 +134,7 @@ void negotiateEdr_shouldRenewTheEdr() throws IOException {
.atMost(ASYNC_TIMEOUT)
.untilAsserted(() -> {
var tpState = SOKRATES.getTransferProcessState(transferProcessId);
assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.COMPLETED.toString());
assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.TERMINATED.toString());
});

await().pollInterval(fibonacci())
Expand All @@ -148,7 +148,7 @@ void negotiateEdr_shouldRenewTheEdr() throws IOException {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessCompleted;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessStarted;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.edc.spi.event.EventEnvelope;
import org.eclipse.tractusx.edc.lifecycle.Participant;
Expand All @@ -32,11 +32,15 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.Duration;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static java.time.Duration.ofSeconds;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.awaitility.pollinterval.FibonacciPollInterval.fibonacci;
import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE;
import static org.eclipse.tractusx.edc.helpers.EdrNegotiationHelperFunctions.createCallback;
import static org.eclipse.tractusx.edc.helpers.PolicyHelperFunctions.businessPartnerGroupPolicy;
Expand All @@ -58,6 +62,8 @@ public abstract class AbstractDataPlaneProxyTest {

private static final String CUSTOM_QUERY_PARAMS = "foo=bar";

private static final Duration ASYNC_TIMEOUT = ofSeconds(45);

private static final String CUSTOM_FULL_PATH = CUSTOM_BASE_PATH + CUSTOM_SUB_PATH + "?" + CUSTOM_QUERY_PARAMS;
private final ObjectMapper mapper = new ObjectMapper();
private MockWebServer server;
Expand Down Expand Up @@ -86,7 +92,7 @@ void httpPullDataTransfer_withEdrAndProxy() {
PLATO.createContractDefinition(assetId, "def-1", "policy-1", "policy-2");

var callbacks = Json.createArrayBuilder()
.add(createCallback(eventsUrl.toString(), true, Set.of("transfer.process.completed")))
.add(createCallback(eventsUrl.toString(), true, Set.of("transfer.process.started")))
.build();

// response to callback
Expand Down Expand Up @@ -159,7 +165,7 @@ void httpPullDataTransfer_shouldFailForAsset_withTwoEdrAndProxy() throws IOExcep
PLATO.createContractDefinition(assetId, "def-1", "policy-1", "policy-2");

var callbacks = Json.createArrayBuilder()
.add(createCallback(eventsUrl.toString(), true, Set.of("transfer.process.completed")))
.add(createCallback(eventsUrl.toString(), true, Set.of("transfer.process.started")))
.build();

// response to callback
Expand All @@ -174,9 +180,14 @@ void httpPullDataTransfer_shouldFailForAsset_withTwoEdrAndProxy() throws IOExcep

var body = "{\"response\": \"ok\"}";

server.enqueue(new MockResponse().setBody(body));
SOKRATES.pullProxyDataResponseByAssetId(PLATO, assetId).then()
.assertThat().statusCode(428);
await().pollInterval(fibonacci())
.atMost(ASYNC_TIMEOUT)
.untilAsserted(() -> {
server.enqueue(new MockResponse().setBody(body));
SOKRATES.pullProxyDataResponseByAssetId(PLATO, assetId).then()
.assertThat().statusCode(428);
});


server.enqueue(new MockResponse().setBody(body));
var data = SOKRATES.pullProxyDataByTransferProcessId(PLATO, transferEvent1.getPayload().getTransferProcessId());
Expand Down Expand Up @@ -210,7 +221,7 @@ void httpPullDataTransfer_withEdrAndProviderDataPlaneProxy() throws IOException
PLATO.createContractDefinition(assetId, "def-1", "policy-1", "policy-2");

var callbacks = Json.createArrayBuilder()
.add(createCallback(eventsUrl.toString(), true, Set.of("transfer.process.completed")))
.add(createCallback(eventsUrl.toString(), true, Set.of("transfer.process.started")))
.build();

// response to callback
Expand Down Expand Up @@ -272,7 +283,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) throws In
PLATO.createContractDefinition(assetId, "def-1", "policy-1", "policy-2");

var callbacks = Json.createArrayBuilder()
.add(createCallback(eventsUrl.toString(), true, Set.of("transfer.process.completed")))
.add(createCallback(eventsUrl.toString(), true, Set.of("transfer.process.started")))
.build();

SOKRATES.negotiateEdr(PLATO, assetId, callbacks);
Expand All @@ -295,7 +306,7 @@ void teardown() throws IOException {
server.shutdown();
}

private EventEnvelope<TransferProcessCompleted> waitForTransferCompletion() {
private EventEnvelope<TransferProcessStarted> waitForTransferCompletion() {
try {
var request = server.takeRequest(60, TimeUnit.SECONDS);
if (request != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void transferData_privateBackend() throws IOException, InterruptedException {
.atMost(ASYNC_TIMEOUT)
.untilAsserted(() -> {
var tpState = SOKRATES.getTransferProcessState(transferProcessId.get());
assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.COMPLETED.toString());
assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.STARTED.toString());
});

// wait until EDC is available on the consumer side
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@

org.eclipse.tractusx.edc.lifecycle.ConsumerServicesExtension
org.eclipse.tractusx.edc.lifecycle.VaultSeedExtension
org.eclipse.tractusx.edc.lifecycle.TestServiceExtension

0 comments on commit f69827e

Please sign in to comment.