Skip to content

Commit

Permalink
build: speed up e2e transfer tests (eclipse-edc#3443)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored and ndkrimbacher committed Oct 4, 2023
1 parent 5ce067a commit e0249ad
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ public EdcHttpClientImpl(OkHttpClient okHttpClient, RetryPolicy<Response> retryP

@Override
public Response execute(Request request) throws IOException {
return execute(request, emptyList());
}

@Override
public Response execute(Request request, List<FallbackFactory> fallbacks) throws IOException {
var call = okHttpClient.newCall(request);
return with(retryPolicy).compose(call).execute();
var builder = with(retryPolicy);
fallbacks.stream().map(it -> it.create(request)).forEach(builder::compose);
return builder.compose(call).execute();
}

@Override
Expand All @@ -59,11 +66,7 @@ public <T> Result<T> execute(Request request, Function<Response, Result<T>> mapp

@Override
public <T> Result<T> execute(Request request, List<FallbackFactory> fallbacks, Function<Response, Result<T>> mappingFunction) {
var call = okHttpClient.newCall(request);
var builder = with(retryPolicy);
fallbacks.stream().map(it -> it.create(request)).forEach(builder::compose);

try (var response = builder.compose(call).execute()) {
try (var response = execute(request, fallbacks)) {
return mappingFunction.apply(response);
} catch (Throwable e) {
monitor.severe("HTTP client exception caught for request " + request, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.edc.junit.extensions;

import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

/**
* Utility class that permits to run multiple EDC runtimes statically
*/
public class EdcClassRuntimesExtension implements BeforeAllCallback, AfterAllCallback {

public final EdcRuntimeExtension[] extensions;

public EdcClassRuntimesExtension(EdcRuntimeExtension... extensions) {
this.extensions = extensions;
}

@Override
public void beforeAll(ExtensionContext extensionContext) {
for (var extension : this.extensions) {
try {
extension.beforeTestExecution(extensionContext);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

@Override
public void afterAll(ExtensionContext extensionContext) throws Exception {
for (var extension : this.extensions) {
extension.afterTestExecution(extensionContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;

import static org.eclipse.edc.spi.http.FallbackFactories.retryWhenStatusIsNot;

/**
* Implementation of {@link TransferProcessApiClient} which talks to the Control Plane Transfer Process via HTTP APIs
Expand Down Expand Up @@ -61,7 +64,7 @@ private void sendRequest(DataFlowRequest dataFlowRequest, String action, Object
if (dataFlowRequest.getCallbackAddress() != null) {
try {
var request = createRequest(buildUrl(dataFlowRequest, action), body);
try (var response = httpClient.execute(request)) {
try (var response = httpClient.execute(request, List.of(retryWhenStatusIsNot(200)))) {
if (!response.isSuccessful()) {
monitor.severe(String.format("Failed to send callback request: received %s from the TransferProcess API", response.code()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ void setUp(EdcExtension extension) {
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.control.port", String.valueOf(port),
"web.http.control.path", "/control"
"web.http.control.path", "/control",
"edc.core.retry.retries.max", "0"
));

extension.registerSystemExtension(ServiceExtension.class, new TransferServiceMockExtension(service));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public interface EdcHttpClient {
*/
Response execute(Request request) throws IOException;

/**
* Executes the specified request synchronously.
* Accepts a list of {@link FallbackFactories} that could apply retry in particular occasions.
*
* @param request the {@link Request}.
* @param fallbacks a list of fallbacks to be applied.
* @return a {@link Response}, must be closed explicitly after consumption
* @throws IOException on connection error.
*/
Response execute(Request request, List<FallbackFactory> fallbacks) throws IOException;

/**
* Executes the specified request synchronously applying the mapping function to the response.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.edc.test.e2e;

import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.extensions.EdcClassRuntimesExtension;
import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -24,53 +25,44 @@
class EndToEndTransferInMemoryTest extends AbstractEndToEndTransfer {

@RegisterExtension
static EdcRuntimeExtension consumerControlPlane = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:control-plane",
"consumer-control-plane",
CONSUMER.controlPlaneConfiguration()
static EdcClassRuntimesExtension runtimes = new EdcClassRuntimesExtension(
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:control-plane",
"consumer-control-plane",
CONSUMER.controlPlaneConfiguration()
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:data-plane",
"consumer-data-plane",
CONSUMER.dataPlaneConfiguration()
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:backend-service",
"consumer-backend-service",
new HashMap<>() {
{
put("web.http.port", String.valueOf(CONSUMER.backendService().getPort()));
}
}
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:data-plane",
"provider-data-plane",
PROVIDER.dataPlaneConfiguration()
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:control-plane",
"provider-control-plane",
PROVIDER.controlPlaneConfiguration()
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:backend-service",
"provider-backend-service",
new HashMap<>() {
{
put("web.http.port", String.valueOf(PROVIDER.backendService().getPort()));
}
}
)
);

@RegisterExtension
static EdcRuntimeExtension consumerDataPlane = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:data-plane",
"consumer-data-plane",
CONSUMER.dataPlaneConfiguration()
);

@RegisterExtension
static EdcRuntimeExtension consumerBackendService = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:backend-service",
"consumer-backend-service",
new HashMap<>() {
{
put("web.http.port", String.valueOf(CONSUMER.backendService().getPort()));
}
}
);

@RegisterExtension
static EdcRuntimeExtension providerDataPlane = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:data-plane",
"provider-data-plane",
PROVIDER.dataPlaneConfiguration()
);

@RegisterExtension
static EdcRuntimeExtension providerControlPlane = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:control-plane",
"provider-control-plane",
PROVIDER.controlPlaneConfiguration()
);

@RegisterExtension
static EdcRuntimeExtension providerBackendService = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:backend-service",
"provider-backend-service",
new HashMap<>() {
{
put("web.http.port", String.valueOf(PROVIDER.backendService().getPort()));
}
}
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.edc.test.e2e;

import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest;
import org.eclipse.edc.junit.extensions.EdcClassRuntimesExtension;
import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -29,53 +30,45 @@
class EndToEndTransferPostgresqlTest extends AbstractEndToEndTransfer {

@RegisterExtension
static EdcRuntimeExtension consumerControlPlane = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:control-plane-postgresql",
"consumer-control-plane",
CONSUMER.controlPlanePostgresConfiguration()
);

@RegisterExtension
static EdcRuntimeExtension consumerDataPlane = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:data-plane",
"consumer-data-plane",
CONSUMER.dataPlaneConfiguration()
);

@RegisterExtension
static EdcRuntimeExtension consumerBackendService = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:backend-service",
"consumer-backend-service",
new HashMap<>() {
{
put("web.http.port", String.valueOf(CONSUMER.backendService().getPort()));
}
}
);

@RegisterExtension
static EdcRuntimeExtension providerDataPlane = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:data-plane",
"provider-data-plane",
PROVIDER.dataPlaneConfiguration()
);

@RegisterExtension
static EdcRuntimeExtension providerControlPlane = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:control-plane-postgresql",
"provider-control-plane",
PROVIDER.controlPlanePostgresConfiguration()
);

@RegisterExtension
static EdcRuntimeExtension providerBackendService = new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:backend-service",
"provider-backend-service",
new HashMap<>() {
{
put("web.http.port", String.valueOf(PROVIDER.backendService().getPort()));
}
}
static EdcClassRuntimesExtension runtimes = new EdcClassRuntimesExtension(
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:control-plane-postgresql",
"consumer-control-plane",
CONSUMER.controlPlanePostgresConfiguration()
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:data-plane",
"consumer-data-plane",
CONSUMER.dataPlaneConfiguration()
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:backend-service",
"consumer-backend-service",
new HashMap<>() {
{
put("web.http.port", String.valueOf(CONSUMER.backendService().getPort()));
}
}
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:data-plane",
"provider-data-plane",
PROVIDER.dataPlaneConfiguration()
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:control-plane-postgresql",
"provider-control-plane",
PROVIDER.controlPlanePostgresConfiguration()
),
new EdcRuntimeExtension(
":system-tests:e2e-transfer-test:backend-service",
"provider-backend-service",
new HashMap<>() {
{
put("web.http.port", String.valueOf(PROVIDER.backendService().getPort()));
}
}
)
);

@BeforeAll
Expand Down

0 comments on commit e0249ad

Please sign in to comment.