Skip to content

Commit

Permalink
FISH-5881: improving structure of packages for the gRPC examples
Browse files Browse the repository at this point in the history
  • Loading branch information
breakponchito committed Jan 22, 2022
1 parent fefa842 commit f9d9699
Show file tree
Hide file tree
Showing 20 changed files with 987 additions and 236 deletions.
103 changes: 103 additions & 0 deletions grpc/grpc-stubs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fish.payara.grpc</groupId>
<artifactId>grpc-stubs</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<!-- Java versions -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Maven encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- gRPC versions -->
<grpc.version>1.43.1</grpc.version>
<payara.grpc.version>1.0.0-SNAPSHOT</payara.grpc.version>
<protobuf.version>3.19.2</protobuf.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-bom</artifactId>
<version>${grpc.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- gRPC dependencies -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>${protobuf.version}</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>grpc</artifactId>
<version>${payara.grpc.version}</version>
</dependency>
</dependencies>

<build>
<finalName>route-guide</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.7.0</version>
</extension>
</extensions>
</build>
</project>
File renamed without changes.
156 changes: 156 additions & 0 deletions grpc/grpc-web/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fish.payara.grpc</groupId>
<artifactId>grpc-web</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<!-- Java versions -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Maven encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- gRPC versions -->
<grpc.version>1.43.1</grpc.version>
<payara.grpc.version>1.0.0-SNAPSHOT</payara.grpc.version>
<protobuf.version>3.19.2</protobuf.version>
</properties>

<dependencies>
<!-- Java EE -->
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<!-- proto stubs-->
<dependency>
<groupId>fish.payara.grpc</groupId>
<artifactId>grpc-stubs</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.6.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>fish.payara.arquillian</groupId>
<artifactId>arquillian-payara-server-remote</artifactId>
<version>2.4.5</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>fish.payara.arquillian</groupId>
<artifactId>payara-client-ee8</artifactId>
<version>2.4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>3.1.4</version>
<scope>runtime</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>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>grpc</artifactId>
<version>${payara.grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>${protobuf.version}</version>
</dependency>
</dependencies>

<build>
<finalName>route-guide</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
<!-- Copy dependencies to lib/ -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<excludeScope>provided</excludeScope>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>payara-server-remote</id>
<dependencies>
<dependency>
<groupId>fish.payara.arquillian</groupId>
<artifactId>arquillian-payara-server-remote</artifactId>
<version>2.4.5</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fish.payara.example.grpc;


import com.google.protobuf.util.JsonFormat;
import io.grpc.examples.routeguide.Feature;
import io.grpc.examples.routeguide.FeatureDatabase;
Expand All @@ -13,6 +14,7 @@
import java.nio.charset.Charset;
import java.util.List;


@ApplicationScoped
public class RouteGuideJSONReader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,9 @@
*/
package fish.payara.example.grpc;

import com.google.protobuf.util.JsonFormat;
import io.grpc.examples.routeguide.Feature;
import io.grpc.examples.routeguide.FeatureDatabase;
import io.grpc.examples.routeguide.Point;

import javax.enterprise.context.ApplicationScoped;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.List;

import static java.lang.Math.*;
import static java.lang.Math.sqrt;
Expand Down
101 changes: 101 additions & 0 deletions grpc/grpc-web/src/test/java/fish/payara/example/grpc/TestGrpc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package fish.payara.example.grpc;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.examples.routeguide.Feature;
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.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystem;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;


@RunWith(Arquillian.class)
public class TestGrpc {

public static final String STUBS_IMPL = "fish.payara.grpc:grpc-stubs";
public static final String PROTOBUF = "com.google.protobuf:protobuf-java";
public static final String IO_GRPC_API = "io.grpc:grpc-api";
public static final String IO_GRPC_STUB = "io.grpc:grpc-stub";
public static final String PAYARA_GRPC = "fish.payara.extras:grpc";
public static final String PROTOBUF_JAVA_UTIL = "com.google.protobuf:protobuf-java-util";

private static List<String> listOfLibs;

static {
listOfLibs = new ArrayList<>();
listOfLibs.add(STUBS_IMPL);
listOfLibs.add(PROTOBUF);
listOfLibs.add(IO_GRPC_API);
listOfLibs.add(IO_GRPC_STUB);
listOfLibs.add(PAYARA_GRPC);
listOfLibs.add(PROTOBUF_JAVA_UTIL);
}

@Deployment
public static WebArchive deployWar() {
MavenResolverSystem resolver = Maven.resolver();
File[] singleDependencies = resolver.loadPomFromFile("pom.xml").resolve(listOfLibs).withoutTransitivity().asFile();
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 {
String target = "localhost:8080";
String clientPrefix = "[] ";

List<Feature> features;
try {
features = new RouteGuideJSONReader().readFeatures();
} catch (IOException ex) {
ex.printStackTrace();
return;
}

ManagedChannel channel = ManagedChannelBuilder.forTarget(target).usePlaintext().build();

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

// Feature missing.
client.getFeature(0, 0);

// Looking for features between 40, -75 and 42, -73.
client.listFeatures(400000000, -750000000, 420000000, -730000000);

// Record a few randomly selected points from the features file.
client.recordRoute(features, 10);

// Send and receive some notes.
CountDownLatch finishLatch = client.routeChat();

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

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

}
Loading

0 comments on commit f9d9699

Please sign in to comment.