Skip to content

Commit f3e589e

Browse files
author
Alexander Furer
committed
GRPC_PORT environment variable test
1 parent abcf5a5 commit f3e589e

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ subprojects {
4141
sourceCompatibility = 1.8
4242
targetCompatibility = 1.8
4343
test {
44+
forkEvery = 1
4445
testLogging {
4546
exceptionFormat = 'full'
4647
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Wed Sep 12 11:15:37 IDT 2018
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip

grpc-spring-boot-starter-demo/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ buildscript {
77
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBoot_1_X_Version}")
88
}
99
}
10-
1110
apply plugin: 'com.google.protobuf'
1211
apply plugin: 'org.springframework.boot'
1312

@@ -20,7 +19,8 @@ dependencies {
2019
compile project(':grpc-spring-boot-starter')
2120

2221
testCompile 'org.springframework.boot:spring-boot-starter-aop'
23-
testCompile('org.springframework.boot:spring-boot-starter-test')
22+
testCompile 'org.springframework.boot:spring-boot-starter-test'
23+
testCompile 'com.github.stefanbirkner:system-rules:1.18.0'
2424
}
2525
sourceSets {
2626
main {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.lognet.springboot.grpc;
2+
3+
import org.junit.AfterClass;
4+
import org.junit.Assert;
5+
import org.junit.ClassRule;
6+
import org.junit.contrib.java.lang.system.EnvironmentVariables;
7+
import org.junit.runner.RunWith;
8+
import org.lognet.springboot.grpc.context.LocalRunningGrpcPort;
9+
import org.lognet.springboot.grpc.demo.DemoApp;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
import org.springframework.test.context.junit4.SpringRunner;
12+
import org.springframework.util.SocketUtils;
13+
14+
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
15+
16+
@RunWith(SpringRunner.class)
17+
@SpringBootTest(classes = {DemoApp.class}, webEnvironment = NONE)
18+
public class EnvVarGrpcPortTest extends GrpcServerTestBase {
19+
20+
21+
private static int randomPort;
22+
private static EnvironmentVariables environmentVariables;
23+
24+
@ClassRule
25+
public static EnvironmentVariables environmentVariables() {
26+
randomPort = SocketUtils.findAvailableTcpPort();
27+
28+
environmentVariables = new EnvironmentVariables();
29+
environmentVariables.set("GRPC_PORT", "" + randomPort);
30+
return environmentVariables;
31+
}
32+
33+
@AfterClass
34+
public static void tearDown() {
35+
environmentVariables.clear("GRPC_PORT");
36+
}
37+
38+
@LocalRunningGrpcPort
39+
int runningPort;
40+
41+
@Override
42+
protected int getPort() {
43+
return runningPort;
44+
}
45+
46+
@Override
47+
protected void beforeGreeting() {
48+
Assert.assertEquals(randomPort, gRpcServerProperties.getPort());
49+
Assert.assertEquals(randomPort, runningPort);
50+
}
51+
}

grpc-spring-boot2-starter-demo/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ apply plugin: 'org.springframework.boot'
1313
apply plugin: 'io.spring.dependency-management'
1414

1515

16-
sourceSets.test{
16+
project.sourceSets.test{
1717
java{
1818
srcDir "${project(':grpc-spring-boot-starter-demo').getProjectDir()}/src/test/java"
1919
}
@@ -26,6 +26,7 @@ dependencies {
2626

2727
testCompile('org.springframework.boot:spring-boot-starter-test')
2828
testCompile 'org.springframework.boot:spring-boot-starter-aop'
29+
testCompile 'com.github.stefanbirkner:system-rules:1.18.0'
2930

3031
testRuntime('org.springframework.boot:spring-boot-starter-actuator')
3132
testRuntime('org.springframework.boot:spring-boot-starter-web')

0 commit comments

Comments
 (0)