Skip to content

Commit

Permalink
Mimic reproducer from issue quarkusio#33024
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed May 17, 2023
1 parent 5a2347f commit 0634d9c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.example.grpc.exc;

import io.grpc.Status;
import com.google.protobuf.Any;
import com.google.rpc.ErrorInfo;
import com.google.rpc.Status;

import io.grpc.StatusException;
import io.grpc.StatusRuntimeException;
import io.grpc.protobuf.StatusProto;
import io.grpc.stub.StreamObserver;
import io.quarkus.grpc.GrpcService;

Expand All @@ -10,7 +15,23 @@ public class LegacyHelloGrpcService extends LegacyHelloGrpcGrpc.LegacyHelloGrpcI
@Override
public void legacySayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
// it NEEDS to be plain StatusException, and NOT StatusRuntimeException ?!
final StatusException t = new StatusException(Status.INVALID_ARGUMENT);
final StatusException t = new StatusException(io.grpc.Status.INVALID_ARGUMENT);
responseObserver.onError(t);
}

@Override
public void legacySayHelloRuntime(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
ErrorInfo errorInfo = ErrorInfo.newBuilder()
.setDomain("org.acme.test")
.setReason("stub-error")
.build();

final StatusRuntimeException t = StatusProto.toStatusRuntimeException(
Status.newBuilder()
.setCode(io.grpc.Status.INVALID_ARGUMENT.getCode().value())
.setMessage("this is a test error")
.addDetails(Any.pack(errorInfo))
.build());
responseObserver.onError(t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ service HelloGrpc {

service LegacyHelloGrpc {
rpc LegacySayHello (HelloRequest) returns (HelloReply) {}
rpc LegacySayHelloRuntime (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.quarkus.grpc.GrpcClient;
Expand All @@ -21,4 +23,15 @@ void legacySayHello() {
() -> stub.legacySayHello(HelloRequest.newBuilder().setName("Neo").build()));
assertEquals(Status.Code.INVALID_ARGUMENT, exception.getStatus().getCode());
}

@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
void legacySayHelloRuntime() {
final StatusRuntimeException exception = assertThrows(StatusRuntimeException.class,
() -> stub.legacySayHello(HelloRequest.newBuilder().setName("Neo").build()));
assertEquals(Status.Code.INVALID_ARGUMENT, exception.getStatus().getCode());
Metadata trailers = exception.getTrailers();
Assertions.assertNotNull(trailers);
System.out.println("trailers = " + trailers);
}
}

0 comments on commit 0634d9c

Please sign in to comment.