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: explicitly set default ports in tests #1746

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class AssetApiControllerIntegrationTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.data.port", String.valueOf(port),
"web.http.data.path", "/api/v1/data",
"edc.api.auth.key", authKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import org.eclipse.dataspaceconnector.spi.event.asset.AssetDeleted;
import org.eclipse.dataspaceconnector.spi.types.domain.DataAddress;
import org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Map;
import java.util.concurrent.CountDownLatch;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.dataspaceconnector.junit.testfixtures.TestUtils.getFreePort;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
Expand All @@ -39,6 +42,14 @@ public class AssetEventDispatchTest {

private final EventSubscriber eventSubscriber = mock(EventSubscriber.class);

@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api"
));
}

@Test
void shouldDispatchEventsOnAssetCreationAndDeletion(AssetService service, EventRouter eventRouter) throws InterruptedException {
var createdLatch = onDispatchLatch(AssetCreated.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void setUp(EdcExtension extension) {

extension.registerSystemExtension(ServiceExtension.class, new TestExtension());
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.data.port", String.valueOf(port),
"web.http.data.path", "/api/v1/data",
"edc.api.auth.key", authKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class ContractAgreementApiControllerIntegrationTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.data.port", String.valueOf(port),
"web.http.data.path", "/api/v1/data",
"edc.api.auth.key", authKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class ContractDefinitionApiControllerIntegrationTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.data.port", String.valueOf(port),
"web.http.data.path", "/api/v1/data",
"edc.api.auth.key", authKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
import org.eclipse.dataspaceconnector.spi.event.contractdefinition.ContractDefinitionCreated;
import org.eclipse.dataspaceconnector.spi.event.contractdefinition.ContractDefinitionDeleted;
import org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractDefinition;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Map;
import java.util.UUID;

import static org.awaitility.Awaitility.await;
import static org.eclipse.dataspaceconnector.junit.testfixtures.TestUtils.getFreePort;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand All @@ -36,6 +39,14 @@ public class ContractDefinitionEventDispatchTest {

private final EventSubscriber eventSubscriber = mock(EventSubscriber.class);

@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api"
));
}

@Test
void shouldDispatchEventOnContractDefinitionCreationAndDeletion(ContractDefinitionService service, EventRouter eventRouter) {
eventRouter.register(eventSubscriber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class ContractNegotiationApiControllerIntegrationTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.data.port", String.valueOf(port),
"web.http.data.path", "/api/v1/data",
"edc.api.auth.key", authKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.concurrent.CompletableFuture;

import static org.awaitility.Awaitility.await;
import static org.eclipse.dataspaceconnector.junit.testfixtures.TestUtils.getFreePort;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
Expand All @@ -68,6 +69,8 @@ public class ContractNegotiationEventDispatchTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"edc.negotiation.consumer.send.retry.limit", "0",
"edc.negotiation.provider.send.retry.limit", "0"
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class PolicyDefinitionApiControllerIntegrationTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.data.port", String.valueOf(port),
"web.http.data.path", "/api/v1/data",
"edc.api.auth.key", authKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import org.eclipse.dataspaceconnector.spi.event.EventSubscriber;
import org.eclipse.dataspaceconnector.spi.event.policydefinition.PolicyDefinitionCreated;
import org.eclipse.dataspaceconnector.spi.event.policydefinition.PolicyDefinitionDeleted;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Map;
import java.util.concurrent.CountDownLatch;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.dataspaceconnector.junit.testfixtures.TestUtils.getFreePort;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
Expand All @@ -39,6 +42,14 @@ public class PolicyDefinitionEventDispatchTest {

private final EventSubscriber eventSubscriber = mock(EventSubscriber.class);

@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api"
));
}

@Test
void shouldDispatchEventOnPolicyDefinitionCreationAndDeletion(PolicyDefinitionService service, EventRouter eventRouter) throws InterruptedException {
var createdLatch = onDispatchLatch(PolicyDefinitionCreated.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class TransferProcessApiControllerIntegrationTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.data.port", String.valueOf(port),
"web.http.data.path", "/api/v1/data",
"edc.api.auth.key", authKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.concurrent.Executors;

import static org.awaitility.Awaitility.await;
import static org.eclipse.dataspaceconnector.junit.testfixtures.TestUtils.getFreePort;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
Expand All @@ -54,10 +55,12 @@ public class TransferProcessEventDispatchTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of("edc.transfer.send.retry.limit", "0",
"edc.transfer.send.retry.base-delay.ms", "0"));
"edc.transfer.send.retry.base-delay.ms", "0",
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api"));
extension.registerServiceMock(TransferWaitStrategy.class, () -> 1);
extension.registerServiceMock(EventExecutorServiceContainer.class,
new EventExecutorServiceContainer(Executors.newSingleThreadExecutor()));
new EventExecutorServiceContainer(Executors.newSingleThreadExecutor()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ void processProviderRequestRetry(TransferProcessManager processManager,
@BeforeEach
void setup(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.data.port", String.valueOf(dataPort),
"web.http.data.path", "/api/v1/data"
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class HttpProvisionerWebhookApiControllerIntegrationTest {
@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.provisioner.port", String.valueOf(port),
"web.http.provisioner.path", PROVISIONER_BASE_PATH,
"edc.api.auth.key", authKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ExceptionMappersIntegrationTest {
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.test.port", String.valueOf(port),
"web.http.test.path", "/"
));
Expand Down Expand Up @@ -115,6 +116,16 @@ void shouldReturn500ErrorOnJavaLangExceptions() {
.statusCode(500);
}

private static class RequestPayload {
@NotBlank
@JsonProperty
private String data;

@Positive
@JsonProperty
private long number;
}

@Path("/test")
public class TestController {

Expand All @@ -132,16 +143,6 @@ public void doAction(@Valid RequestPayload payload) {

}

private static class RequestPayload {
@NotBlank
@JsonProperty
private String data;

@Positive
@JsonProperty
private long number;
}

private class MyServiceExtension implements ServiceExtension {
@Inject
private WebService webService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
public class TestUtils {
public static final int MAX_TCP_PORT = 65_535;
public static final String GRADLE_WRAPPER;
private static File buildRoot = null;
private static final String GRADLE_WRAPPER_UNIX = "gradlew";
private static final String GRADLE_WRAPPER_WINDOWS = "gradlew.bat";
private static final Random RANDOM = new Random();
private static File buildRoot = null;

static {
GRADLE_WRAPPER = (System.getProperty("os.name").toLowerCase().contains("win")) ? GRADLE_WRAPPER_WINDOWS : GRADLE_WRAPPER_UNIX;
Expand Down Expand Up @@ -65,7 +66,7 @@ public static String getResourceFileContentAsString(String resourceName) {
* @throws IllegalArgumentException if no free port is available
*/
public static int getFreePort() {
var rnd = 1024 + new Random().nextInt(MAX_TCP_PORT - 1024);
var rnd = 1024 + RANDOM.nextInt(MAX_TCP_PORT - 1024);
return getFreePort(rnd);
}

Expand Down Expand Up @@ -152,7 +153,9 @@ public static OkHttpClient testOkHttpClient() {
*/
public static File findBuildRoot() {
// Use cached value if already existing.
if (buildRoot != null) return buildRoot;
if (buildRoot != null) {
return buildRoot;
}

File canonicalFile;
try {
Expand Down