Skip to content

Commit

Permalink
CR carried out
Browse files Browse the repository at this point in the history
  • Loading branch information
zub4t committed Jun 26, 2024
1 parent 8426120 commit a97eb64
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSinkFactory;
import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSource;
import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSourceFactory;
import org.eclipse.edc.connector.dataplane.spi.pipeline.StreamFailure;
import org.eclipse.edc.connector.dataplane.spi.pipeline.StreamResult;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.types.domain.DataAddress;
Expand Down Expand Up @@ -135,9 +134,12 @@ void terminate_shouldFail_whenSourceClosureFails() throws Exception {

var future = service.transfer(dataFlow.toRequest()).thenApply(result -> service.terminate(dataFlow));

assertThat(future).succeedsWithin(5, TimeUnit.SECONDS).satisfies(result -> {
assertThat(result).isFailed().extracting(StreamFailure::getReason).isEqualTo(GENERAL_ERROR);
});
assertThat(future).succeedsWithin(5, TimeUnit.SECONDS)
.satisfies(result -> {
assertThat(result.failed()).isTrue();
assertThat(result.getFailure().getReason()).isEqualTo(GENERAL_ERROR);
assertThat(result.getFailure().getFailureDetail()).startsWith(GENERAL_ERROR.toString());
});
}

@Test
Expand All @@ -146,7 +148,12 @@ void terminate_shouldFail_whenTransferDoesNotExist() {

var result = service.terminate(dataFlow);

assertThat(result).isFailed().extracting(StreamFailure::getReason).isEqualTo(NOT_FOUND);
assertThat(result)
.satisfies(r -> {
assertThat(r.failed()).isTrue();
assertThat(r.getFailure().getReason()).isEqualTo(NOT_FOUND);
assertThat(r.getFailure().getFailureDetail()).startsWith(NOT_FOUND.toString());
});
verifyNoInteractions(source);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static java.lang.String.format;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.connector.dataplane.spi.pipeline.StreamFailure.Reason.GENERAL_ERROR;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -92,9 +93,12 @@ void transfer_whenFailureDuringTransfer_fails() {
fakeSink.transferResultSupplier = () -> StreamResult.error(errorMessage);

assertThat(fakeSink.transfer(dataSource)).succeedsWithin(500, TimeUnit.MILLISECONDS)
.satisfies(transferResult -> assertThat(transferResult.failed()).isTrue())
.satisfies(transferResult -> assertThat(transferResult.getFailure().getReason()).isEqualTo(StreamFailure.Reason.GENERAL_ERROR))
.satisfies(transferResult -> assertThat(transferResult.getFailureMessages()).containsExactly(errorMessage));
.satisfies(transferResult -> {
assertThat(transferResult.failed()).isTrue();
assertThat(transferResult.getFailure().getReason()).isEqualTo(GENERAL_ERROR);
assertThat(transferResult.getFailure().getFailureDetail()).startsWith(GENERAL_ERROR.toString());
assertThat(transferResult.getFailureMessages()).containsExactly(errorMessage);
});

assertThat(fakeSink.parts).containsExactly(dataSource);
assertThat(fakeSink.complete).isEqualTo(0);
Expand All @@ -107,10 +111,13 @@ void transfer_whenExceptionDuringTransfer_fails() {
};

assertThat(fakeSink.transfer(dataSource)).succeedsWithin(500, TimeUnit.MILLISECONDS)
.satisfies(transferResult -> assertThat(transferResult.failed()).isTrue())
.satisfies(transferResult -> assertThat(transferResult.getFailure().getReason()).isEqualTo(StreamFailure.Reason.GENERAL_ERROR))
.satisfies(transferResult -> assertThat(transferResult.getFailureMessages())
.containsExactly("Unhandled exception raised when transferring data: java.lang.RuntimeException: " + errorMessage));
.satisfies(transferResult -> {
assertThat(transferResult.failed()).isTrue();
assertThat(transferResult.getFailure().getReason()).isEqualTo(GENERAL_ERROR);
assertThat(transferResult.getFailure().getFailureDetail()).startsWith(GENERAL_ERROR.toString());
assertThat(transferResult.getFailureMessages())
.containsExactly("Unhandled exception raised when transferring data: java.lang.RuntimeException: " + errorMessage);
});

assertThat(fakeSink.parts).containsExactly(dataSource);
assertThat(fakeSink.complete).isEqualTo(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 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
Expand All @@ -9,7 +9,6 @@
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
* zub4t - Improving failure detail message
*
*/

Expand All @@ -33,11 +32,7 @@ public StreamFailure(List<String> messages, Reason reason) {
@Override
public String getFailureDetail() {
var str = super.getFailureDetail();
if (str != null && !str.isEmpty()) {
str = reason + ": " + str;
return str;
}
return String.valueOf(reason);
return (str != null && !str.isEmpty()) ? (reason + ": " + str) : (reason + "");
}

public Reason getReason() {
Expand Down

0 comments on commit a97eb64

Please sign in to comment.