Skip to content

Commit

Permalink
Test gRPC usage of Vert.x event loops
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Apr 5, 2023
1 parent 398e845 commit 79339f6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ public Uni<HelloReply> sayHello(HelloRequest request) {
return Uni.createFrom().item("Hello " + name)
.map(res -> HelloReply.newBuilder().setMessage(res).build());
}

@Override
public Uni<HelloReply> threadName(HelloRequest request) {
return Uni.createFrom().item(Thread.currentThread().getName())
.map(res -> HelloReply.newBuilder().setMessage(res).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ package helloworld;
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
rpc ThreadName (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
quarkus.grpc.server.port=9001
quarkus.grpc.server.instances=2

%vertx.quarkus.grpc.server.use-separate-server=false
%n2o.quarkus.grpc.server.use-separate-server=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.util.HashSet;
import java.util.Set;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -14,7 +17,10 @@
import examples.MutinyGreeterGrpc;
import io.grpc.Channel;
import io.quarkus.grpc.test.utils.GRPCTestUtils;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
import io.vertx.core.impl.Deployment;
import io.vertx.core.impl.VertxInternal;

abstract class HelloWorldNewServiceTestBase {

Expand Down Expand Up @@ -42,6 +48,33 @@ public void cleanup() {
close(_vertx);
}

@Test
public void testEventLoop() {
// for old Vert.x this is null, but we know we have 2 verticles
if (_vertx != null) {
VertxInternal internal = (VertxInternal) _vertx;
Set<String> deploymentIDs = internal.deploymentIDs();
// should be just one, but in the worst case skip the test if not
Assumptions.assumeTrue(deploymentIDs.size() == 1);
Deployment deployment = internal.getDeployment(deploymentIDs.iterator().next());
Set<Verticle> verticles = deployment.getVerticles();
Assumptions.assumeTrue(verticles.size() > 1);
}

Set<String> threadNames = new HashSet<>();
for (int i = 0; i < 10; i++) {
Channel newChannel = GRPCTestUtils.channel(_vertx, port());
try {
GreeterGrpc.GreeterBlockingStub client = GreeterGrpc.newBlockingStub(newChannel);
HelloReply reply = client.threadName(HelloRequest.newBuilder().build());
threadNames.add(reply.getMessage());
} finally {
GRPCTestUtils.close(newChannel);
}
}
assertThat(threadNames.size()).isGreaterThan(1);
}

@Test
public void testHelloWorldServiceUsingBlockingStub() {
GreeterGrpc.GreeterBlockingStub client = GreeterGrpc.newBlockingStub(channel);
Expand Down

0 comments on commit 79339f6

Please sign in to comment.