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.
quarkus grpc - multiple server instances
fixes quarkusio#10057
- Loading branch information
1 parent
12bcdca
commit f348d1e
Showing
12 changed files
with
291 additions
and
148 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
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
32 changes: 32 additions & 0 deletions
32
...pc/deployment/src/test/java/io/quarkus/grpc/server/scaling/MultipleGrpcVerticlesTest.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,32 @@ | ||
package io.quarkus.grpc.server.scaling; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
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.examples.helloworld.GreeterGrpc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MultipleGrpcVerticlesTest extends ScalingTestBase { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addPackage(GreeterGrpc.class.getPackage()) | ||
.addClass(ThreadReturningGreeterService.class)) | ||
.withConfigurationResource("multiple-instances-config.properties"); | ||
|
||
@Test | ||
public void shouldUseMultipleThreads() throws InterruptedException, TimeoutException, ExecutionException { | ||
Set<String> threads = getThreadsUsedFor100Requests(); | ||
|
||
assertThat(threads).hasSizeGreaterThan(1); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/scaling/ScalingTestBase.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,45 @@ | ||
package io.quarkus.grpc.server.scaling; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import io.grpc.Channel; | ||
import io.grpc.ManagedChannelBuilder; | ||
import io.grpc.examples.helloworld.GreeterGrpc; | ||
import io.grpc.examples.helloworld.HelloReply; | ||
import io.grpc.examples.helloworld.HelloRequest; | ||
|
||
public class ScalingTestBase { | ||
|
||
Set<String> getThreadsUsedFor100Requests() throws InterruptedException, ExecutionException, TimeoutException { | ||
int requestNo = 100; | ||
List<Callable<String>> calls = new ArrayList<>(); | ||
for (int i = 0; i < requestNo; i++) { | ||
calls.add(() -> { | ||
Channel channel = ManagedChannelBuilder.forAddress("localhost", 9000) | ||
.usePlaintext() | ||
.build(); | ||
HelloReply reply = GreeterGrpc.newBlockingStub(channel) | ||
.sayHello(HelloRequest.newBuilder().setName("foo").build()); | ||
return reply.getMessage(); | ||
}); | ||
} | ||
List<Future<String>> results = Executors.newFixedThreadPool(requestNo) | ||
.invokeAll(calls); | ||
|
||
Set<String> threads = new HashSet<>(); | ||
for (Future<String> result : results) { | ||
threads.add(result.get(10, TimeUnit.SECONDS)); | ||
} | ||
return threads; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
.../grpc/deployment/src/test/java/io/quarkus/grpc/server/scaling/SingleGrpcVerticleTest.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,32 @@ | ||
package io.quarkus.grpc.server.scaling; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
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.examples.helloworld.GreeterGrpc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class SingleGrpcVerticleTest extends ScalingTestBase { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addPackage(GreeterGrpc.class.getPackage()) | ||
.addClass(ThreadReturningGreeterService.class)) | ||
.withConfigurationResource("single-instance-config.properties"); | ||
|
||
@Test | ||
public void shouldUseMultipleThreads() throws InterruptedException, TimeoutException, ExecutionException { | ||
Set<String> threads = getThreadsUsedFor100Requests(); | ||
|
||
assertThat(threads).hasSize(1); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...eployment/src/test/java/io/quarkus/grpc/server/scaling/ThreadReturningGreeterService.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,19 @@ | ||
package io.quarkus.grpc.server.scaling; | ||
|
||
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.stub.StreamObserver; | ||
|
||
@Singleton | ||
public class ThreadReturningGreeterService extends GreeterGrpc.GreeterImplBase { | ||
|
||
@Override | ||
public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) { | ||
String threadName = Thread.currentThread().getName(); | ||
responseObserver.onNext(HelloReply.newBuilder().setMessage(threadName).build()); | ||
responseObserver.onCompleted(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
extensions/grpc/deployment/src/test/resources/multiple-instances-config.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,3 @@ | ||
quarkus.grpc.server.instances=3 | ||
quarkus.grpc.clients.hello-service.host=localhost | ||
quarkus.grpc.clients.hello-service.keep-alive-timeout=1s |
3 changes: 3 additions & 0 deletions
3
extensions/grpc/deployment/src/test/resources/single-instance-config.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,3 @@ | ||
quarkus.grpc.server.instances=1 | ||
quarkus.grpc.clients.hello-service.host=localhost | ||
quarkus.grpc.clients.hello-service.keep-alive-timeout=1s |
9 changes: 0 additions & 9 deletions
9
extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerHolder.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.