Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/main/java/tech/ydb/core/impl/YdbTransportImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ static EndpointRecord getDiscoveryEndpoint(GrpcTransportBuilder builder) {
+ "endpoint " + builder.getEndpoint() + " and empty host " + builder.getHost());
}

if (endpointURI.getPort() < 0) {
throw new IllegalArgumentException("Can't create discovery rpc, port is not specified for "
+ "endpoint " + builder.getEndpoint());
}

return new EndpointRecord(endpointURI.getHost(), endpointURI.getPort());
}

Expand Down
31 changes: 31 additions & 0 deletions core/src/test/java/tech/ydb/core/grpc/GrpcTransportTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tech.ydb.core.grpc;

import org.junit.Assert;
import org.junit.Test;

/**
* @author Mikhail Firsov
*/
public class GrpcTransportTest {

@Test
public void failFastOnMissingPort() {
String endpoint = "127.1.2.3";
try {
GrpcTransport.forEndpoint(endpoint, "test").build().close();
Assert.fail("Exception expected");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Can't create discovery rpc, port is not specified for endpoint 127.1.2.3", e.getMessage());
}
}

@Test
public void doNotFailIfEndpointHasPort() {
String endpoint = "127.1.2.3:12345";
GrpcTransport
.forEndpoint(endpoint, "test")
.withInitMode(GrpcTransportBuilder.InitMode.ASYNC)
.build()
.close();
}
}