Skip to content

Commit 3b99b30

Browse files
committed
Fix implementation and add a test
1 parent 888dc0c commit 3b99b30

File tree

7 files changed

+66
-15
lines changed

7 files changed

+66
-15
lines changed

grpc-client-spring-boot-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424
// api comes from java-library, and allows exposure of the dependency to consumers of the library
2525
// this means it can be used implicitly without specifying the dependency (unless you wish to override with a different version, or exclude)
2626
optionalSupportApi 'io.grpc:grpc-netty'
27+
optionalSupportApi 'io.netty:netty-transport-native-epoll'
2728
api 'io.grpc:grpc-netty-shaded'
2829
api 'io.grpc:grpc-protobuf'
2930
api 'io.grpc:grpc-stub'

grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/channelfactory/NettyChannelFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ protected NettyChannelBuilder newChannelBuilder(final String name) {
7474
if (address == null) {
7575
address = URI.create(name);
7676
}
77-
NettyChannelBuilder builder;
78-
if (address.getScheme().equals(GrpcChannelProperties.DOMAIN_SOCKET_ADDRESS_SCHEME)) {
79-
builder = NettyChannelBuilder.forAddress(new DomainSocketAddress(address.getPath()))
77+
if (GrpcChannelProperties.DOMAIN_SOCKET_ADDRESS_SCHEME.equals(address.getScheme())) {
78+
String path = address.getSchemeSpecificPart();
79+
return NettyChannelBuilder.forAddress(new DomainSocketAddress(path))
8080
.channelType(EpollDomainSocketChannel.class)
8181
.eventLoopGroup(new EpollEventLoopGroup());
8282
} else {
83-
builder = NettyChannelBuilder.forTarget(address.toString());
83+
return NettyChannelBuilder.forTarget(address.toString())
84+
.defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
8485
}
85-
return builder.defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
8686
}
8787

8888
@Override

grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/channelfactory/ShadedNettyChannelFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ protected NettyChannelBuilder newChannelBuilder(final String name) {
7272
if (address == null) {
7373
address = URI.create(name);
7474
}
75-
NettyChannelBuilder builder;
76-
if (address.getScheme().equals(GrpcChannelProperties.DOMAIN_SOCKET_ADDRESS_SCHEME)) {
77-
builder = NettyChannelBuilder.forAddress(new DomainSocketAddress(address.getPath()))
75+
if (GrpcChannelProperties.DOMAIN_SOCKET_ADDRESS_SCHEME.equals(address.getScheme())) {
76+
final String path = address.getSchemeSpecificPart();
77+
return NettyChannelBuilder.forAddress(new DomainSocketAddress(path))
7878
.channelType(EpollDomainSocketChannel.class)
7979
.eventLoopGroup(new EpollEventLoopGroup());
8080
} else {
81-
builder = NettyChannelBuilder.forTarget(address.toString());
81+
return NettyChannelBuilder.forTarget(address.toString())
82+
.defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
8283
}
83-
return builder.defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
8484
}
8585

8686
@Override

grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class GrpcServerProperties {
6969
/**
7070
* A constant that defines, the prefix of a Unix domain socket address.
7171
*/
72-
public static final String DOMAIN_SOCKET_ADDRESS_PREFIX = "unix://";
72+
public static final String DOMAIN_SOCKET_ADDRESS_PREFIX = "unix:";
7373

7474
/**
7575
* Bind address for the server. Defaults to {@link #ANY_IP_ADDRESS "*"}. Alternatively you can restrict this to

grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/serverfactory/NettyGrpcServerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ protected NettyServerBuilder newServerBuilder() {
6565
final String address = getAddress();
6666
final int port = getPort();
6767
if (address.startsWith(GrpcServerProperties.DOMAIN_SOCKET_ADDRESS_PREFIX)) {
68-
return NettyServerBuilder
69-
.forAddress(new DomainSocketAddress(address.substring(GrpcServerProperties.DOMAIN_SOCKET_ADDRESS_PREFIX.length())))
68+
String path = address.substring(GrpcServerProperties.DOMAIN_SOCKET_ADDRESS_PREFIX.length());
69+
return NettyServerBuilder.forAddress(new DomainSocketAddress(path))
7070
.channelType(EpollServerDomainSocketChannel.class)
7171
.bossEventLoopGroup(new EpollEventLoopGroup(1))
7272
.workerEventLoopGroup(new EpollEventLoopGroup());

grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/serverfactory/ShadedNettyGrpcServerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ protected NettyServerBuilder newServerBuilder() {
6666
final String address = getAddress();
6767
final int port = getPort();
6868
if (address.startsWith(GrpcServerProperties.DOMAIN_SOCKET_ADDRESS_PREFIX)) {
69-
return NettyServerBuilder
70-
.forAddress(new DomainSocketAddress(address.substring(GrpcServerProperties.DOMAIN_SOCKET_ADDRESS_PREFIX.length())))
69+
final String path = address.substring(GrpcServerProperties.DOMAIN_SOCKET_ADDRESS_PREFIX.length());
70+
return NettyServerBuilder.forAddress(new DomainSocketAddress(path))
7171
.channelType(EpollServerDomainSocketChannel.class)
7272
.bossEventLoopGroup(new EpollEventLoopGroup(1))
7373
.workerEventLoopGroup(new EpollEventLoopGroup());
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2016-2021 Michael Zhang <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package net.devh.boot.grpc.test.setup;
19+
20+
import org.junit.jupiter.api.condition.EnabledOnOs;
21+
import org.junit.jupiter.api.condition.OS;
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.test.annotation.DirtiesContext;
24+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
25+
26+
import lombok.extern.slf4j.Slf4j;
27+
import net.devh.boot.grpc.test.config.BaseAutoConfiguration;
28+
import net.devh.boot.grpc.test.config.ServiceConfiguration;
29+
30+
/**
31+
* A test checking that the server and client can start and connect to each other with minimal config.
32+
*
33+
* @author Daniel Theuke ([email protected])
34+
*/
35+
@Slf4j
36+
@SpringBootTest(properties = {
37+
"grpc.server.address=unix:unix-test",
38+
"grpc.client.GLOBAL.address=unix:unix-test",
39+
"grpc.client.GLOBAL.negotiationType=PLAINTEXT",
40+
})
41+
@SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class})
42+
@DirtiesContext
43+
@EnabledOnOs(OS.LINUX)
44+
public class UnixSetupTest extends AbstractSimpleServerClientTest {
45+
46+
public UnixSetupTest() {
47+
log.info("--- UnixSetupTest ---");
48+
}
49+
50+
}

0 commit comments

Comments
 (0)