-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 #28053.
- Loading branch information
1 parent
9bc683f
commit 2a09a03
Showing
3 changed files
with
180 additions
and
32 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...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,64 @@ | ||
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.*; | ||
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); | ||
} | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
.../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,52 @@ | ||
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.*; | ||
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 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