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

Bugfix: Correct handling of communication status in InMemoryRpcClient #163

Merged
merged 1 commit into from
Jul 24, 2024
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 @@ -137,7 +137,7 @@ private void handleResponses(UMessage response) {
}

// Check if the response has a commstatus and if it is not OK then complete the future with an exception
if (responseAttributes.hasCommstatus()) {
if (responseAttributes.hasCommstatus() && responseAttributes.getCommstatus() != UCode.OK) {
final UCode code = responseAttributes.getCommstatus();
responseFuture.completeExceptionally(
new UStatusException(code, "Communication error [" + code + "]"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Optional;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -194,6 +195,22 @@ public UMessage buildResponse(UMessage request) {
assertTrue(response.toCompletableFuture().isCompletedExceptionally());
}

@Test
@DisplayName("Test calling invokeMethod when we set comm status to UCode.OK")
public void testInvokeMethodWithCommStatusUCodeOKTransport() {
RpcClient rpcClient = new InMemoryRpcClient(new CommStatusOkTransport());
UPayload payload = UPayload.packToAny(UUri.newBuilder().build());
CompletionStage<UPayload> response = rpcClient.invokeMethod(createMethodUri(), payload, null);
assertFalse(response.toCompletableFuture().isCompletedExceptionally());
assertDoesNotThrow(() -> {
Optional<UStatus> unpackedStatus = UPayload.unpack(response.toCompletableFuture().get(), UStatus.class);
assertTrue(unpackedStatus.isPresent());
assertEquals(UCode.OK, unpackedStatus.get().getCode());
assertEquals("No Communication Error", unpackedStatus.get().getMessage());
});
}



private UUri createMethodUri() {
return UUri.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ public UMessage buildResponse(UMessage request) {
}
};

/**
* Test UTransport that will set the commstatus for a success response
*/
class CommStatusOkTransport extends TestUTransport {
@Override
public UMessage buildResponse(UMessage request) {
UStatus status = UStatus.newBuilder()
.setCode(UCode.OK)
.setMessage("No Communication Error")
.build();
return UMessageBuilder.response(request.getAttributes())
.withCommStatus(status.getCode())
.build(UPayload.pack(status));
}
}

class EchoUTransport extends TestUTransport {
@Override
Expand Down
Loading