mirror of https://github.com/apache/druid.git
parent
59a48a560a
commit
421e02203f
|
@ -54,11 +54,18 @@ public class ServerDiscoverySelector implements DiscoverySelector<Server>
|
|||
public Server apply(final ServiceInstance instance)
|
||||
{
|
||||
Preconditions.checkState(
|
||||
instance.getPort() >= 0 || instance.getSslPort() >= 0,
|
||||
instance.getPort() >= 0 || (instance.getSslPort() != null && instance.getSslPort() >= 0),
|
||||
"WTH?! Both port and sslPort not set"
|
||||
);
|
||||
final int port = instance.getSslPort() >= 0 ? instance.getSslPort() : instance.getPort();
|
||||
final String scheme = instance.getSslPort() >= 0 ? "https" : "http";
|
||||
final int port;
|
||||
final String scheme;
|
||||
if (instance.getSslPort() == null) {
|
||||
port = instance.getPort();
|
||||
scheme = "http";
|
||||
} else {
|
||||
port = instance.getSslPort() >= 0 ? instance.getSslPort() : instance.getPort();
|
||||
scheme = instance.getSslPort() >= 0 ? "https" : "http";
|
||||
}
|
||||
return new Server()
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -38,6 +38,7 @@ public class ServerDiscoverySelectorTest
|
|||
private ServerDiscoverySelector serverDiscoverySelector;
|
||||
private ServiceInstance instance;
|
||||
private static final int PORT = 8080;
|
||||
private static final int SSL_PORT = 8280;
|
||||
private static final String ADDRESS = "localhost";
|
||||
|
||||
@Before
|
||||
|
@ -77,6 +78,63 @@ public class ServerDiscoverySelectorTest
|
|||
Assert.assertEquals("http", uri.getScheme());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPickWithNullSslPort() throws Exception
|
||||
{
|
||||
EasyMock.expect(serviceProvider.getInstance()).andReturn(instance).anyTimes();
|
||||
EasyMock.expect(instance.getAddress()).andReturn(ADDRESS).anyTimes();
|
||||
EasyMock.expect(instance.getPort()).andReturn(PORT).anyTimes();
|
||||
EasyMock.expect(instance.getSslPort()).andReturn(null).anyTimes();
|
||||
EasyMock.replay(instance, serviceProvider);
|
||||
Server server = serverDiscoverySelector.pick();
|
||||
Assert.assertEquals(PORT, server.getPort());
|
||||
Assert.assertEquals(ADDRESS, server.getAddress());
|
||||
Assert.assertTrue(server.getHost().contains(Integer.toString(PORT)));
|
||||
Assert.assertTrue(server.getHost().contains(ADDRESS));
|
||||
Assert.assertEquals("http", server.getScheme());
|
||||
EasyMock.verify(instance, serviceProvider);
|
||||
final URI uri = new URI(
|
||||
server.getScheme(),
|
||||
null,
|
||||
server.getAddress(),
|
||||
server.getPort(),
|
||||
"/druid/indexer/v1/action",
|
||||
null,
|
||||
null
|
||||
);
|
||||
Assert.assertEquals(PORT, uri.getPort());
|
||||
Assert.assertEquals(ADDRESS, uri.getHost());
|
||||
Assert.assertEquals("http", uri.getScheme());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPickWithSslPort() throws Exception
|
||||
{
|
||||
EasyMock.expect(serviceProvider.getInstance()).andReturn(instance).anyTimes();
|
||||
EasyMock.expect(instance.getAddress()).andReturn(ADDRESS).anyTimes();
|
||||
EasyMock.expect(instance.getPort()).andReturn(PORT).anyTimes();
|
||||
EasyMock.expect(instance.getSslPort()).andReturn(SSL_PORT).anyTimes();
|
||||
EasyMock.replay(instance, serviceProvider);
|
||||
Server server = serverDiscoverySelector.pick();
|
||||
Assert.assertEquals(SSL_PORT, server.getPort());
|
||||
Assert.assertEquals(ADDRESS, server.getAddress());
|
||||
Assert.assertTrue(server.getHost().contains(Integer.toString(SSL_PORT)));
|
||||
Assert.assertTrue(server.getHost().contains(ADDRESS));
|
||||
Assert.assertEquals("https", server.getScheme());
|
||||
EasyMock.verify(instance, serviceProvider);
|
||||
final URI uri = new URI(
|
||||
server.getScheme(),
|
||||
null,
|
||||
server.getAddress(),
|
||||
server.getPort(),
|
||||
"/druid/indexer/v1/action",
|
||||
null,
|
||||
null
|
||||
);
|
||||
Assert.assertEquals(SSL_PORT, uri.getPort());
|
||||
Assert.assertEquals(ADDRESS, uri.getHost());
|
||||
Assert.assertEquals("https", uri.getScheme());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPickIPv6() throws Exception
|
||||
|
|
Loading…
Reference in New Issue