forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catch exception happening in the gRPC interceptors and close the call…
… immediately. Fix quarkusio#28053. (cherry picked from commit 747f6ee)
- Loading branch information
1 parent
6e1d849
commit 1f2ac33
Showing
3 changed files
with
194 additions
and
28 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...eployment/src/test/java/io/quarkus/grpc/server/interceptors/FailingInInterceptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.quarkus.grpc.server.interceptors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.time.Duration; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.grpc.ForwardingServerCall; | ||
import io.grpc.Metadata; | ||
import io.grpc.ServerCall; | ||
import io.grpc.ServerCallHandler; | ||
import io.grpc.ServerInterceptor; | ||
import io.grpc.Status; | ||
import io.grpc.StatusRuntimeException; | ||
import io.grpc.examples.helloworld.*; | ||
import io.quarkus.grpc.GlobalInterceptor; | ||
import io.quarkus.grpc.GrpcClient; | ||
import io.quarkus.grpc.server.services.HelloService; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class FailingInInterceptorTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addPackage(GreeterGrpc.class.getPackage()) | ||
.addClasses(MyFailingInterceptor.class, GreeterBean.class, HelloRequest.class, HelloService.class)); | ||
|
||
@GrpcClient | ||
Greeter greeter; | ||
|
||
@Test | ||
void test() { | ||
Uni<HelloReply> result = greeter.sayHello(HelloRequest.newBuilder().setName("ServiceA").build()); | ||
assertThatThrownBy(() -> result.await().atMost(Duration.ofSeconds(4))) | ||
.isInstanceOf(StatusRuntimeException.class) | ||
.hasMessageContaining("UNKNOWN"); | ||
} | ||
|
||
@ApplicationScoped | ||
@GlobalInterceptor | ||
public static class MyFailingInterceptor implements ServerInterceptor { | ||
|
||
@Override | ||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, | ||
ServerCallHandler<ReqT, RespT> next) { | ||
return next | ||
.startCall(new ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) { | ||
|
||
@Override | ||
public void sendMessage(RespT message) { | ||
throw new IllegalArgumentException("BOOM"); | ||
} | ||
|
||
@Override | ||
public void close(Status status, Metadata trailers) { | ||
super.close(status, trailers); | ||
} | ||
}, headers); | ||
} | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
.../deployment/src/test/java/io/quarkus/grpc/server/interceptors/FailingInterceptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.quarkus.grpc.server.interceptors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.time.Duration; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.grpc.Metadata; | ||
import io.grpc.ServerCall; | ||
import io.grpc.ServerCallHandler; | ||
import io.grpc.ServerInterceptor; | ||
import io.grpc.StatusRuntimeException; | ||
import io.grpc.examples.helloworld.Greeter; | ||
import io.grpc.examples.helloworld.GreeterBean; | ||
import io.grpc.examples.helloworld.GreeterGrpc; | ||
import io.grpc.examples.helloworld.HelloReply; | ||
import io.grpc.examples.helloworld.HelloRequest; | ||
import io.quarkus.grpc.GlobalInterceptor; | ||
import io.quarkus.grpc.GrpcClient; | ||
import io.quarkus.grpc.server.services.HelloService; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class FailingInterceptorTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addPackage(GreeterGrpc.class.getPackage()) | ||
.addClasses(MyFailingInterceptor.class, GreeterBean.class, HelloRequest.class, HelloService.class)); | ||
|
||
@GrpcClient | ||
Greeter greeter; | ||
|
||
@Test | ||
void test() { | ||
Uni<HelloReply> result = greeter.sayHello(HelloRequest.newBuilder().setName("ServiceA").build()); | ||
assertThatThrownBy(() -> result.await().atMost(Duration.ofSeconds(4))) | ||
.isInstanceOf(StatusRuntimeException.class) | ||
.hasMessageContaining("UNKNOWN"); | ||
} | ||
|
||
@ApplicationScoped | ||
@GlobalInterceptor | ||
public static class MyFailingInterceptor implements ServerInterceptor { | ||
|
||
@Override | ||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, | ||
ServerCallHandler<ReqT, RespT> next) { | ||
throw new IllegalArgumentException("BOOM!"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters