-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1541 from michalvavrik/backports/3.2.9-second
[3.2] Backport gRPC interceptor test coverage and tagging tests with JIRAs
- Loading branch information
Showing
11 changed files
with
179 additions
and
4 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/GrpcClientInterceptors.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,55 @@ | ||
package io.quarkus.ts.http.advanced; | ||
|
||
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
|
||
import io.grpc.CallOptions; | ||
import io.grpc.Channel; | ||
import io.grpc.ClientCall; | ||
import io.grpc.ClientInterceptor; | ||
import io.grpc.ForwardingClientCall; | ||
import io.grpc.Metadata; | ||
import io.grpc.MethodDescriptor; | ||
import io.quarkus.grpc.GlobalInterceptor; | ||
|
||
class GrpcClientInterceptors { | ||
public static Metadata.Key<String> CLIENT_METHOD = Metadata.Key.of("client-method-target", ASCII_STRING_MARSHALLER); | ||
public static Metadata.Key<String> CLIENT_CLASS = Metadata.Key.of("client-class-target", ASCII_STRING_MARSHALLER); | ||
|
||
@GlobalInterceptor | ||
@ApplicationScoped | ||
static class ClassTarget extends Base { | ||
} | ||
|
||
static class MethodTarget extends Base { | ||
} | ||
|
||
static class Producer { | ||
@GlobalInterceptor | ||
@Produces | ||
MethodTarget methodTarget() { | ||
return new MethodTarget(); | ||
} | ||
} | ||
|
||
abstract static class Base implements ClientInterceptor { | ||
@Override | ||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions options, | ||
Channel next) { | ||
String interceptedTarget = getClass().getName(); | ||
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, options)) { | ||
@Override | ||
public void start(Listener<RespT> responseListener, Metadata headers) { | ||
if (interceptedTarget.contains("MethodTarget")) { | ||
headers.put(CLIENT_METHOD, interceptedTarget); | ||
} else if (interceptedTarget.contains("ClassTarget")) { | ||
headers.put(CLIENT_CLASS, interceptedTarget); | ||
} | ||
super.start(responseListener, headers); | ||
} | ||
}; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/GrpcInterceptorsService.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,23 @@ | ||
package io.quarkus.ts.http.advanced; | ||
|
||
import io.grpc.stub.StreamObserver; | ||
import io.quarkus.example.HelloReply; | ||
import io.quarkus.example.InterceptedMessageGrpc; | ||
import io.quarkus.example.InterceptedRequest; | ||
import io.quarkus.grpc.GrpcService; | ||
|
||
@GrpcService | ||
public class GrpcInterceptorsService extends InterceptedMessageGrpc.InterceptedMessageImplBase { | ||
|
||
@Override | ||
public void showInterceptedMessage(InterceptedRequest request, StreamObserver<HelloReply> responseObserver) { | ||
String serverMethod = GrpcServerInterceptors.SERVER_METHOD.get(); | ||
String serverClass = GrpcServerInterceptors.SERVER_CLASS.get(); | ||
HelloReply reply = HelloReply.newBuilder() | ||
.setMessage("Intercepted client side method passed by server method interceptor is: " + serverMethod | ||
+ "\nIntercepted client side class passed by server class interceptor is: " + serverClass) | ||
.build(); | ||
responseObserver.onNext(reply); | ||
responseObserver.onCompleted(); | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/GrpcServerInterceptors.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,57 @@ | ||
package io.quarkus.ts.http.advanced; | ||
|
||
import static io.quarkus.ts.http.advanced.GrpcClientInterceptors.CLIENT_CLASS; | ||
import static io.quarkus.ts.http.advanced.GrpcClientInterceptors.CLIENT_METHOD; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
|
||
import io.grpc.Context; | ||
import io.grpc.Contexts; | ||
import io.grpc.Metadata; | ||
import io.grpc.ServerCall; | ||
import io.grpc.ServerCallHandler; | ||
import io.grpc.ServerInterceptor; | ||
import io.quarkus.grpc.GlobalInterceptor; | ||
|
||
class GrpcServerInterceptors { | ||
|
||
public static Context.Key<String> SERVER_METHOD = Context.key("server-method-target"); | ||
public static Context.Key<String> SERVER_CLASS = Context.key("server-class-target"); | ||
|
||
@GlobalInterceptor | ||
@ApplicationScoped | ||
static class ClassTarget extends Base { | ||
} | ||
|
||
static class MethodTarget extends Base { | ||
} | ||
|
||
static class Producer { | ||
@GlobalInterceptor | ||
@Produces | ||
MethodTarget methodTarget() { | ||
return new MethodTarget(); | ||
} | ||
} | ||
|
||
abstract static class Base implements ServerInterceptor { | ||
@Override | ||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata metadata, | ||
ServerCallHandler<ReqT, RespT> next) { | ||
Context ctx = null; | ||
String interceptedTarget = getClass().getName(); | ||
// Determine where was grpc call intercepted and put client side intercepted data to Context. | ||
if (interceptedTarget.contains("MethodTarget")) { | ||
ctx = Context.current().withValue(SERVER_METHOD, metadata.get(CLIENT_METHOD)); | ||
ctx.attach(); | ||
} else if (interceptedTarget.contains("ClassTarget")) { | ||
ctx = Context.current().withValue(SERVER_CLASS, metadata.get(CLIENT_CLASS)); | ||
ctx.attach(); | ||
} else { | ||
throw new RuntimeException("Unexpected intercepted class or method by GlobalInterceptor."); | ||
} | ||
return Contexts.interceptCall(ctx, call, metadata, next); | ||
} | ||
} | ||
} |
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
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
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
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
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
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