Skip to content

Commit 7ed924a

Browse files
committed
Endpoint port validation in GrpcTransport
1 parent d653031 commit 7ed924a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

core/src/main/java/tech/ydb/core/impl/YdbTransportImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ static EndpointRecord getDiscoveryEndpoint(GrpcTransportBuilder builder) {
126126
+ "endpoint " + builder.getEndpoint() + " and empty host " + builder.getHost());
127127
}
128128

129+
if (endpointURI.getPort() == -1) {
130+
throw new IllegalArgumentException("Can't create discovery rpc, port is not specified for "
131+
+ "endpoint " + builder.getEndpoint());
132+
}
133+
129134
return new EndpointRecord(endpointURI.getHost(), endpointURI.getPort());
130135
}
131136

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tech.ydb.core.grpc;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
/**
7+
* @author Mikhail Firsov
8+
*/
9+
public class GrpcTransportTest {
10+
11+
@Test
12+
public void failFastOnMissingPort() {
13+
String endpoint = "127.1.2.3";
14+
try {
15+
GrpcTransport.forEndpoint(endpoint, "test").build().close();
16+
Assert.fail("Exception expected");
17+
} catch (IllegalArgumentException e) {
18+
Assert.assertEquals("Can't create discovery rpc, port is not specified for endpoint 127.1.2.3", e.getMessage());
19+
}
20+
}
21+
22+
@Test
23+
public void doNotFailIfEndpointHasPort() {
24+
String endpoint = "127.1.2.3:12345";
25+
GrpcTransport
26+
.forEndpoint(endpoint, "test")
27+
.withInitMode(GrpcTransportBuilder.InitMode.ASYNC)
28+
.build()
29+
.close();
30+
}
31+
}

0 commit comments

Comments
 (0)