Skip to content

Commit abc87c2

Browse files
committed
Add grpc-server and grpc-client samples back in.
Signed-off-by: onobc <chris.bono@gmail.com>
1 parent 5a90fd2 commit abc87c2

File tree

15 files changed

+143
-87
lines changed

15 files changed

+143
-87
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<module>spring-grpc-core</module>
2020
<module>spring-grpc-dependencies</module>
2121
<module>spring-grpc-docs</module>
22-
<!-- <module>samples</module>,-->
22+
<module>samples</module>
2323

2424
<!-- Spring Boot modules -->
2525
<module>spring-grpc-client-spring-boot-autoconfigure</module>

samples/grpc-client/build.gradle

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.5.5'
4-
id 'io.spring.dependency-management' version '1.1.6'
3+
id 'org.springframework.boot' version '4.0.0-RC1'
4+
id 'io.spring.dependency-management' version '1.1.7'
55
id 'com.google.protobuf' version '0.9.4'
66
}
77

@@ -28,13 +28,18 @@ dependencyManagement {
2828
}
2929

3030
dependencies {
31-
implementation 'org.springframework.grpc:spring-grpc-client-spring-boot-starter'
32-
testImplementation 'org.springframework.boot:spring-boot-starter-test'
33-
testImplementation 'org.springframework.grpc:spring-grpc-test'
34-
testImplementation 'org.springframework.experimental.boot:spring-boot-testjars-maven:0.0.3'
35-
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
31+
implementation 'org.springframework.grpc:spring-grpc-client-spring-boot-starter'
32+
33+
testImplementation 'org.springframework.grpc:spring-grpc-test-spring-boot-autoconfigure'
34+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
35+
testImplementation 'org.springframework.boot:spring-boot-web-server'
36+
testImplementation 'org.springframework.experimental.boot:spring-boot-testjars-maven:0.4.0.0-SNAPSHOT'
37+
testImplementation 'io.grpc:grpc-inprocess'
38+
39+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
3640
}
3741

42+
3843
tasks.named('test') {
3944
useJUnitPlatform()
4045
}

samples/grpc-client/pom.xml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.5.5</version>
9+
<version>4.0.0-SNAPSHOT</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>org.springframework.grpc</groupId>
@@ -30,7 +30,7 @@
3030
<properties>
3131
<java.version>17</java.version>
3232
<spring-javaformat-maven-plugin.version>0.0.39</spring-javaformat-maven-plugin.version>
33-
<protobuf-java.version>4.31.1</protobuf-java.version>
33+
<protobuf-java.version>4.32.1</protobuf-java.version>
3434
<grpc.version>1.76.0</grpc.version>
3535
<maven.version>3.9.4</maven.version>
3636
<maven.resolver.version>1.9.18</maven.resolver.version>
@@ -46,6 +46,7 @@
4646
</dependency>
4747
</dependencies>
4848
</dependencyManagement>
49+
4950
<dependencies>
5051
<dependency>
5152
<groupId>org.springframework.grpc</groupId>
@@ -54,13 +55,28 @@
5455

5556
<dependency>
5657
<groupId>org.springframework.grpc</groupId>
57-
<artifactId>spring-grpc-test</artifactId>
58+
<artifactId>spring-grpc-test-spring-boot-autoconfigure</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-starter-test</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-web-server</artifactId>
5869
<scope>test</scope>
5970
</dependency>
6071
<dependency>
6172
<groupId>org.springframework.experimental.boot</groupId>
6273
<artifactId>spring-boot-testjars-maven</artifactId>
63-
<version>0.0.3</version>
74+
<version>0.4.0.0-SNAPSHOT</version>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>io.grpc</groupId>
79+
<artifactId>grpc-inprocess</artifactId>
6480
<scope>test</scope>
6581
</dependency>
6682
</dependencies>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
spring.application.name=grpc-client
2-
spring.grpc.client.default-channel.address=static://0.0.0.0:9090
2+
spring.grpc.client.default-channel.address=static://0.0.0.0:${launched.grpc.port}
3+
4+
#logging.level.org.springframework.experimental.boot.server.exec=debug

samples/grpc-client/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerPortFileWriter.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
import org.springframework.util.FileCopyUtils;
2929

3030
/**
31-
* An {@link ApplicationListener} that saves embedded server port and management port into
32-
* file. This application listener will be triggered whenever the server starts, and the
33-
* file name can be overridden at runtime with a System property or environment variable
34-
* named "PORTFILE" or "portfile".
31+
* An {@link ApplicationListener} that saves the gRPC server port into a file. This
32+
* application listener will be triggered whenever the gRPC server starts, and the file
33+
* name can be overridden at runtime with a System property or environment variable named
34+
* "PORTFILE" or "portfile".
35+
*
36+
* <b>NOTE:</b> This is currently required in order to use spring-boot-testjars as it
37+
* expects this file to be available in order to determine the port of the dynamically
38+
* launched gRPC server.
3539
*
3640
* @author David Liu
3741
* @author Phillip Webb

samples/grpc-client/src/test/java/org/springframework/grpc/sample/DefaultDeadlineSetupTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
public class DefaultDeadlineSetupTests {
2929

3030
@Nested
31-
@SpringBootTest(properties = { "spring.grpc.client.default-channel.address=static://0.0.0.0:${local.grpc.port}",
32-
"spring.grpc.client.default-channel.default-deadline=1s" })
31+
@SpringBootTest(properties = "spring.grpc.client.default-channel.default-deadline=1s")
3332
@DirtiesContext
3433
@EnabledIf("serverJarAvailable")
3534
class Deadline {
@@ -48,11 +47,12 @@ void contextLoads() {
4847
static class ExtraConfiguration {
4948

5049
@Bean
51-
@DynamicProperty(name = "local.grpc.port", value = "port")
50+
@DynamicProperty(name = "launched.grpc.port", value = "port")
5251
static CommonsExecWebServerFactoryBean grpcServer() {
5352
return CommonsExecWebServerFactoryBean.builder()
5453
.classpath(classpath -> classpath
5554
.entries(new MavenClasspathEntry("org.springframework.grpc:grpc-server-sample:1.0.0-SNAPSHOT"))
55+
.entries(MavenClasspathEntry.springBootDependency("spring-boot-web-server"))
5656
.files("target/test-classes"));
5757
}
5858

@@ -76,8 +76,7 @@ public CommandLineRunner otherRunner(SimpleGrpc.SimpleBlockingStub stub) {
7676
}
7777

7878
@Nested
79-
@SpringBootTest(properties = { "spring.grpc.client.default-channel.address=static://0.0.0.0:${local.grpc.port}",
80-
"spring.grpc.client.default-channel.default-deadline=1s" })
79+
@SpringBootTest(properties = "spring.grpc.client.default-channel.default-deadline=1s")
8180
@DirtiesContext
8281
@EnabledIf("serverJarAvailable")
8382
class WithoutDeadline {
@@ -96,11 +95,12 @@ void contextLoads() {
9695
static class ExtraConfiguration {
9796

9897
@Bean
99-
@DynamicProperty(name = "local.grpc.port", value = "port")
98+
@DynamicProperty(name = "launched.grpc.port", value = "port")
10099
static CommonsExecWebServerFactoryBean grpcServer() {
101100
return CommonsExecWebServerFactoryBean.builder()
102101
.classpath(classpath -> classpath
103102
.entries(new MavenClasspathEntry("org.springframework.grpc:grpc-server-sample:1.0.0-SNAPSHOT"))
103+
.entries(MavenClasspathEntry.springBootDependency("spring-boot-web-server"))
104104
.files("target/test-classes"));
105105
}
106106

samples/grpc-client/src/test/java/org/springframework/grpc/sample/GrpcClientApplicationTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.springframework.experimental.boot.test.context.EnableDynamicProperty;
1717
import org.springframework.test.annotation.DirtiesContext;
1818

19-
@SpringBootTest(properties = "spring.grpc.client.default-channel.address=static://0.0.0.0:${local.grpc.port}")
19+
@SpringBootTest
2020
@DirtiesContext
2121
@EnabledIf("serverJarAvailable")
2222
public class GrpcClientApplicationTests {
@@ -38,19 +38,18 @@ void contextLoads() {
3838
static class ExtraConfiguration {
3939

4040
@Bean
41-
@DynamicProperty(name = "local.grpc.port", value = "port")
41+
@DynamicProperty(name = "launched.grpc.port", value = "port")
4242
static CommonsExecWebServerFactoryBean grpcServer() {
4343
return CommonsExecWebServerFactoryBean.builder()
4444
.classpath(classpath -> classpath
4545
.entries(new MavenClasspathEntry("org.springframework.grpc:grpc-server-sample:1.0.0-SNAPSHOT"))
46+
.entries(MavenClasspathEntry.springBootDependency("spring-boot-web-server"))
4647
.files("target/test-classes"));
4748
}
4849

4950
@Bean
5051
static BeanDefinitionRegistryPostProcessor startup(WebServer server) {
51-
return registry -> {
52-
server.getPort();
53-
};
52+
return registry -> System.out.println("*** gRPC server started on port " + server.getPort());
5453
}
5554

5655
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
org.springframework.context.ApplicationListener=\
2-
org.springframework.grpc.autoconfigure.server.GrpcServerPortFileWriter
2+
org.springframework.grpc.autoconfigure.server.GrpcServerPortFileWriter
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
spring:
22
grpc:
33
server:
4-
port: ${server.port}
4+
port: ${server.port}
5+
6+
#logging.level:
7+
# org.springframework.experimental.boot.server.exec: debug

samples/grpc-server/build.gradle

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.5.5'
4-
id 'io.spring.dependency-management' version '1.1.6'
3+
id 'org.springframework.boot' version '4.0.0-RC1'
4+
id 'io.spring.dependency-management' version '1.1.7'
55
id 'org.graalvm.buildtools.native' version '0.10.3'
66
id 'com.google.protobuf' version '0.9.4'
77
}
@@ -30,11 +30,13 @@ dependencyManagement {
3030
dependencies {
3131
implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter'
3232
implementation 'org.springframework.boot:spring-boot-starter-actuator'
33-
implementation 'io.grpc:grpc-services'
34-
testImplementation 'org.springframework.boot:spring-boot-starter-test'
35-
testImplementation 'org.springframework.grpc:spring-grpc-test'
36-
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
33+
34+
testImplementation 'org.springframework.grpc:spring-grpc-test-spring-boot-autoconfigure'
35+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
36+
testImplementation 'io.grpc:grpc-inprocess'
37+
3738
testRuntimeOnly "io.netty:netty-transport-native-epoll::linux-x86_64"
39+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
3840
}
3941

4042
test {

0 commit comments

Comments
 (0)