forked from payara/Payara-Examples
-
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.
FISH-5881: improving execution of concurrent grpc example
- Loading branch information
1 parent
f9d9699
commit f7e6772
Showing
4 changed files
with
87 additions
and
21 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
48 changes: 47 additions & 1 deletion
48
grpc/grpc-web/src/test/java/fish/payara/example/grpc/TestGrpcConcurrent.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 |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} | ||
|
||
} |
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