Skip to content

Commit

Permalink
FISH-5881: improving execution of concurrent grpc example
Browse files Browse the repository at this point in the history
  • Loading branch information
breakponchito committed Jan 25, 2022
1 parent f9d9699 commit f7e6772
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 21 deletions.
23 changes: 11 additions & 12 deletions grpc/grpc-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,43 @@
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>3.1.4</version>
<scope>runtime</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
<version>3.1.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
<version>${grpc.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>grpc</artifactId>
<version>${payara.grpc.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc.version}</version>
<scope>runtime</scope>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>${protobuf.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>

Expand Down
17 changes: 12 additions & 5 deletions grpc/grpc-web/src/test/java/fish/payara/example/grpc/TestGrpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,23 @@ public static WebArchive deployWar() {
WebArchive war = ShrinkWrap.create(WebArchive.class).addPackage(FeatureRepository.class.getPackage())
.addAsWebInfResource("glassfish-web.xml").addAsLibraries(singleDependencies)
.addAsResource(TestGrpc.class.getResource("route_guide_db.json"), "fish/payara/example/grpc/route_guide_db.json");
System.out.println(war.toString(true));
return war;
}

@Test
@RunAsClient
public void testGrpc() throws InterruptedException {
executeRouteGuideClient(null);
Assert.assertTrue(true);
}

public static void executeRouteGuideClient(String clientId) throws InterruptedException {
String target = "localhost:8080";
String clientPrefix = "[] ";
String clientIdPrefix = "[] ";

if(clientId != null) {
clientIdPrefix = clientId;
}

List<Feature> features;
try {
Expand All @@ -72,7 +80,7 @@ public void testGrpc() throws InterruptedException {
ManagedChannel channel = ManagedChannelBuilder.forTarget(target).usePlaintext().build();

try {
RouteGuideClient client = new RouteGuideClient(channel, clientPrefix);
RouteGuideClient client = new RouteGuideClient(channel, clientIdPrefix);
// Looking for a valid feature
client.getFeature(409146138, -746188906);

Expand All @@ -89,13 +97,12 @@ public void testGrpc() throws InterruptedException {
CountDownLatch finishLatch = client.routeChat();

if (!finishLatch.await(1, TimeUnit.MINUTES)) {
LogHelper.warning(clientPrefix + "routeChat can not finish within 1 minutes");
LogHelper.warning(clientIdPrefix + "routeChat can not finish within 1 minutes");
}

} finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
Assert.assertTrue(true);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
package fish.payara.example.grpc;

import java.util.Random;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@RunWith(Arquillian.class)
public class TestGrpcConcurrent {

@Deployment
public static WebArchive deployWar() {
return TestGrpc.deployWar();
}

@Test
@RunAsClient
public void testConcurrentGrpc() throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(5);
for(int i = 0; i < 5; i++) {
String client = String.format("[Client %s] ", i);
executor.execute(new GrpcClient(client));
Thread.sleep(500);
}
executor.awaitTermination(10, TimeUnit.SECONDS);
Assert.assertTrue(true);
}

private static class GrpcClient implements Runnable {

private String client;

public GrpcClient(String client) {
this.client = client;
}

@Override
public void run() {
try {
TestGrpc.executeRouteGuideClient(client);
} catch(InterruptedException e) {
e.printStackTrace();
}
}
}

}
20 changes: 17 additions & 3 deletions grpc/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Example gRPC

Currently, a POC that requires the gRPC module which is not yet publicly available.
POC that requires the gRPC module which is not yet publicly available.

prepare artifacts

Expand All @@ -11,7 +11,21 @@ Deploy on Payara Server and make sure the HTTP/2 and HTTP Push are activate.
./asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.http2-push-enabled=true
./asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.http2-enabled=true

Before to run test client's

Run the client (located in the test folder) or use
Before to execute the test client's you must verify that an instance of the server is up and running.
This is because the test needs an available instance of the server to be able to deploy a generated war from arquillian

./run-client.sh
Run the test client's (located in the test folder) with the following command:

From root folder grpc: mvn verify -Ppayara-server-remote -pl grpc-web

you can also execute directly from the grpc-web folder as follows: mvn verify -Ppayara-server-remote

Execute individual tests with the following command:

single thread execution use the folllowing command
(under grpc-web folder): mvn verify -Ppayara-server-remote -Dtest=TestGrpc test

for concurrent execution use the following command
(under grpc-web folder): mvn verify -Ppayara-server-remote -Dtest=TestGrpcConcurrent test

0 comments on commit f7e6772

Please sign in to comment.