-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 #15260 from michalszynkiewicz/unblock-grpc
gRPC blocking: fix calling grpc client within blocking service
- Loading branch information
Showing
5 changed files
with
139 additions
and
9 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...pc/deployment/src/test/java/io/quarkus/grpc/server/ClientCallFromBlockingServiceTest.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,44 @@ | ||
package io.quarkus.grpc.server; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Timeout; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.grpc.examples.helloworld.GreeterGrpc; | ||
import io.grpc.examples.helloworld3.Greeter3Grpc; | ||
import io.grpc.examples.helloworld3.HelloReply3; | ||
import io.grpc.examples.helloworld3.HelloRequest3; | ||
import io.quarkus.grpc.runtime.annotations.GrpcService; | ||
import io.quarkus.grpc.server.services.GrpcCallWithinBlockingService; | ||
import io.quarkus.grpc.server.services.HelloService; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ClientCallFromBlockingServiceTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addPackage(Greeter3Grpc.class.getPackage()) | ||
.addPackage(GreeterGrpc.class.getPackage()) | ||
.addClass(HelloService.class) | ||
.addClass(GrpcCallWithinBlockingService.class)) | ||
.withConfigurationResource("call-from-blocking-service.properties"); | ||
|
||
@Inject | ||
@GrpcService("service3") | ||
Greeter3Grpc.Greeter3BlockingStub greeter3Client; | ||
|
||
@Test | ||
@Timeout(5) | ||
void shouldWorkMultipleTimes() { | ||
for (int i = 0; i < 20; i++) { | ||
HelloReply3 reply = greeter3Client.sayHello(HelloRequest3.newBuilder().setName("Slim").build()); | ||
assertThat(reply.getMessage()).isEqualTo("response:Hello Slim"); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ployment/src/test/java/io/quarkus/grpc/server/services/GrpcCallWithinBlockingService.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,30 @@ | ||
package io.quarkus.grpc.server.services; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import io.grpc.examples.helloworld.GreeterGrpc; | ||
import io.grpc.examples.helloworld.HelloReply; | ||
import io.grpc.examples.helloworld.HelloRequest; | ||
import io.grpc.examples.helloworld3.Greeter3Grpc; | ||
import io.grpc.examples.helloworld3.HelloReply3; | ||
import io.grpc.examples.helloworld3.HelloRequest3; | ||
import io.grpc.stub.StreamObserver; | ||
import io.quarkus.grpc.runtime.annotations.GrpcService; | ||
import io.smallrye.common.annotation.Blocking; | ||
|
||
@Singleton | ||
public class GrpcCallWithinBlockingService extends Greeter3Grpc.Greeter3ImplBase { | ||
|
||
@Inject | ||
@GrpcService("greeter") | ||
GreeterGrpc.GreeterBlockingStub greeter; | ||
|
||
@Override | ||
@Blocking | ||
public void sayHello(HelloRequest3 request, StreamObserver<HelloReply3> responseObserver) { | ||
HelloReply reply = greeter.sayHello(HelloRequest.newBuilder().setName(request.getName()).build()); | ||
responseObserver.onNext(HelloReply3.newBuilder().setMessage("response:" + reply.getMessage()).build()); | ||
responseObserver.onCompleted(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
extensions/grpc/deployment/src/test/proto/helloworld3.proto
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,24 @@ | ||
syntax = "proto3"; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "io.grpc.examples.helloworld3"; | ||
option java_outer_classname = "HelloWorldProto3"; | ||
option objc_class_prefix = "HLW"; | ||
|
||
package helloworld; | ||
|
||
// The greeting service definition. | ||
service Greeter3 { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest3) returns (HelloReply3) {} | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest3 { | ||
string name = 1; | ||
} | ||
|
||
// The response message containing the greetings | ||
message HelloReply3 { | ||
string message = 1; | ||
} |
2 changes: 2 additions & 0 deletions
2
extensions/grpc/deployment/src/test/resources/call-from-blocking-service.properties
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,2 @@ | ||
quarkus.grpc.clients.greeter.host=localhost | ||
quarkus.grpc.clients.service3.host=localhost |
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