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

Change InvokeMethod() to return UMessage #74

Merged
merged 1 commit into from
Jan 28, 2024

Conversation

stevenhartley
Copy link

#73

@stevenhartley stevenhartley merged commit a83fc2a into main Jan 28, 2024
2 checks passed
* @param responseFuture CompletionStage<UPayload> response from uTransport.
* @param expectedClazz The class name of the declared expected return type of the RPC method.
* @return Returns a CompletionStage containing the declared expected return type of the RPC method or an exception.
* @param <T> The declared expected return type of the RPC method.
*/
static <T extends Message> CompletionStage<T> mapResponse(CompletionStage<UPayload> responseFuture, Class<T> expectedClazz) {
return responseFuture.handle((payload, exception) -> {
static <T extends Message> CompletionStage<T> mapResponse(CompletionStage<UMessage> responseFuture, Class<T> expectedClazz) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that we are not returning a UPayload, I think it would be better to rename expectedClazz to expectedPayloadClazz
I know it is Class and T represents the Message that is the payload, but I still think this can add a lot of clarity.
code is read more than it is written

static <T extends Message> CompletionStage<T> mapResponse(CompletionStage<UPayload> responseFuture, Class<T> expectedClazz) {
return responseFuture.handle((payload, exception) -> {
static <T extends Message> CompletionStage<T> mapResponse(CompletionStage<UMessage> responseFuture, Class<T> expectedClazz) {
return responseFuture.handle((message, exception) -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call it uMessage so as not to be confused with Message of protobuf since the class type is not in the code

// Unexpected exception
if (exception != null) {
throw new CompletionException(exception.getMessage(), exception);
}
if (payload == null) {
if (message == null || !message.hasPayload()) {
throw new RuntimeException("Server returned a null payload. Expected " + expectedClazz.getName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the case where the payload only contains default values - like a UStatus that contains OK, there were times that the payload serialized to empy - there were times I got an empty string.
Are there tests to check this exception.
In addition, the exception could be clearer - UMessage payload is empty, expected payload of type expectedClazz.getName()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants