Skip to content

Commit

Permalink
fix: DOS-1413 error while resume PULL transfer from provider
Browse files Browse the repository at this point in the history
tests improvement
  • Loading branch information
AndrYurk committed Nov 24, 2024
1 parent 64b0594 commit 4b19572
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset;
import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition;
import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition;
import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates;
import org.eclipse.edc.jsonld.TitaniumJsonLd;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.jsonld.util.JacksonJsonLd;
Expand Down Expand Up @@ -498,6 +499,10 @@ public String getContractNegotiationState(String id) {
return getContractNegotiationField(id, "state");
}

public void awaitTransferToBeInState(String transferProcessId, TransferProcessStates state) {
await().atMost(timeout).until(() -> getTransferProcessState(transferProcessId), it -> Objects.equals(it, state.name()));
}

protected String getContractNegotiationField(String negotiationId, String fieldName) {
return managementEndpoint.baseRequest()
.contentType(JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.IOException;
import java.io.StringWriter;
Expand All @@ -32,6 +31,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess.Type.CONSUMER;
import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.STARTED;
import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.TERMINATING;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -87,9 +87,8 @@ void verifyCopy() {
assertThat(process).usingRecursiveComparison().isEqualTo(copy);
}

@ParameterizedTest
@ValueSource(strings = { "STARTED", "SUSPENDED"})
void verifyConsumerTransitions(String state) {
@Test
void verifyConsumerTransitions() {
var process = TransferProcess.Builder.newInstance().id(UUID.randomUUID().toString()).type(CONSUMER).build();

process.transitionProvisioning(ResourceManifest.Builder.newInstance().build());
Expand All @@ -100,24 +99,31 @@ void verifyConsumerTransitions(String state) {

assertThrows(IllegalStateException.class, process::transitionStarting, "STARTING is not a valid state for consumer");
process.transitionStarted("dataPlaneId");
// should not set the data plane id
assertThat(process.getDataPlaneId()).isNull();

switch (state) {
case "STARTED":
process.transitionCompleting();
process.transitionCompleted();

process.transitionDeprovisioning();
process.transitionDeprovisioned();
break;
case "SUSPENDED":
process.transitionSuspending("suspension");
process.transitionSuspended();
break;
default:
throw new IllegalArgumentException("Unsupported state: " + state);
}
process.transitionSuspending("suspension");
process.transitionSuspended();

process.transitionStarted("dataPlaneId");

process.transitionCompleting();
process.transitionCompleted();

process.transitionDeprovisioning();
process.transitionDeprovisioned();
}

@ParameterizedTest
@EnumSource(value = TransferProcessStates.class, mode = INCLUDE, names = { "STARTING", "SUSPENDED" })
void shouldNotSetDataPlaneIdOnStart_whenTransferIsConsumer(TransferProcessStates fromState) {
var process = TransferProcess.Builder.newInstance()
.id(UUID.randomUUID().toString()).type(CONSUMER)
.state(fromState.code())
.build();

process.transitionStarted("dataPlaneId");

assertThat(process.stateAsString()).isEqualTo(STARTED.name());
assertThat(process.getDataPlaneId()).isNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@
import io.restassured.common.mapper.TypeRef;
import org.assertj.core.api.ThrowingConsumer;
import org.eclipse.edc.connector.controlplane.test.system.utils.Participant;
import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates;
import org.eclipse.edc.spi.types.domain.DataAddress;
import org.jetbrains.annotations.NotNull;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static io.restassured.RestAssured.given;
import static io.restassured.http.ContentType.JSON;
import static java.io.File.separator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.eclipse.edc.boot.BootServicesExtension.PARTICIPANT_ID;
import static org.eclipse.edc.sql.testfixtures.PostgresqlEndToEndInstance.defaultDatasourceConfiguration;
import static org.eclipse.edc.util.io.Ports.getFreePort;
Expand Down Expand Up @@ -175,10 +172,6 @@ public void pullData(DataAddress edr, Map<String, String> queryParams, ThrowingC
assertThat(data).satisfies(bodyAssertion);
}

protected void awaitTransferToBeInState(String transferProcessId, TransferProcessStates state) {
await().atMost(timeout).until(() -> getTransferProcessState(transferProcessId), it -> Objects.equals(it, state.name()));
}

@NotNull
private String resourceAbsolutePath(String filename) {
return System.getProperty("user.dir") + separator + "build" + separator + "resources" + separator + "test" + separator + filename;
Expand Down

0 comments on commit 4b19572

Please sign in to comment.